Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/refactor/1' into re…
Browse files Browse the repository at this point in the history
…factor/1
  • Loading branch information
hazcod committed Apr 29, 2024
2 parents 4c3f234 + 0153887 commit 6a91248
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
16 changes: 6 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# vscode
/\~
~/.vscode-root
.vscode

# Binary
misconfig-mapper

# Release files
releases

# IntelliJ files
.idea/

# VS Code files
.vscode/

main
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ require (
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
)

require golang.org/x/sys v0.19.0 // indirect
31 changes: 8 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"strings"
"time"

"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
"golang.org/x/time/rate"
)

Expand Down Expand Up @@ -148,7 +148,6 @@ func parseRequestHeaders(rawHeaders string) map[string]string {
func parseRegex(v []string) string {
x := strings.Join(v, `|`) // Split array entries with regex alternation
x = strings.Replace(x, ".", `\.`, -1) // Escape dot characters
x = fmt.Sprintf(`%s`, x)

return x
}
Expand Down Expand Up @@ -197,7 +196,7 @@ func checkResponse(result *Result, service *Service, r *RequestContext) {
CheckRedirect: func(req *http.Request, via []*http.Request) error {
// Follow max amount of specified redirects
if len(via) >= r.MaxRedirects {
return fmt.Errorf("[-] Error: Too many redirects encountered for %v\n", result.URL)
return fmt.Errorf("[-] Error: Too many redirects encountered for %v", result.URL)
}
return nil
},
Expand All @@ -209,7 +208,7 @@ func checkResponse(result *Result, service *Service, r *RequestContext) {
requestBody = bytes.NewBuffer([]byte(fmt.Sprintf(`%v`, service.Request.Body)))
}

req, err := http.NewRequest(fmt.Sprintf(`%v`, service.Request.Method), result.URL, requestBody)
req, err := http.NewRequestWithContext(ctx, fmt.Sprintf(`%v`, service.Request.Method), result.URL, requestBody)
if err != nil {
if r.Verbose {
fmt.Printf("[-] Error: Failed to request %s (%v)\n", result.URL, err)
Expand Down Expand Up @@ -285,8 +284,6 @@ func checkResponse(result *Result, service *Service, r *RequestContext) {
pattern := fmt.Sprintf(`%s`, parseRegex(service.Response.Fingerprints)) // Transform array into regex pattern

Check failure on line 284 in main.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] main.go#L284

S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
Raw output
main.go:284:14: S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
		pattern := fmt.Sprintf(`%s`, parseRegex(service.Response.Fingerprints)) // Transform array into regex pattern
		           ^
result.Vulnerable = !!regexp.MustCompile(pattern).MatchString(fmt.Sprintf(`%v %v`, responseHeaders, string(body))) && statusCodeMatched

Check failure on line 285 in main.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] main.go#L285

SA4013: negating a boolean twice has no effect; is this a typo? (staticcheck)
Raw output
main.go:285:23: SA4013: negating a boolean twice has no effect; is this a typo? (staticcheck)
		result.Vulnerable = !!regexp.MustCompile(pattern).MatchString(fmt.Sprintf(`%v %v`, responseHeaders, string(body))) && statusCodeMatched
		                    ^
}

return
}

func handleResult(result *Result, reqCTX *RequestContext, width int) {
Expand Down Expand Up @@ -342,11 +339,7 @@ func isFile(path string) bool {
}

_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}

return true
return !os.IsNotExist(err)
}

func processInput(fileName string, input *[]string) {
Expand Down Expand Up @@ -397,7 +390,7 @@ func main() {

// Derrive terminal width
fd := int(os.Stdout.Fd())
width, _, _ := terminal.GetSize(fd)
width, _, _ := term.GetSize(fd)

services, err := loadTemplates()
if err != nil {
Expand Down Expand Up @@ -441,14 +434,11 @@ func main() {
switch strings.ToLower(*skipChecksFlag) {
case "", "y", "yes", "true", "on", "1", "enable":
reqCTX.SkipChecks = true
break
case "n", "no", "false", "off", "0", "disable":
reqCTX.SkipChecks = false
break
default:
reqCTX.SkipChecks = false
fmt.Printf("[-] Warning: Invalid skipChecks flag value supplied: \"%v\"\n", *skipChecksFlag)
break
}

// Parse "permutations" CLI flag
Expand All @@ -458,14 +448,11 @@ func main() {
switch strings.ToLower(*permutationsFlag) {
case "", "y", "yes", "true", "on", "1", "enable":
permutations = true
break
case "n", "no", "false", "off", "0", "disable":
permutations = false
break
default:
permutations = false
fmt.Printf("[-] Warning: Invalid permutations flag value supplied: \"%v\"\n", *permutationsFlag)
break
}

if isFile(target) {
Expand All @@ -478,9 +465,7 @@ func main() {
possibleDomains = append(possibleDomains, returnPossibleDomains(e)...)
}
} else {
for _, e := range targets {
possibleDomains = append(possibleDomains, e)
}
possibleDomains = append(possibleDomains, targets...)
}
} else {
// Treat target as a domain
Expand Down Expand Up @@ -509,8 +494,8 @@ func main() {
}

// Crafting URL
if !!permutations {
targetURL = strings.Replace(fmt.Sprintf(`%v%v`, selectedService.Request.BaseURL, path), "{TARGET}", fmt.Sprintf(`%s`, domain), -1)
if permutations {
targetURL = strings.Replace(fmt.Sprintf(`%v%v`, selectedService.Request.BaseURL, path), "{TARGET}", domain, -1)
} else {
targetURL = fmt.Sprintf(`%v%v`, domain, path)
}
Expand Down

0 comments on commit 6a91248

Please sign in to comment.