-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvendor-scan.go
101 lines (93 loc) · 3.71 KB
/
vendor-scan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"io/ioutil"
"log"
"regexp"
"strings"
)
func vendorpassScan(target string, product string, tag string) Issue {
var vendorpassIssue Issue
if !strings.HasSuffix(target, "/") {
target += "/"
}
for _, entry := range vendorDB.Entries {
if entry.Tag == tag { // LOOK FOR THE EXACT VENDOR PASS ENTRY WE WANNA TRY
for _, payloadPath := range entry.Payload.Paths {
resp, err := makeHTTPRequest(target+payloadPath, entry.Payload.Headers, entry.Payload.Body, entry.Payload.Method)
if err != nil { // IF THERE WAS AN ERROR MAKING THE REQ
log.Println(err)
return vendorpassIssue
} else { // IF THERE WERE NO ERRORS
//DO THE MATCHING OVER HERE
// FIRST DO NON-200 STATUS CODE MATCHES HERE
if entry.Matchers.ResponseCode != 200 {
if resp.StatusCode == entry.Matchers.ResponseCode {
log.Println(target, "[", product, "]", "is vulnerable with default password - ", entry.Issue)
vendorpassIssue.IssueTitle = entry.Issue
vendorpassIssue.URL = target + payloadPath
vendorpassIssue.AdditionalContext = "The resulting non-200 status code matched with the one in DB."
return vendorpassIssue
}
}
// SECONDLY CHECK FOR THE RESPONSE PATH
if entry.Matchers.Responsepath != "" {
if strings.Contains(resp.Request.URL.Path, entry.Matchers.Responsepath) {
log.Println(target, "[", product, "]", "is vulnerable with default password - ", entry.Issue)
vendorpassIssue.IssueTitle = entry.Issue
vendorpassIssue.URL = target + payloadPath
vendorpassIssue.AdditionalContext = "The resulting URL path matched with the one in DB."
return vendorpassIssue
}
}
// THIRDLY CHECK OVER THE RESPONSE HEADERS
if entry.Matchers.Headers != nil {
for headerKey, headerValue := range entry.Matchers.Headers {
for key, values := range resp.Header {
for _, value := range values {
if strings.EqualFold(strings.ToLower(headerKey), strings.ToLower(key)) && strings.Contains(strings.ToLower(value), strings.ToLower(headerValue)) {
log.Println(target, "[", product, "]", "is vulnerable with default password - ", entry.Issue)
vendorpassIssue.IssueTitle = entry.Issue
vendorpassIssue.URL = target + payloadPath
vendorpassIssue.AdditionalContext = "The resulting headers matched with those in the DB."
return vendorpassIssue
}
}
}
}
}
respBody, _ := ioutil.ReadAll(resp.Body)
// NEXT CHECK FOR STRINGS WITHIN RESPONSE BODY
if entry.Matchers.Strings != nil {
for _, matchString := range entry.Matchers.Strings {
matchRe := regexp.MustCompile(strings.ToLower(matchString))
if matchRe.MatchString(strings.ToLower(string(respBody))) {
log.Println(target, "[", product, "]", "is vulnerable with default password - ", entry.Issue)
vendorpassIssue.IssueTitle = entry.Issue
vendorpassIssue.URL = target + payloadPath
vendorpassIssue.AdditionalContext = "The resulting body had matching strings from the DB."
return vendorpassIssue
}
}
}
}
/*
fmt.Printf("Vendor: %s\n", vendor)
fmt.Println("Payload:")
fmt.Printf(" Method: %s\n", entry.Payload.Method)
fmt.Println(" Headers:")
for key, value := range entry.Payload.Headers {
fmt.Printf(" %s: %s\n", key, value)
}
fmt.Println("Matchers:")
fmt.Printf(" Response Code: %d\n", entry.Matchers.ResponseCode)
fmt.Println(" Strings:", entry.Matchers.Strings)
fmt.Println(" Headers:")
for key, value := range entry.Matchers.Headers {
fmt.Printf(" %s: %s\n", key, value)
}
*/
}
}
}
return vendorpassIssue
}