Skip to content

Commit 2cd95a3

Browse files
committed
add optional flag for request headers. Thanks bp0lr #7
1 parent fbeb172 commit 2cd95a3

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

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"
@@ -12,6 +11,7 @@ import (
1211

1312
"github.com/PuerkitoBio/goquery"
1413
"github.com/logrusorgru/aurora"
14+
flag "github.com/spf13/pflag"
1515
)
1616

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

6566
au = aurora.NewAurora(!*noColorsArg)
@@ -119,7 +120,7 @@ func main() {
119120
var sourcesBak []string
120121
var completedSuccessfully = true
121122
output.Log("[+] Getting sources from " + e)
122-
sources, err := getScriptSrc(e)
123+
sources, err := getScriptSrc(e, *HeaderArg)
123124
if err != nil {
124125
output.Error("[!] Couldn't get sources from "+e, err)
125126
}
@@ -187,11 +188,25 @@ func saveToFile(sources []string, path string) error {
187188
return w.Flush()
188189
}
189190

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

0 commit comments

Comments
 (0)