diff --git a/internal/file/file.go b/internal/file/file.go index 4c46cca..8768e37 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -161,6 +161,7 @@ func ReadFile(inputFile string) []string { for scanner.Scan() { text = append(text, scanner.Text()) } + file.Close() return text diff --git a/pkg/crawler/colly.go b/pkg/crawler/colly.go index 8dd5b87..5319fb3 100644 --- a/pkg/crawler/colly.go +++ b/pkg/crawler/colly.go @@ -139,6 +139,7 @@ func New(scan *Scan) *Results { if scan.StoreResp { var err error outputPath, err = output.StoreHTTPResponse(r, scan.OutputDir) + if err != nil { log.Println(err) } diff --git a/pkg/crawler/useragents.go b/pkg/crawler/useragents.go index ada2079..54385b1 100644 --- a/pkg/crawler/useragents.go +++ b/pkg/crawler/useragents.go @@ -151,7 +151,8 @@ func GenerateRandomUserAgent() string { source := rand.NewSource(time.Now().UnixNano()) rng := rand.New(source) - decision := rng.Intn(100) + const maxRandomValue = 100 + decision := rng.Intn(maxRandomValue) var ua string if decision%2 == 0 { diff --git a/pkg/output/jsonl_test.go b/pkg/output/jsonl_test.go index fdee122..fd8c387 100644 --- a/pkg/output/jsonl_test.go +++ b/pkg/output/jsonl_test.go @@ -123,7 +123,7 @@ func TestJSONOutput(t *testing.T) { filetype: filetype, errors: errors, infos: infos, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]}}`, //nolint:lll + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll outputPath: "C:\\testDir1\\testDir2", }, { @@ -134,7 +134,7 @@ func TestJSONOutput(t *testing.T) { filetype: filetype, errors: errors, infos: infos, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]}}`, //nolint:lll + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll outputPath: "C:\\testDir1\\testDir2", }, { @@ -145,7 +145,7 @@ func TestJSONOutput(t *testing.T) { filetype: &scanner.FileType{}, errors: []scanner.ErrorMatched{}, infos: []scanner.InfoMatched{}, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128}`, //nolint: all + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"output_path":"C:\\testDir1\\testDir2"}`, //nolint: all outputPath: "C:\\testDir1\\testDir2", }, { @@ -156,7 +156,7 @@ func TestJSONOutput(t *testing.T) { filetype: &scanner.FileType{}, errors: []scanner.ErrorMatched{}, infos: []scanner.InfoMatched{}, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]}}`, //nolint:lll + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll outputPath: "C:\\testDir1\\testDir2", }, { @@ -167,7 +167,7 @@ func TestJSONOutput(t *testing.T) { filetype: &scanner.FileType{}, errors: []scanner.ErrorMatched{}, infos: []scanner.InfoMatched{}, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"parameters":[{"name":"id","attacks":[]}]}}`, //nolint:lll + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"parameters":[{"name":"id","attacks":[]}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll outputPath: "C:\\testDir1\\testDir2", }, { @@ -178,7 +178,7 @@ func TestJSONOutput(t *testing.T) { filetype: &scanner.FileType{}, errors: errors, infos: []scanner.InfoMatched{}, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}]}}`, //nolint:lll + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll outputPath: "C:\\testDir1\\testDir2", }, { @@ -189,7 +189,7 @@ func TestJSONOutput(t *testing.T) { filetype: &scanner.FileType{}, errors: []scanner.ErrorMatched{}, infos: infos, - want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}]}}`, //nolint:lll + want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll outputPath: "C:\\testDir1\\testDir2", }, { diff --git a/pkg/output/output.go b/pkg/output/output.go index 6e803e4..92f553f 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -36,7 +36,7 @@ import ( "github.com/edoardottt/cariddi/pkg/scanner" ) -// constant defined in file.go as well, for circular dependency +// constant defined in file.go as well, redefining here for circular dependency. const ( CariddiOutputFolder = "output-cariddi" ) @@ -53,7 +53,6 @@ func PrintSimpleOutput(out []string) { func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.SecretMatched, finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched, finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) { - exists, err := fileUtils.ElementExists(outputDir) if err != nil { fmt.Println("Error while creating the output directory.") @@ -126,7 +125,6 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S func HTMLOutput(flags input.Input, resultFilename string, finalResults []string, finalSecret []scanner.SecretMatched, finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched, finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) { - exists, err := fileUtils.ElementExists(outputDir) if err != nil {