From b22d12e9fa3ac5ae40f5c162ce64f36ca847b075 Mon Sep 17 00:00:00 2001 From: Olivier Cervello Date: Fri, 3 Feb 2023 16:43:05 +0000 Subject: [PATCH] update --- pkg/output/json.go | 45 +++++++++++++++++++++++++++++---------- pkg/scanner/endpoints.go | 4 ++-- pkg/scanner/error.go | 10 ++++----- pkg/scanner/extensions.go | 4 ++-- pkg/scanner/info.go | 10 ++++----- pkg/scanner/secrets.go | 16 +++++++------- 6 files changed, 56 insertions(+), 33 deletions(-) diff --git a/pkg/output/json.go b/pkg/output/json.go index 6a547dd..47a0421 100644 --- a/pkg/output/json.go +++ b/pkg/output/json.go @@ -42,18 +42,23 @@ type jsonData struct { StatusCode int `json:"status_code"` Words int `json:"words"` Lines int `json:"lines"` - ContentType string `json:"content_type,omit_empty"` - ContentLength int `json:"content_length,omit_empty"` + ContentType string `json:"content_type,omitempty"` + ContentLength int `json:"content_length,omitempty"` Matches MatcherResults `json:"matches,omitempty"` // Host string `json:"host"` # TODO: Add when migrating to Colly 2.x } type MatcherResults struct { - Secrets []scanner.SecretMatched `json:"secrets,omit_empty"` - Parameters []scanner.Parameter `json:"parameters,omit_empty"` - FileType scanner.FileType `json:"filetype,omit_empty"` - Errors []scanner.ErrorMatched `json:"errors,omit_empty"` - Infos []scanner.InfoMatched `json:"infos,omit_empty"` + FileType scanner.FileType `json:"filetype,omitempty"` + Parameters []scanner.Parameter `json:"parameters,omitempty"` + Errors []MatcherResult `json:"errors,omitempty"` + Infos []MatcherResult `json:"infos,omitempty"` + Secrets []MatcherResult `json:"secrets,omitempty"` +} + +type MatcherResult struct { + Name string `json:"name"` + Match string `json:"match"` } func GetJsonString( @@ -89,13 +94,31 @@ func GetJsonString( // Parse lines from body lines := len(strings.Split(string(r.Body), "\n")) + // Process secrets + secretList := []MatcherResult{} + for _, secret := range secrets { + secretList = append(secretList, MatcherResult{secret.Secret.Name, secret.Match}) + } + + // Process infos + infoList := []MatcherResult{} + for _, info := range infos { + infoList = append(infoList, MatcherResult{info.Info.Name, info.Match}) + } + + // Process + errorList := []MatcherResult{} + for _, error := range errors { + errorList = append(errorList, MatcherResult{error.Error.ErrorName, error.Match}) + } + // Construct JSON response data := MatcherResults{ - Secrets: secrets, - Parameters: parameters, FileType: filetype, - Errors: errors, - Infos: infos, + Parameters: parameters, + Errors: errorList, + Infos: infoList, + Secrets: secretList, } resp := &jsonData{ URL: r.Request.URL.String(), diff --git a/pkg/scanner/endpoints.go b/pkg/scanner/endpoints.go index ba4fad3..463c7c6 100644 --- a/pkg/scanner/endpoints.go +++ b/pkg/scanner/endpoints.go @@ -30,8 +30,8 @@ package scanner // Parameter = the name of the parameter. // Attacks = Possible attacks. type Parameter struct { - Parameter string `json:"name,omitempty"` - Attacks []string `json:"attacks,omitempty"` + Parameter string + Attacks []string } // EndpointMatched struct. diff --git a/pkg/scanner/error.go b/pkg/scanner/error.go index 44c6855..9d3870e 100644 --- a/pkg/scanner/error.go +++ b/pkg/scanner/error.go @@ -27,8 +27,8 @@ package scanner // ErrorName = the name that identifies the error. // Regex = The regular expression to be matched. type Error struct { - ErrorName string `json:"name,omitempty"` - Regex []string `json:"regex,omitempty"` + ErrorName string + Regex []string } // ErrorMatched struct. @@ -36,9 +36,9 @@ type Error struct { // Url = url in which the error is found. // Match = the string matching the regex. type ErrorMatched struct { - Error Error `json:"details,omitempty"` - URL string `json:"-"` - Match string `json:"match,omitempty"` + Error Error + URL string + Match string } // GetErrorRegexes returns all the error structs. diff --git a/pkg/scanner/extensions.go b/pkg/scanner/extensions.go index 9aef287..f84feb2 100644 --- a/pkg/scanner/extensions.go +++ b/pkg/scanner/extensions.go @@ -30,8 +30,8 @@ package scanner // Extension = the file extension (doc, txt ..etc..). // Severity = the 'importance' of the file found. Higher is better. type FileType struct { - Extension string `json:"extension,omitempty"` - Severity int `json:"severity,omitempty"` + Extension string + Severity int } // FileTypeMatched struct. diff --git a/pkg/scanner/info.go b/pkg/scanner/info.go index 2754861..f45e9d5 100644 --- a/pkg/scanner/info.go +++ b/pkg/scanner/info.go @@ -27,8 +27,8 @@ package scanner // Name = the name that identifies the information. // Regex = The regular expression to be matched. type Info struct { - Name string `json:"name,omitempty"` - Regex []string `json:"regex,omitempty"` + Name string + Regex []string } // InfoMatched struct. @@ -36,9 +36,9 @@ type Info struct { // Url = url in which the information is found. // Match = the string matching the regex. type InfoMatched struct { - Info Info `json:"details,omitempty"` - URL string `json:"-"` - Match string `json:"match,omitempty"` + Info Info + URL string + Match string } // GetInfoRegexes returns all the info structs. diff --git a/pkg/scanner/secrets.go b/pkg/scanner/secrets.go index 835e149..b005d74 100644 --- a/pkg/scanner/secrets.go +++ b/pkg/scanner/secrets.go @@ -33,11 +33,11 @@ package scanner // FalsePositives = A list of known false positives. // PoC = cli command to check if the secret is valid or not. type Secret struct { - Name string `json:"name"` - Description string `json:"description"` - Regex string `json:"regex"` - FalsePositives []string `json:"-"` - Poc string `json:"-"` + Name string + Description string + Regex string + FalsePositives []string + Poc string } // SecretMatched struct. @@ -45,9 +45,9 @@ type Secret struct { // Url = url in which is present the secret. // Match = the string matching the regex. type SecretMatched struct { - Secret Secret `json:"details,omitempty"` - URL string `json:"-"` - Match string `json:"match,omitempty"` + Secret Secret + URL string + Match string } // GetSecretRegexes returns a slice of all