Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature load http headers from file #46

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ type StringSet struct {
set map[string]bool
}

// Shim type for a header tuple
type StringDict struct {
set map[string]string
}

// Contains State that are read in from the command
// line when the program is invoked.
type State struct {
Expand Down Expand Up @@ -96,6 +101,8 @@ type State struct {
Terminate bool
StdIn bool
InsecureSSL bool
Headers StringDict
HeaderFile string
}

type RedirectHandler struct {
Expand Down Expand Up @@ -188,6 +195,10 @@ func MakeRequest(s *State, fullUrl, cookie string) (*int, *int64) {
req.SetBasicAuth(s.Username, s.Password)
}

for key, value := range s.Headers.set {
req.Header.Set(key, value)
}

resp, err := s.Client.Do(req)

if err != nil {
Expand Down Expand Up @@ -240,6 +251,7 @@ func ParseCmdLine() *State {
s := State{
StatusCodes: IntSet{set: map[int]bool{}},
WildcardIps: StringSet{set: map[string]bool{}},
Headers: StringDict{set: map[string]string{}},
IsWildcard: false,
StdIn: false,
}
Expand All @@ -257,6 +269,7 @@ func ParseCmdLine() *State {
flag.StringVar(&extensions, "x", "", "File extension(s) to search for (dir mode only)")
flag.StringVar(&s.UserAgent, "a", "", "Set the User-Agent string (dir mode only)")
flag.StringVar(&proxy, "p", "", "Proxy to use for requests [http(s)://host:port] (dir mode only)")
flag.StringVar(&s.HeaderFile, "hf", "", "File of HTTP Headers to use (colon separated, like a normal HTTP Request) (dir mode only)")
flag.BoolVar(&s.Verbose, "v", false, "Verbose output (errors)")
flag.BoolVar(&s.ShowIPs, "i", false, "Show IP addresses (dns mode only)")
flag.BoolVar(&s.ShowCNAME, "cn", false, "Show CNAME records (dns mode only, cannot be used with '-i' option)")
Expand Down Expand Up @@ -353,6 +366,26 @@ func ParseCmdLine() *State {
}
}

if s.HeaderFile != "" {
if _, err := os.Stat(s.HeaderFile); os.IsNotExist(err) {
fmt.Println("[!] Header File (-hf): File does not exist:", s.HeaderFile)
valid = false
}

HeaderList, err := os.Open(s.HeaderFile)
if err != nil {
panic("Failed to open wordlist")
}
defer HeaderList.Close()

scanner := bufio.NewScanner(HeaderList)
for scanner.Scan() {
word := scanner.Text()
keypair := strings.SplitN(word, ": ", 2)
s.Headers.set[keypair[0]] = keypair[1]
}
}

// status codes are comma separated
if codes != "" {
for _, c := range strings.Split(codes, ",") {
Expand Down Expand Up @@ -812,6 +845,10 @@ func ShowConfig(state *State) {
if state.Verbose {
fmt.Printf("[+] Verbose : true\n")
}

if state.HeaderFile != "" {
fmt.Printf("[+] Header File : %s\n", state.HeaderFile)
}
}

Ruler(state)
Expand Down