@@ -1051,94 +1051,92 @@ func (r *Runner) RunEnumeration() {
1051
1051
gologger .Silent ().Msgf ("%s\n " , resp .str )
1052
1052
}
1053
1053
1054
- if resp .Err != nil {
1055
- continue
1056
- }
1057
-
1058
1054
// 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
+ }
1076
1073
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
1095
1094
}
1096
- resp .StoredResponsePath = responsePath
1097
- }
1098
1095
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
+ }
1107
1104
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
+ }
1112
1110
}
1113
- }
1114
1111
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
+ }
1123
1120
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
+ }
1133
1131
}
1134
- }
1135
1132
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 )
1140
1139
}
1141
- r .pHashClusters = append (r .pHashClusters , newCluster )
1142
1140
}
1143
1141
}
1144
1142
0 commit comments