Skip to content

Commit 1052895

Browse files
author
Hideo Hattori
committed
config headers
1 parent 1675fd1 commit 1052895

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

attacker.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Attacker struct {
2121
UserAgent string
2222
Gzip bool
2323
QueryParams *map[string]string
24+
Headers *map[string]string
2425
ExVarOffset map[string]int
2526
sync.RWMutex
2627
}
@@ -81,6 +82,10 @@ func (atk *Attacker) makeRequest() (req *http.Request, err error) {
8182
}
8283
req.URL.RawQuery = values.Encode()
8384

85+
for k, v := range *atk.Headers {
86+
req.Header.Add(k, v)
87+
}
88+
8489
req.Header.Set("User-Agent", atk.UserAgent)
8590
return req, err
8691
}

config.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Config struct {
5353
Consts map[string]string `yaml:"consts"`
5454
ExVars []map[string]string `yaml:"exvars"`
5555
Vars []map[string]string `yaml:"vars"`
56+
Headers map[string]string `yaml:"headers"`
5657
HTTPVersion int `yaml:"http_version"`
5758
}
5859

example/ev2.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
10
2+
09
3+
08
4+
07

example/vars.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exvars:
1010
- name: ev1
1111
file: ev.txt
1212
- name: ev2
13-
file: ev.txt
13+
file: ev2.txt
1414

1515
vars:
1616
- name: v1
@@ -26,3 +26,6 @@ query_params:
2626
qp1: "%(ev1)%"
2727
qp2: "%(c1)%"
2828
qp3: "%(c2)%"
29+
30+
headers:
31+
X-Foo: "%(ev2)%"

main.go

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func hakai(c http.Client, config *Config, offset map[string]int) {
5555
queryParams[k] = vv
5656
}
5757

58+
headers := map[string]string{}
59+
for k, v := range config.Headers {
60+
headers[k] = ReplaceNames(v, offset)
61+
}
62+
5863
cookieJar, _ := cookiejar.New(nil)
5964
c.Jar = cookieJar
6065
attacker := Attacker{
@@ -63,6 +68,7 @@ func hakai(c http.Client, config *Config, offset map[string]int) {
6368
Gzip: config.Gzip,
6469
UserAgent: config.UserAgent,
6570
QueryParams: &queryParams,
71+
Headers: &headers,
6672
ExVarOffset: offset,
6773
}
6874
for _, action := range config.Actions {

0 commit comments

Comments
 (0)