Skip to content

Commit ee19085

Browse files
Bug fix on non exist file not save to the diff folder
1 parent d4e2286 commit ee19085

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

cli/webscan.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,9 @@ func StartWebScan(domains []string) []webscans.WebsiteDetails {
107107
csvData = append(csvData, []string{domain, technologyName, result.StatusCode, result.Source, strings.Join(result.Urls, ",")})
108108
}
109109

110-
helper.ResultPrintf(" +- URLs:\n")
111-
for _, urls := range result.Urls {
112-
helper.ResultPrintf(" +- %-150s\n", urls)
113-
}
110+
helper.ResultPrintf(" +- Extracted URLs: %d\n", len(result.Urls))
114111

115-
helper.ResultPrintln(">> Total Tech / Urls: (", len(result.Technologies), "/", len(result.Urls), "), Files saved in:", result.CrawlDirectory)
112+
helper.ResultPrintln(">> Total Tech: ", len(result.Technologies), ", Files saved in:", result.CrawlDirectory)
116113
helper.ResultPrintln("+> Diff files saved in:", result.CrawlDirectory+".diff", "\n")
117114
}
118115
helper.InfoPrintln("<========================================================================================")

webscans/crawler.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (c *Crawler) fetchAndParseURLs(isHttps bool, domain string, urlString strin
179179
Transport: lib.HttpClientTransportSettings,
180180
}
181181
urlOnly := parsedURL.Scheme + "://" + parsedURL.Host + parsedURL.Path
182-
helper.InfoPrintln("[-] Fetching url: ", urlOnly)
182+
helper.VerbosePrintln("[-] Fetching url: ", urlOnly)
183183
// Send a GET request to the website
184184
req, err := http.NewRequest("GET", urlOnly, nil)
185185
if err != nil {
@@ -276,17 +276,7 @@ func (c *Crawler) diffDirectories(domain, dir1, dir2 string) error {
276276

277277
pathInDir2 := filepath.Join(dir2, relPath)
278278

279-
// Check if file exists in the second directory
280-
if _, err := os.Stat(pathInDir2); os.IsNotExist(err) {
281-
url := domain + "/" + relPath
282-
if strings.HasSuffix(url, "index") {
283-
url = url[:len(url)-6] // Remove "/index"
284-
}
285-
helper.ResultPrintf("[!] URL %s [%s] does not exist in %s\n", url, relPath, dir2)
286-
return nil
287-
}
288-
289-
// Compare file contents
279+
// Read and pretty-print the contents
290280
content1, err := os.ReadFile(path)
291281
if err != nil {
292282
return err
@@ -297,6 +287,45 @@ func (c *Crawler) diffDirectories(domain, dir1, dir2 string) error {
297287
return err
298288
}
299289

290+
// Check if file exists in the second directory
291+
if _, err := os.Stat(pathInDir2); os.IsNotExist(err) {
292+
url := domain + "/" + relPath
293+
if strings.HasSuffix(url, "index") {
294+
url = url[:len(url)-6] // Remove "/index"
295+
}
296+
helper.ResultPrintf("[!] URL %s [%s] does not exist in %s\n", url, relPath, dir2)
297+
298+
// Create directories and write the file
299+
filePath := filepath.Join(c.outputDir, domain+".diff", relPath)
300+
dirPath := filepath.Dir(filePath)
301+
if err := os.MkdirAll(dirPath, 0755); err != nil {
302+
return err
303+
}
304+
file, err := os.Create(filePath)
305+
if err != nil {
306+
return err
307+
}
308+
defer file.Close()
309+
310+
// Secret scanning
311+
stringContent := make([]string, 0)
312+
for _, line := range strings.Split(contentStr1, "\n") {
313+
fmt.Fprintf(file, "%s\n", line)
314+
stringContent = append(stringContent, line)
315+
}
316+
matchedFiles, err := localscan.StringArrayScanning(stringContent, path)
317+
if err != nil {
318+
helper.ErrorPrintln(err)
319+
} else {
320+
for _, matchedFile := range matchedFiles {
321+
helper.CustomizePrintln(matchedFile)
322+
}
323+
}
324+
325+
return nil
326+
}
327+
328+
// Read and pretty-print the contents
300329
content2, err := os.ReadFile(pathInDir2)
301330
if err != nil {
302331
return err
@@ -307,6 +336,7 @@ func (c *Crawler) diffDirectories(domain, dir1, dir2 string) error {
307336
return err
308337
}
309338

339+
// Compare file contents
310340
if contentStr1 != contentStr2 {
311341
helper.InfoPrintf("[+] File %s differs between directories\n", relPath)
312342

0 commit comments

Comments
 (0)