Skip to content

Commit e8d9b69

Browse files
fix probe json and csv output (#1966)
1 parent c4b06f6 commit e8d9b69

File tree

1 file changed

+75
-77
lines changed

1 file changed

+75
-77
lines changed

runner/runner.go

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,94 +1051,92 @@ func (r *Runner) RunEnumeration() {
10511051
gologger.Silent().Msgf("%s\n", resp.str)
10521052
}
10531053

1054-
if resp.Err != nil {
1055-
continue
1056-
}
1057-
10581054
// store responses or chain in directory
1059-
URL, _ := urlutil.Parse(resp.URL)
1060-
domainFile := resp.Method + ":" + URL.EscapedString()
1061-
hash := hashes.Sha1([]byte(domainFile))
1062-
domainResponseFile := fmt.Sprintf("%s.txt", hash)
1063-
screenshotResponseFile := fmt.Sprintf("%s.png", hash)
1064-
hostFilename := strings.ReplaceAll(URL.Host, ":", "_")
1065-
domainResponseBaseDir := filepath.Join(r.options.StoreResponseDir, "response")
1066-
domainScreenshotBaseDir := filepath.Join(r.options.StoreResponseDir, "screenshot")
1067-
responseBaseDir := filepath.Join(domainResponseBaseDir, hostFilename)
1068-
screenshotBaseDir := filepath.Join(domainScreenshotBaseDir, hostFilename)
1069-
1070-
var responsePath, screenshotPath, screenshotPathRel string
1071-
// store response
1072-
if r.scanopts.StoreResponse || r.scanopts.StoreChain {
1073-
if r.scanopts.OmitBody {
1074-
resp.Raw = strings.Replace(resp.Raw, resp.ResponseBody, "", -1)
1075-
}
1055+
if resp.Err == nil {
1056+
URL, _ := urlutil.Parse(resp.URL)
1057+
domainFile := resp.Method + ":" + URL.EscapedString()
1058+
hash := hashes.Sha1([]byte(domainFile))
1059+
domainResponseFile := fmt.Sprintf("%s.txt", hash)
1060+
screenshotResponseFile := fmt.Sprintf("%s.png", hash)
1061+
hostFilename := strings.ReplaceAll(URL.Host, ":", "_")
1062+
domainResponseBaseDir := filepath.Join(r.options.StoreResponseDir, "response")
1063+
domainScreenshotBaseDir := filepath.Join(r.options.StoreResponseDir, "screenshot")
1064+
responseBaseDir := filepath.Join(domainResponseBaseDir, hostFilename)
1065+
screenshotBaseDir := filepath.Join(domainScreenshotBaseDir, hostFilename)
1066+
1067+
var responsePath, screenshotPath, screenshotPathRel string
1068+
// store response
1069+
if r.scanopts.StoreResponse || r.scanopts.StoreChain {
1070+
if r.scanopts.OmitBody {
1071+
resp.Raw = strings.Replace(resp.Raw, resp.ResponseBody, "", -1)
1072+
}
10761073

1077-
responsePath = fileutilz.AbsPathOrDefault(filepath.Join(responseBaseDir, domainResponseFile))
1078-
// URL.EscapedString returns that can be used as filename
1079-
respRaw := resp.Raw
1080-
reqRaw := resp.RequestRaw
1081-
if len(respRaw) > r.scanopts.MaxResponseBodySizeToSave {
1082-
respRaw = respRaw[:r.scanopts.MaxResponseBodySizeToSave]
1083-
}
1084-
data := reqRaw
1085-
if r.options.StoreChain && resp.Response != nil && resp.Response.HasChain() {
1086-
data = append(data, append([]byte("\n"), []byte(resp.Response.GetChain())...)...)
1087-
}
1088-
data = append(data, respRaw...)
1089-
data = append(data, []byte("\n\n\n")...)
1090-
data = append(data, []byte(resp.URL)...)
1091-
_ = fileutil.CreateFolder(responseBaseDir)
1092-
writeErr := os.WriteFile(responsePath, data, 0644)
1093-
if writeErr != nil {
1094-
gologger.Error().Msgf("Could not write response at path '%s', to disk: %s", responsePath, writeErr)
1074+
responsePath = fileutilz.AbsPathOrDefault(filepath.Join(responseBaseDir, domainResponseFile))
1075+
// URL.EscapedString returns that can be used as filename
1076+
respRaw := resp.Raw
1077+
reqRaw := resp.RequestRaw
1078+
if len(respRaw) > r.scanopts.MaxResponseBodySizeToSave {
1079+
respRaw = respRaw[:r.scanopts.MaxResponseBodySizeToSave]
1080+
}
1081+
data := reqRaw
1082+
if r.options.StoreChain && resp.Response != nil && resp.Response.HasChain() {
1083+
data = append(data, append([]byte("\n"), []byte(resp.Response.GetChain())...)...)
1084+
}
1085+
data = append(data, respRaw...)
1086+
data = append(data, []byte("\n\n\n")...)
1087+
data = append(data, []byte(resp.URL)...)
1088+
_ = fileutil.CreateFolder(responseBaseDir)
1089+
writeErr := os.WriteFile(responsePath, data, 0644)
1090+
if writeErr != nil {
1091+
gologger.Error().Msgf("Could not write response at path '%s', to disk: %s", responsePath, writeErr)
1092+
}
1093+
resp.StoredResponsePath = responsePath
10951094
}
1096-
resp.StoredResponsePath = responsePath
1097-
}
10981095

1099-
if r.scanopts.Screenshot {
1100-
screenshotPath = fileutilz.AbsPathOrDefault(filepath.Join(screenshotBaseDir, screenshotResponseFile))
1101-
screenshotPathRel = filepath.Join(hostFilename, screenshotResponseFile)
1102-
_ = fileutil.CreateFolder(screenshotBaseDir)
1103-
err := os.WriteFile(screenshotPath, resp.ScreenshotBytes, 0644)
1104-
if err != nil {
1105-
gologger.Error().Msgf("Could not write screenshot at path '%s', to disk: %s", screenshotPath, err)
1106-
}
1096+
if r.scanopts.Screenshot {
1097+
screenshotPath = fileutilz.AbsPathOrDefault(filepath.Join(screenshotBaseDir, screenshotResponseFile))
1098+
screenshotPathRel = filepath.Join(hostFilename, screenshotResponseFile)
1099+
_ = fileutil.CreateFolder(screenshotBaseDir)
1100+
err := os.WriteFile(screenshotPath, resp.ScreenshotBytes, 0644)
1101+
if err != nil {
1102+
gologger.Error().Msgf("Could not write screenshot at path '%s', to disk: %s", screenshotPath, err)
1103+
}
11071104

1108-
resp.ScreenshotPath = screenshotPath
1109-
resp.ScreenshotPathRel = screenshotPathRel
1110-
if r.scanopts.NoScreenshotBytes {
1111-
resp.ScreenshotBytes = []byte{}
1105+
resp.ScreenshotPath = screenshotPath
1106+
resp.ScreenshotPathRel = screenshotPathRel
1107+
if r.scanopts.NoScreenshotBytes {
1108+
resp.ScreenshotBytes = []byte{}
1109+
}
11121110
}
1113-
}
11141111

1115-
if indexFile != nil {
1116-
indexData := fmt.Sprintf("%s %s (%d %s)\n", resp.StoredResponsePath, resp.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
1117-
_, _ = indexFile.WriteString(indexData)
1118-
}
1119-
if indexScreenshotFile != nil && resp.ScreenshotPathRel != "" {
1120-
indexData := fmt.Sprintf("%s %s (%d %s)\n", resp.ScreenshotPathRel, resp.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
1121-
_, _ = indexScreenshotFile.WriteString(indexData)
1122-
}
1112+
if indexFile != nil {
1113+
indexData := fmt.Sprintf("%s %s (%d %s)\n", resp.StoredResponsePath, resp.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
1114+
_, _ = indexFile.WriteString(indexData)
1115+
}
1116+
if indexScreenshotFile != nil && resp.ScreenshotPathRel != "" {
1117+
indexData := fmt.Sprintf("%s %s (%d %s)\n", resp.ScreenshotPathRel, resp.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
1118+
_, _ = indexScreenshotFile.WriteString(indexData)
1119+
}
11231120

1124-
if r.scanopts.StoreVisionReconClusters {
1125-
foundCluster := false
1126-
pHash, _ := resp.KnowledgeBase["pHash"].(uint64)
1127-
for i, cluster := range r.pHashClusters {
1128-
distance, _ := goimagehash.NewImageHash(pHash, goimagehash.PHash).Distance(goimagehash.NewImageHash(cluster.BasePHash, goimagehash.PHash))
1129-
if distance <= hammingDistanceThreshold {
1130-
r.pHashClusters[i].Hashes = append(r.pHashClusters[i].Hashes, pHashUrl{PHash: pHash, Url: resp.URL})
1131-
foundCluster = true
1132-
break
1121+
if r.scanopts.StoreVisionReconClusters {
1122+
foundCluster := false
1123+
pHash, _ := resp.KnowledgeBase["pHash"].(uint64)
1124+
for i, cluster := range r.pHashClusters {
1125+
distance, _ := goimagehash.NewImageHash(pHash, goimagehash.PHash).Distance(goimagehash.NewImageHash(cluster.BasePHash, goimagehash.PHash))
1126+
if distance <= hammingDistanceThreshold {
1127+
r.pHashClusters[i].Hashes = append(r.pHashClusters[i].Hashes, pHashUrl{PHash: pHash, Url: resp.URL})
1128+
foundCluster = true
1129+
break
1130+
}
11331131
}
1134-
}
11351132

1136-
if !foundCluster {
1137-
newCluster := pHashCluster{
1138-
BasePHash: pHash,
1139-
Hashes: []pHashUrl{{PHash: pHash, Url: resp.URL}},
1133+
if !foundCluster {
1134+
newCluster := pHashCluster{
1135+
BasePHash: pHash,
1136+
Hashes: []pHashUrl{{PHash: pHash, Url: resp.URL}},
1137+
}
1138+
r.pHashClusters = append(r.pHashClusters, newCluster)
11401139
}
1141-
r.pHashClusters = append(r.pHashClusters, newCluster)
11421140
}
11431141
}
11441142

0 commit comments

Comments
 (0)