Skip to content

Commit f21c5b0

Browse files
authored
Merge pull request #10 from 003random/headers
add optional flag for request headers. Thanks bp0lr #7
2 parents ee9fc91 + 2cd95a3 commit f21c5b0

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"bufio"
5-
"flag"
65
"fmt"
76
"net/http"
87
"net/url"
@@ -11,6 +10,7 @@ import (
1110

1211
"github.com/PuerkitoBio/goquery"
1312
"github.com/logrusorgru/aurora"
13+
flag "github.com/spf13/pflag"
1414
)
1515

1616
type logger interface {
@@ -59,6 +59,7 @@ func main() {
5959
completeArg := flag.Bool("complete", false, "Complete the url. e.g. append the domain to the path")
6060
verboseArg := flag.Bool("verbose", false, "Display info of what is going on")
6161
noColorsArg := flag.Bool("nocolors", false, "Enable or disable colors")
62+
HeaderArg := flag.StringArrayP("header", "H", nil, "Any HTTP headers(-H \"Authorization:Bearer token\")")
6263
flag.Parse()
6364

6465
au = aurora.NewAurora(!*noColorsArg)
@@ -118,7 +119,7 @@ func main() {
118119
var sourcesBak []string
119120
var completedSuccessfully = true
120121
output.Log("[+] Getting sources from " + e)
121-
sources, err := getScriptSrc(e)
122+
sources, err := getScriptSrc(e, *HeaderArg)
122123
if err != nil {
123124
output.Error(fmt.Sprintf("[!] Couldn't get sources from %s", e), err)
124125
}
@@ -186,11 +187,25 @@ func saveToFile(sources []string, path string) error {
186187
return w.Flush()
187188
}
188189

189-
func getScriptSrc(url string) ([]string, error) {
190+
func getScriptSrc(url string, headers []string) ([]string, error) {
190191
// Request the HTML page.
191-
res, err := http.Get(url)
192+
req, err := http.NewRequest("GET", url, nil)
192193
if err != nil {
193-
return nil, err
194+
return []string{}, err
195+
}
196+
197+
for _, d := range headers {
198+
values := strings.Split(d, ":")
199+
if len(values) == 2 {
200+
output.Log("[+] New Header: " + values[0] + ": " + values[1])
201+
req.Header.Set(values[0], values[1])
202+
}
203+
}
204+
205+
client := new(http.Client)
206+
res, err := client.Do(req)
207+
if err != nil {
208+
return []string{}, err
194209
}
195210
defer res.Body.Close()
196211
if res.StatusCode != 200 {

0 commit comments

Comments
 (0)