This commit is contained in:
edoardottt
2022-09-03 13:34:49 +02:00
parent fa7be5ac3c
commit 4cb5e2e8f6
22 changed files with 221 additions and 223 deletions
+25 -25
View File
@@ -43,9 +43,9 @@ import (
"github.com/gocolly/colly/extensions"
)
//Crawler it's the actual crawler engine.
//It controls all the behaviours of a scan
//(event handlers, secrets, errors, extensions and endpoints scanning).
// Crawler it's the actual crawler engine.
// It controls all the behaviours of a scan
// (event handlers, secrets, errors, extensions and endpoints scanning).
func Crawler(target string, txt string, html string, delayTime int, concurrency int,
ignore string, ignoreTxt string, cache bool, timeout int, intensive bool, rua bool,
proxy string, insecure bool, secrets bool, secretsFile []string, plain bool, endpoints bool,
@@ -80,19 +80,19 @@ func Crawler(target string, txt string, html string, delayTime int, concurrency
os.Exit(1)
}
//clean target input
// clean target input
target = utils.RemoveProtocol(target)
ignoreSlice := []string{}
ignoreBool := false
//if ignore -> produce the slice
// if ignore -> produce the slice
if ignore != "" {
ignoreBool = true
ignoreSlice = utils.CheckInputArray(ignore)
}
//if ignoreTxt -> produce the slice
// if ignoreTxt -> produce the slice
if ignoreTxt != "" {
ignoreBool = true
ignoreSlice = utils.ReadFile(ignoreTxt)
@@ -105,7 +105,7 @@ func Crawler(target string, txt string, html string, delayTime int, concurrency
FinalErrors := []scanner.ErrorMatched{}
FinalInfos := []scanner.InfoMatched{}
//crawler creation
// crawler creation
c := CreateColly(delayTime, concurrency, cache, timeout, intensive, rua, proxy, insecure, userAgent, target)
// On every a element which has href attribute call callback
@@ -276,7 +276,7 @@ func Crawler(target string, txt string, html string, delayTime int, concurrency
}
})
//Add headers (if needed) on each request
// Add headers (if needed) on each request
if (len(headers)) > 0 {
c.OnRequest(func(r *colly.Request) {
for header, value := range headers {
@@ -290,7 +290,7 @@ func Crawler(target string, txt string, html string, delayTime int, concurrency
lengthOk := len(string(r.Body)) > 10
//if endpoints or secrets or filetype: scan
// if endpoints or secrets or filetype: scan
if endpoints || secrets || (1 <= fileType && fileType <= 7) || errors || info {
// HERE SCAN FOR SECRETS
if secrets && lengthOk {
@@ -367,8 +367,8 @@ func Crawler(target string, txt string, html string, delayTime int, concurrency
return FinalResults, FinalSecrets, FinalEndpoints, FinalExtensions, FinalErrors, FinalInfos
}
//CreateColly takes as input all the settings needed to instantiate
//a new Colly Collector object and it returns this object.
// CreateColly takes as input all the settings needed to instantiate
// a new Colly Collector object and it returns this object.
func CreateColly(delayTime int, concurrency int, cache bool, timeout int,
intensive bool, rua bool, proxy string, insecure bool, userAgent string, target string) *colly.Collector {
c := colly.NewCollector(
@@ -428,13 +428,13 @@ func CreateColly(delayTime int, concurrency int, cache bool, timeout int,
return c
}
//huntSecrets hunts for secrets
// huntSecrets hunts for secrets.
func huntSecrets(secretsFile []string, target string, body string) []scanner.SecretMatched {
secrets := SecretsMatch(target, body, secretsFile)
return secrets
}
//SecretsMatch checks if a body matches some secrets
// SecretsMatch checks if a body matches some secrets.
func SecretsMatch(url string, body string, secretsFile []string) []scanner.SecretMatched {
var secrets []scanner.SecretMatched
@@ -475,13 +475,13 @@ func SecretsMatch(url string, body string, secretsFile []string) []scanner.Secre
return secrets
}
//huntEndpoints hunts for juicy endpoints
// huntEndpoints hunts for juicy endpoints.
func huntEndpoints(endpointsFile []string, target string) []scanner.EndpointMatched {
endpoints := EndpointsMatch(target, endpointsFile)
return endpoints
}
//EndpointsMatch check if an endpoint matches a juicy parameter
// EndpointsMatch check if an endpoint matches a juicy parameter.
func EndpointsMatch(target string, endpointsFile []string) []scanner.EndpointMatched {
endpoints := []scanner.EndpointMatched{}
matched := []scanner.Parameter{}
@@ -510,7 +510,7 @@ func EndpointsMatch(target string, endpointsFile []string) []scanner.EndpointMat
return endpoints
}
//huntExtensions hunts for extensions
// huntExtensions hunts for extensions.
func huntExtensions(target string, severity int) scanner.FileTypeMatched {
extension := scanner.FileTypeMatched{}
copyTarget := target
@@ -532,13 +532,13 @@ func huntExtensions(target string, severity int) scanner.FileTypeMatched {
return extension
}
//huntErrors hunts for errors
// huntErrors hunts for errors.
func huntErrors(target string, body string) []scanner.ErrorMatched {
errorsSlice := ErrorsMatch(target, body)
return errorsSlice
}
//ErrorsMatch checks the patterns for errors
// ErrorsMatch checks the patterns for errors.
func ErrorsMatch(url string, body string) []scanner.ErrorMatched {
errors := []scanner.ErrorMatched{}
@@ -556,13 +556,13 @@ func ErrorsMatch(url string, body string) []scanner.ErrorMatched {
return errors
}
//huntInfos hunts for infos
// huntInfos hunts for infos.
func huntInfos(target string, body string) []scanner.InfoMatched {
infosSlice := InfoMatch(target, body)
return infosSlice
}
//InfoMatch checks the patterns for infos
// InfoMatch checks the patterns for infos.
func InfoMatch(url string, body string) []scanner.InfoMatched {
infos := []scanner.InfoMatched{}
@@ -580,7 +580,7 @@ func InfoMatch(url string, body string) []scanner.InfoMatched {
return infos
}
//RetrieveBody retrieves the body (in the response) of a url
// RetrieveBody retrieves the body (in the response) of a url.
func RetrieveBody(target string) string {
sb, err := GetRequest(target)
if err == nil && sb != "" {
@@ -590,7 +590,7 @@ func RetrieveBody(target string) string {
return ""
}
//IgnoreMatch checks if the URL should be ignored or not.
// IgnoreMatch checks if the URL should be ignored or not.
func IgnoreMatch(url string, ignoreSlice []string) bool {
for _, ignore := range ignoreSlice {
if strings.Contains(url, ignore) {
@@ -601,9 +601,9 @@ func IgnoreMatch(url string, ignoreSlice []string) bool {
return false
}
//intensiveOk checks if a given url can be crawled
//in intensive mode (if the 2nd level domain matches with
//the inputted target).
// intensiveOk checks if a given url can be crawled
// in intensive mode (if the 2nd level domain matches with
// the inputted target).
func intensiveOk(target string, urlInput string) bool {
root, err := utils.GetRootHost(urlInput)
if err != nil {
+15 -15
View File
@@ -33,8 +33,8 @@ import (
"net/http"
)
//GetRequest performs a GET request and return
//a string (the body of the response).
// GetRequest performs a GET request and return
// a string (the body of the response).
func GetRequest(target string) (string, error) {
resp, err := http.Get(target)
if err != nil {
@@ -42,33 +42,33 @@ func GetRequest(target string) (string, error) {
}
defer resp.Body.Close()
//We Read the response body on the line below.
// We Read the response body on the line below.
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
//Convert the body to type string
// Convert the body to type string
sb := string(body)
return sb, nil
}
//PostRequest performs a POST request and return
//a string (the body of the response)
//the map in the input should contains the data fields and values
//in this way for example:
//{ email: test@example.com, password: stupid_pwd }.
// PostRequest performs a POST request and return
// a string (the body of the response)
// the map in the input should contains the data fields and values
// in this way for example:
// { email: test@example.com, password: stupid_pwd }.
func PostRequest(target string, data map[string]string) (string, error) {
postBody, _ := json.Marshal(data)
responseBody := bytes.NewBuffer(postBody)
//Leverage Go's HTTP Post function to make request
// Leverage Go's HTTP Post function to make request
resp, err := http.Post(target, "application/json", responseBody)
//Handle Error
// Handle Error
if err != nil {
return "", err
}
defer resp.Body.Close()
//Read the response body
// Read the response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
@@ -79,15 +79,15 @@ func PostRequest(target string, data map[string]string) (string, error) {
return sb, nil
}
//HeadRequest performs a HEAD request and return
//a string (the headers of the response).
// HeadRequest performs a HEAD request and return
// a string (the headers of the response).
func HeadRequest(target string) (string, error) {
resp, err := http.Head(target)
if err != nil {
return "", err
}
defer resp.Body.Close()
//Read the response body
// Read the response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
+7 -7
View File
@@ -35,7 +35,7 @@ import (
"time"
)
//Firefox versions
// Firefox versions.
var ffVersions = []float32{
58.0,
57.0,
@@ -46,7 +46,7 @@ var ffVersions = []float32{
35.0,
}
//Chrome versions
// Chrome versions.
var chromeVersions = []string{
"65.0.3325.146",
"64.0.3282.0",
@@ -55,7 +55,7 @@ var chromeVersions = []string{
"37.0.2062.124",
}
//Operating system
// Operating system.
var osStrings = []string{
"Macintosh; Intel Mac OS X 10_10",
"Windows NT 10.0",
@@ -65,7 +65,7 @@ var osStrings = []string{
"X11; Linux x86_64",
}
//genFirefoxUA generates a random Firefox User Agent
// genFirefoxUA generates a random Firefox User Agent.
func genFirefoxUA() string {
rand.Seed(time.Now().UnixNano())
version := ffVersions[rand.Intn(len(ffVersions))]
@@ -74,7 +74,7 @@ func genFirefoxUA() string {
return fmt.Sprintf("Mozilla/5.0 (%s; rv:%.1f) Gecko/20100101 Firefox/%.1f", os, version, version)
}
//genChromeUA generates a random Chrome User Agent
// genChromeUA generates a random Chrome User Agent.
func genChromeUA() string {
rand.Seed(time.Now().UnixNano())
version := chromeVersions[rand.Intn(len(chromeVersions))]
@@ -83,8 +83,8 @@ func genChromeUA() string {
return fmt.Sprintf("Mozilla/5.0 (%s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36", os, version)
}
//GenerateRandomUserAgent generates a random user agent
//(can be Chrome or Firefox).
// GenerateRandomUserAgent generates a random user agent
// (can be Chrome or Firefox).
func GenerateRandomUserAgent() string {
rand.Seed(time.Now().UnixNano())
+6 -6
View File
@@ -34,16 +34,16 @@ import (
"github.com/edoardottt/cariddi/utils"
)
//CheckDataPost should take as input a string and checks
//if it's correctly formatted to be represented as post data
//TODO - for now cariddi sends only GET requests.
// CheckDataPost should take as input a string and checks
// if it's correctly formatted to be represented as post data
// TODO - for now cariddi sends only GET requests.
func CheckDataPost(input string) (map[string]string, error) {
// ===== TODO =======
return map[string]string{}, nil
}
//CheckOutputFile checks if the string provided as input
//is formatted in a correct way.
// CheckOutputFile checks if the string provided as input
// is formatted in a correct way.
func CheckOutputFile(input string) bool {
invalid := []string{"\\", "/", "'", "\""}
for _, elem := range invalid {
@@ -55,7 +55,7 @@ func CheckOutputFile(input string) bool {
return true
}
//CheckFlags checks the flags taken as input.
// CheckFlags checks the flags taken as input.
func CheckFlags(flags Input) {
if flags.TXT != "" {
if !CheckOutputFile(flags.TXT) {
+5 -5
View File
@@ -30,8 +30,8 @@ import (
"flag"
)
//Input struct.
//It contains all the possible options.
// Input struct.
// It contains all the possible options.
type Input struct {
Version bool
Delay int
@@ -62,9 +62,9 @@ type Input struct {
UserAgent string
}
//ScanFlag defines all the options taken
//as input and scan them, then it returns
//an Input struct.
// ScanFlag defines all the options taken
// as input and scan them, then it returns
// an Input struct.
func ScanFlag() Input {
versionPtr := flag.Bool("version", false, "Print the version.")
delayPtr := flag.Int("d", 0, "Delay between a page crawled and another.")
+5 -5
View File
@@ -35,8 +35,8 @@ import (
"github.com/edoardottt/cariddi/utils"
)
//ScanTargets return the array of elements
//taken as input on stdin.
// ScanTargets return the array of elements
// taken as input on stdin.
func ScanTargets() []string {
var result []string
@@ -52,9 +52,9 @@ func ScanTargets() []string {
return utils.RemoveDuplicateValues(result)
}
//GetHeaders returns the headers provided as input
//using the headers flag.
//E.g. -headers \"Cookie: auth=yes;;Client: type=2\".
// GetHeaders returns the headers provided as input
// using the headers flag.
// E.g. -headers \"Cookie: auth=yes;;Client: type=2\".
func GetHeaders(input string) map[string]string {
result := make(map[string]string)
+28 -30
View File
@@ -36,50 +36,49 @@ import (
"github.com/edoardottt/cariddi/utils"
)
//main function >
// main function.
func main() {
// Scan flags.
flags := input.ScanFlag()
//Print version and exit.
// Print version and exit.
if flags.Version {
output.Beautify()
os.Exit(0)
}
//Print help and exit.
// Print help and exit.
if flags.Help {
output.PrintHelp()
os.Exit(0)
}
//Print examples and exit.
// Print examples and exit.
if flags.Examples {
output.PrintExamples()
os.Exit(0)
}
//If it's possible print the cariddi banner.
// If it's possible print the cariddi banner.
if !flags.Plain {
output.Beautify()
}
//Read the targets from standard input.
// Read the targets from standard input.
targets := input.ScanTargets()
//Check if there are errors in the flags definition.
// Check if there are errors in the flags definition.
input.CheckFlags(flags)
//If it is needed, read custom endpoints definition
//from the specified file.
// If it is needed, read custom endpoints definition
// from the specified file.
var endpointsFileSlice []string
if flags.EndpointsFile != "" {
endpointsFileSlice = utils.ReadFile(flags.EndpointsFile)
}
//If it is needed, read custom secrets definition
//from the specified file.
// If it is needed, read custom secrets definition
// from the specified file.
var secretsFileSlice []string
if flags.SecretsFile != "" {
secretsFileSlice = utils.ReadFile(flags.SecretsFile)
@@ -92,20 +91,20 @@ func main() {
finalErrors := []scanner.ErrorMatched{}
finalInfos := []scanner.InfoMatched{}
//Create output files if needed (txt / html).
// Create output files if needed (txt / html).
var ResultTxt = ""
if flags.TXT != "" {
ResultTxt = utils.CreateOutputFile(flags.TXT, "results", "txt")
}
var ResultHtml = ""
var ResultHTML = ""
if flags.HTML != "" {
ResultHtml = utils.CreateOutputFile(flags.HTML, "", "html")
output.BannerHTML(ResultHtml)
output.HeaderHTML("Results", ResultHtml)
ResultHTML = utils.CreateOutputFile(flags.HTML, "", "html")
output.BannerHTML(ResultHTML)
output.HeaderHTML("Results", ResultHTML)
}
//Read headers if needed
// Read headers if needed
var headers map[string]string
if flags.HeadersFile != "" || flags.Headers != "" {
@@ -119,13 +118,12 @@ func main() {
headers = input.GetHeaders(headersInput)
}
//For each target generate a crawler and collect all the results.
// For each target generate a crawler and collect all the results.
for _, inp := range targets {
results, secrets, endpoints, extensions, errors, infos := crawler.Crawler(inp, ResultTxt, ResultHtml, flags.Delay,
results, secrets, endpoints, extensions, errors, infos := crawler.Crawler(inp, ResultTxt, ResultHTML, flags.Delay,
flags.Concurrency, flags.Ignore, flags.IgnoreTXT, flags.Cache, flags.Timeout, flags.Intensive,
flags.Rua, flags.Proxy, flags.Insecure, flags.Secrets, secretsFileSlice, flags.Plain, flags.Endpoints, endpointsFileSlice,
flags.Extensions, headers, flags.Errors, flags.Info, flags.Debug, flags.UserAgent)
flags.Rua, flags.Proxy, flags.Insecure, flags.Secrets, secretsFileSlice, flags.Plain, flags.Endpoints,
endpointsFileSlice, flags.Extensions, headers, flags.Errors, flags.Info, flags.Debug, flags.UserAgent)
finalResults = append(finalResults, results...)
finalSecret = append(finalSecret, secrets...)
@@ -135,7 +133,7 @@ func main() {
finalInfos = append(finalInfos, infos...)
}
//Remove duplicates from all the results.
// Remove duplicates from all the results.
finalResults = utils.RemoveDuplicateValues(finalResults)
finalSecret = scanner.RemoveDuplicateSecrets(finalSecret)
finalEndpoints = scanner.RemovDuplicateEndpoints(finalEndpoints)
@@ -151,18 +149,18 @@ func main() {
// IF HTML OUTPUT >
if flags.HTML != "" {
output.HtmlOutput(flags, ResultHtml, finalResults, finalSecret,
output.HTMLOutput(flags, ResultHTML, finalResults, finalSecret,
finalEndpoints, finalExtensions, finalErrors, finalInfos)
}
//If needed print secrets.
// If needed print secrets.
if !flags.Plain && len(finalSecret) != 0 {
for _, elem := range finalSecret {
output.EncapsulateCustomGreen(elem.Secret.Name, elem.Match+" in "+elem.URL)
}
}
//If needed print endpoints.
// If needed print endpoints.
if !flags.Plain && len(finalEndpoints) != 0 {
for _, elem := range finalEndpoints {
for _, parameter := range elem.Parameters {
@@ -179,21 +177,21 @@ func main() {
}
}
//If needed print extensions.
// If needed print extensions.
if !flags.Plain && len(finalExtensions) != 0 {
for _, elem := range finalExtensions {
output.EncapsulateCustomGreen(elem.Filetype.Extension, elem.URL+" matched!")
}
}
//If needed print errors.
// If needed print errors.
if !flags.Plain && len(finalErrors) != 0 {
for _, elem := range finalErrors {
output.EncapsulateCustomGreen(elem.Error.ErrorName, elem.Match+" in "+elem.URL)
}
}
//If needed print infos.
// If needed print infos.
if !flags.Plain && len(finalInfos) != 0 {
for _, elem := range finalInfos {
output.EncapsulateCustomGreen(elem.Info.Name, elem.Match+" in "+elem.URL)
+1 -1
View File
@@ -32,7 +32,7 @@ import (
"github.com/fatih/color"
)
//Beautify prints the banner + version
// Beautify prints the banner + version.
func Beautify() {
banner1 := " _ _ _ _ \n"
banner2 := " ___ __ _ _ __(_) __| | __| (_)\n"
+12 -12
View File
@@ -32,8 +32,8 @@ import (
"github.com/fatih/color"
)
//EncapsulateGreen takes as input a string and
//print a green prefix.
// EncapsulateGreen takes as input a string and
// print a green prefix.
func EncapsulateGreen(inp string) {
// Create a custom print function for convenience
green := color.New(color.FgGreen).PrintfFunc()
@@ -41,8 +41,8 @@ func EncapsulateGreen(inp string) {
fmt.Println(inp)
}
//EncapsulateRed takes as input a string and
//print a red prefix.
// EncapsulateRed takes as input a string and
// print a red prefix.
func EncapsulateRed(inp string) {
// Create a custom print function for convenience
red := color.New(color.FgRed).PrintfFunc()
@@ -50,8 +50,8 @@ func EncapsulateRed(inp string) {
fmt.Println(inp)
}
//EncapsulateYellow takes as input a string and
//print a yellow prefix.
// EncapsulateYellow takes as input a string and
// print a yellow prefix.
func EncapsulateYellow(inp string) {
// Create a custom print function for convenience
yellow := color.New(color.FgYellow).PrintfFunc()
@@ -59,8 +59,8 @@ func EncapsulateYellow(inp string) {
fmt.Println(inp)
}
//EncapsulateCustomGreen takes as input a string and
//print it with the green color.
// EncapsulateCustomGreen takes as input a string and
// print it with the green color.
func EncapsulateCustomGreen(alert string, inp string) {
// Create a custom print function for convenience
green := color.New(color.FgGreen).PrintfFunc()
@@ -68,8 +68,8 @@ func EncapsulateCustomGreen(alert string, inp string) {
fmt.Println(inp)
}
//EncapsulateCustomRed takes as input a string and
//print it with the red color.
// EncapsulateCustomRed takes as input a string and
// print it with the red color.
func EncapsulateCustomRed(alert string, inp string) {
// Create a custom print function for convenience
red := color.New(color.FgRed).PrintfFunc()
@@ -77,8 +77,8 @@ func EncapsulateCustomRed(alert string, inp string) {
fmt.Println(inp)
}
//EncapsulateCustomYellow takes as input a string and
//print it with the yellow color.
// EncapsulateCustomYellow takes as input a string and
// print it with the yellow color.
func EncapsulateCustomYellow(alert string, inp string) {
// Create a custom print function for convenience
yellow := color.New(color.FgYellow).PrintfFunc()
+1 -1
View File
@@ -28,7 +28,7 @@ package output
import "fmt"
//PrintExamples prints some examples
// PrintExamples prints some examples.
func PrintExamples() {
Beautify()
fmt.Println(`
+1 -1
View File
@@ -28,7 +28,7 @@ package output
import "fmt"
//PrintHelp prints the help.
// PrintHelp prints the help.
func PrintHelp() {
Beautify()
fmt.Println(`Usage of cariddi:
+5 -5
View File
@@ -31,7 +31,7 @@ import (
"os"
)
//BannerHTML appends the initial banner to html file
// BannerHTML appends the initial banner to html file.
func BannerHTML(filename string) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
@@ -50,7 +50,7 @@ func BannerHTML(filename string) {
file.Close()
}
//AppendOutputToHTML appends the output to html file
// AppendOutputToHTML appends the output to html file.
func AppendOutputToHTML(output string, status string, filename string, isLink bool) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
@@ -84,7 +84,7 @@ func AppendOutputToHTML(output string, status string, filename string, isLink bo
file.Close()
}
//HeaderHTML appends the html header
// HeaderHTML appends the html header.
func HeaderHTML(header string, filename string) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
@@ -99,7 +99,7 @@ func HeaderHTML(header string, filename string) {
file.Close()
}
//FooterHTML appends the footer
// FooterHTML appends the footer.
func FooterHTML(filename string) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
@@ -114,7 +114,7 @@ func FooterHTML(filename string) {
file.Close()
}
//BannerFooterHTML appends the final footer
// BannerFooterHTML appends the final footer.
func BannerFooterHTML(filename string) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
+25 -25
View File
@@ -36,15 +36,15 @@ import (
"github.com/edoardottt/cariddi/utils"
)
//PrintSimpleOutput prints line by line
// PrintSimpleOutput prints line by line.
func PrintSimpleOutput(out []string) {
for _, elem := range out {
fmt.Println(elem)
}
}
//TxtOutput it's the wrapper around all the txt things.
//Actually it manages everything related to TXT output.
// TxtOutput it's the wrapper around all the txt things.
// Actually it manages everything related to TXT output.
func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.SecretMatched,
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched) {
@@ -115,9 +115,9 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S
}
}
//HtmlOutput it's the wrapper around all the html things.
//Actually it manages everything related to HTML output.
func HtmlOutput(flags input.Input, ResultFilename string, finalResults []string, finalSecret []scanner.SecretMatched,
// HtmlOutput it's the wrapper around all the html things.
// Actually it manages everything related to HTML output.
func HTMLOutput(flags input.Input, resultFilename string, finalResults []string, finalSecret []scanner.SecretMatched,
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched) {
exists, err := utils.ElementExists("output-cariddi")
@@ -131,28 +131,28 @@ func HtmlOutput(flags input.Input, ResultFilename string, finalResults []string,
utils.CreateOutputFolder()
}
HeaderHTML("Results found", ResultFilename)
HeaderHTML("Results found", resultFilename)
for _, elem := range finalResults {
AppendOutputToHTML(elem, "", ResultFilename, true)
AppendOutputToHTML(elem, "", resultFilename, true)
}
FooterHTML(ResultFilename)
FooterHTML(resultFilename)
// if secrets flag enabled save also secrets
if flags.Secrets {
HeaderHTML("Secrets found", ResultFilename)
HeaderHTML("Secrets found", resultFilename)
for _, elem := range finalSecret {
AppendOutputToHTML(elem.Secret.Name+" - "+elem.Match+" in "+elem.URL, "", ResultFilename, false)
AppendOutputToHTML(elem.Secret.Name+" - "+elem.Match+" in "+elem.URL, "", resultFilename, false)
}
FooterHTML(ResultFilename)
FooterHTML(resultFilename)
}
// if endpoints flag enabled save also endpoints
if flags.Endpoints {
HeaderHTML("Endpoints found", ResultFilename)
HeaderHTML("Endpoints found", resultFilename)
for _, elem := range finalEndpoints {
for _, parameter := range elem.Parameters {
@@ -164,48 +164,48 @@ func HtmlOutput(flags input.Input, ResultFilename string, finalResults []string,
}
}
AppendOutputToHTML(finalString+" in "+elem.URL, "", ResultFilename, false)
AppendOutputToHTML(finalString+" in "+elem.URL, "", resultFilename, false)
}
}
FooterHTML(ResultFilename)
FooterHTML(resultFilename)
}
// if extensions flag enabled save also extensions
if 1 <= flags.Extensions && flags.Extensions <= 7 {
HeaderHTML("Extensions found", ResultFilename)
HeaderHTML("Extensions found", resultFilename)
for _, elem := range finalExtensions {
AppendOutputToHTML(elem.Filetype.Extension+" in "+elem.URL, "", ResultFilename, false)
AppendOutputToHTML(elem.Filetype.Extension+" in "+elem.URL, "", resultFilename, false)
}
FooterHTML(ResultFilename)
FooterHTML(resultFilename)
}
// if errors flag enabled save also errors
if flags.Errors {
HeaderHTML("Errors found", ResultFilename)
HeaderHTML("Errors found", resultFilename)
for _, elem := range finalErrors {
AppendOutputToHTML(elem.Error.ErrorName+" - "+elem.Match+" in "+elem.URL, "", ResultFilename, false)
AppendOutputToHTML(elem.Error.ErrorName+" - "+elem.Match+" in "+elem.URL, "", resultFilename, false)
}
FooterHTML(ResultFilename)
FooterHTML(resultFilename)
}
// if info flag enabled save also infos
if flags.Info {
HeaderHTML("Useful informations found", ResultFilename)
HeaderHTML("Useful informations found", resultFilename)
for _, elem := range finalInfos {
// Escape HTML comment to be shown on the result page
AppendOutputToHTML(elem.Info.Name+" - "+
strings.Replace(strings.Replace(elem.Match, "<", "&lt;", 10), ">", "&gt;", 10)+
" in "+elem.URL, "", ResultFilename, false)
" in "+elem.URL, "", resultFilename, false)
}
FooterHTML(ResultFilename)
FooterHTML(resultFilename)
}
BannerFooterHTML(ResultFilename)
BannerFooterHTML(resultFilename)
}
+2 -2
View File
@@ -31,8 +31,8 @@ import (
"os"
)
//AppendOutputToTxt opens the output file and append
//the string taken as input.
// AppendOutputToTxt opens the output file and append
// the string taken as input.
func AppendOutputToTxt(output string, filename string) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
+4 -4
View File
@@ -26,7 +26,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
package scanner
//Parameter struct.
// Parameter struct.
// Parameter = the name of the parameter.
// Attacks = Possible attacks.
type Parameter struct {
@@ -34,7 +34,7 @@ type Parameter struct {
Attacks []string
}
//EndpointMatched struct.
// EndpointMatched struct.
// Parameters = a list of parameters in a particular endpoint.
// Url = url (aka endpoint).
type EndpointMatched struct {
@@ -42,7 +42,7 @@ type EndpointMatched struct {
URL string
}
//GetJuicyParameters returns juicy parameters and their possible attacks.
// GetJuicyParameters returns juicy parameters and their possible attacks.
func GetJuicyParameters() []Parameter {
var juicyParameters = []Parameter{
{"apikey", []string{"Info"}},
@@ -186,7 +186,7 @@ func GetJuicyParameters() []Parameter {
return juicyParameters
}
//RemovDuplicateEndpoints removes duplicate endpoints found.
// RemovDuplicateEndpoints removes duplicate endpoints found.
func RemovDuplicateEndpoints(input []EndpointMatched) []EndpointMatched {
keys := make(map[string]bool)
list := []EndpointMatched{}
+4 -4
View File
@@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
package scanner
//Error struct.
// Error struct.
// ErrorName = the name that identifies the error.
// Regex = The regular expression to be matched.
type Error struct {
@@ -31,7 +31,7 @@ type Error struct {
Regex []string
}
//ErrorMatched struct.
// ErrorMatched struct.
// Error = Error struct.
// Url = url in which the error is found.
// Match = the string matching the regex.
@@ -41,7 +41,7 @@ type ErrorMatched struct {
Match string
}
//GetErrorRegexes returns all the error structs.
// GetErrorRegexes returns all the error structs.
func GetErrorRegexes() []Error {
var regexes = []Error{
{
@@ -150,7 +150,7 @@ func GetErrorRegexes() []Error {
return regexes
}
//RemoveDuplicateErrors removes duplicates from Errors found.
// RemoveDuplicateErrors removes duplicates from Errors found.
func RemoveDuplicateErrors(input []ErrorMatched) []ErrorMatched {
keys := make(map[string]bool)
list := []ErrorMatched{}
+8 -8
View File
@@ -26,7 +26,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
package scanner
//FileType struct.
// FileType struct.
// Extension = the file extension (doc, txt ..etc..).
// Severity = the 'importance' of the file found. Higher is better.
type FileType struct {
@@ -34,7 +34,7 @@ type FileType struct {
Severity int
}
//FileTypeMatched struct.
// FileTypeMatched struct.
// Filetype = Filetype struct.
// Url = url of the file found.
type FileTypeMatched struct {
@@ -42,12 +42,12 @@ type FileTypeMatched struct {
URL string
}
//GetExtensions returns all the extension structs.
// GetExtensions returns all the extension structs.
func GetExtensions() []FileType {
//extensions contains a list of known extensions
//and the TYPICAL (also say `in general`) associated severity.
//Why in general? Because a python file can be anything, it can
//contain secret data or not.
// extensions contains a list of known extensions
// and the TYPICAL (also say `in general`) associated severity.
// Why in general? Because a python file can be anything, it can
// contain secret data or not.
var extensions = []FileType{
{"key", 1},
{"env", 1},
@@ -111,7 +111,7 @@ func GetExtensions() []FileType {
return extensions
}
//RemoveDuplicateExtensions removes duplicates from Extensions found.
// RemoveDuplicateExtensions removes duplicates from Extensions found.
func RemoveDuplicateExtensions(input []FileTypeMatched) []FileTypeMatched {
keys := make(map[string]bool)
list := []FileTypeMatched{}
+4 -4
View File
@@ -23,7 +23,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
package scanner
//Info struct.
// Info struct.
// Name = the name that identifies the information.
// Regex = The regular expression to be matched.
type Info struct {
@@ -31,7 +31,7 @@ type Info struct {
Regex []string
}
//InfoMatched struct.
// InfoMatched struct.
// Info = Info struct.
// Url = url in which the information is found.
// Match = the string matching the regex.
@@ -41,7 +41,7 @@ type InfoMatched struct {
Match string
}
//GetInfoRegexes returns all the info structs.
// GetInfoRegexes returns all the info structs.
func GetInfoRegexes() []Info {
var regexes = []Info{
{
@@ -83,7 +83,7 @@ func GetInfoRegexes() []Info {
return regexes
}
//RemoveDuplicateInfos removes duplicates from Infos found.
// RemoveDuplicateInfos removes duplicates from Infos found.
func RemoveDuplicateInfos(input []InfoMatched) []InfoMatched {
keys := make(map[string]bool)
list := []InfoMatched{}
+5 -5
View File
@@ -26,7 +26,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
package scanner
//Secret struct.
// Secret struct.
// Name = the name that identifies the secret.
// Description.
// Regex = The regular expression matching the secret.
@@ -40,7 +40,7 @@ type Secret struct {
Poc string
}
//SecretMatched struct.
// SecretMatched struct.
// Secret = The secret matched (struct).
// Url = url in which is present the secret.
// Match = the string matching the regex.
@@ -50,8 +50,8 @@ type SecretMatched struct {
Match string
}
//GetSecretRegexes returns a slice of all
//the secret structs.
// GetSecretRegexes returns a slice of all
// the secret structs.
func GetSecretRegexes() []Secret {
var regexes = []Secret{
{
@@ -342,7 +342,7 @@ func GetSecretRegexes() []Secret {
return regexes
}
//RemoveDuplicateSecrets removes duplicates from secrets found.
// RemoveDuplicateSecrets removes duplicates from secrets found.
func RemoveDuplicateSecrets(input []SecretMatched) []SecretMatched {
keys := make(map[string]bool)
list := []SecretMatched{}
+17 -17
View File
@@ -36,10 +36,10 @@ import (
"strings"
)
//CreateOutputFolder creates the output folder
//If it fails exits with an error message.
// CreateOutputFolder creates the output folder
// If it fails exits with an error message.
func CreateOutputFolder() {
//Create a folder/directory at a full qualified path
// Create a folder/directory at a full qualified path
err := os.Mkdir("output-cariddi", 0755)
if err != nil {
fmt.Println("Can't create output folder.")
@@ -47,12 +47,12 @@ func CreateOutputFolder() {
}
}
//CreateOutputFile takes a target (of the attack), a subcommand
//(PORT-DNS-DIR-SUBDOMAIN-REPORT) and a format (json-html-txt).
//It creates the output folder if needed, then checks if the output file
//already exists, if yes asks the user if scilla has to overwrite it;
//if no scilla creates it.
//Whenever an instruction fails, it exits with an error message.
// CreateOutputFile takes a target (of the attack), a subcommand
// (PORT-DNS-DIR-SUBDOMAIN-REPORT) and a format (json-html-txt).
// It creates the output folder if needed, then checks if the output file
// already exists, if yes asks the user if scilla has to overwrite it;
// if no scilla creates it.
// Whenever an instruction fails, it exits with an error message.
func CreateOutputFile(target string, subcommand string, format string) string {
target = ReplaceBadCharacterOutput(target)
@@ -96,15 +96,15 @@ func CreateOutputFile(target string, subcommand string, format string) string {
return filename
}
//ReplaceBadCharacterOutput replaces forward-slashes
//with dashes (to avoid problems with output folder).
// ReplaceBadCharacterOutput replaces forward-slashes
// with dashes (to avoid problems with output folder).
func ReplaceBadCharacterOutput(input string) string {
result := strings.ReplaceAll(input, "/", "-")
return result
}
//ReadFile reads a file line per line
//and returns a slice of strings.
// ReadFile reads a file line per line
// and returns a slice of strings.
func ReadFile(inputFile string) []string {
file, err := os.Open(inputFile)
if err != nil {
@@ -123,7 +123,7 @@ func ReadFile(inputFile string) []string {
return text
}
//ElementExists returns whether the given file or directory exists.
// ElementExists returns whether the given file or directory exists.
func ElementExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
@@ -137,8 +137,8 @@ func ElementExists(path string) (bool, error) {
return false, err
}
//ReadHTTPRequestFromFile reads from a file an HTTP
//request and returns a *http.Request object.
// ReadHTTPRequestFromFile reads from a file an HTTP
// request and returns a *http.Request object.
func ReadHTTPRequestFromFile(inputFile string) (*http.Request, error) {
f, err := os.Open(inputFile)
if err != nil {
@@ -158,7 +158,7 @@ func ReadHTTPRequestFromFile(inputFile string) (*http.Request, error) {
return req, nil
}
//ReadEntireFile returns the content of the inputted file.
// ReadEntireFile returns the content of the inputted file.
func ReadEntireFile(inputFile string) []byte {
file, err := os.Open(inputFile)
if err != nil {
+9 -9
View File
@@ -31,8 +31,8 @@ import (
"strings"
)
//RemoveDuplicateValues removes duplicates from a slice
//of strings.
// RemoveDuplicateValues removes duplicates from a slice
// of strings.
func RemoveDuplicateValues(strSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
@@ -47,8 +47,8 @@ func RemoveDuplicateValues(strSlice []string) []string {
return list
}
//CheckInputArray checks the basic rules to
//be valid and then returns the array as input.
// CheckInputArray checks the basic rules to
// be valid and then returns the array as input.
// - Delete duplicates.
// - Avoid empty strings.
func CheckInputArray(input string) []string {
@@ -66,16 +66,16 @@ func CheckInputArray(input string) []string {
return result
}
//CheckCookies checks if the string provided to the
//-cookie option is valid.
//format: "name1:value1;name2:value2"
//It returns a slice of Cookies.
// CheckCookies checks if the string provided to the
// -cookie option is valid.
// format: "name1:value1;name2:value2"
// It returns a slice of Cookies.
func CheckCookies(input string) []*http.Cookie {
var result []*http.Cookie
if input == "" {
return result
}
//Split and get different pairs of (name,value)
// Split and get different pairs of (name,value)
pairs := strings.Split(input, ";")
if len(pairs) == 0 {
return result
+32 -32
View File
@@ -32,10 +32,10 @@ import (
"strings"
)
//GetHost takes as input a string and
//tries to parse it as url, if it's a
//well formatted url this function returns
//the host (the domain if you prefer).
// GetHost takes as input a string and
// tries to parse it as url, if it's a
// well formatted url this function returns
// the host (the domain if you prefer).
func GetHost(input string) string {
u, err := url.Parse(input)
if err != nil {
@@ -45,10 +45,10 @@ func GetHost(input string) string {
return u.Host
}
//GetProtocol takes as input a string and
//tries to parse it as url, if it's a
//well formatted url this function returns
//the protocol (the scheme if you prefer).
// GetProtocol takes as input a string and
// tries to parse it as url, if it's a
// well formatted url this function returns
// the protocol (the scheme if you prefer).
func GetProtocol(input string) string {
u, err := url.Parse(input)
if err != nil {
@@ -58,19 +58,19 @@ func GetProtocol(input string) string {
return u.Scheme
}
//GetRootHost takes as input a string and
//tries to parse it as url, if it's a
//well formatted url this function returns
//the second level domain.
// GetRootHost takes as input a string and
// tries to parse it as url, if it's a
// well formatted url this function returns
// the second level domain.
func GetRootHost(input string) (string, error) {
u, err := url.Parse(input)
if err != nil {
return "", err
}
//divide host and port, then split by dot
// divide host and port, then split by dot
parts := strings.Split(strings.Split(u.Host, ":")[0], ".")
//return the last two parts
// return the last two parts
if len(parts) > 1 {
return parts[len(parts)-2] + "." + parts[len(parts)-1], nil
}
@@ -78,17 +78,17 @@ func GetRootHost(input string) (string, error) {
return "", errors.New("domain formatted in a bad way")
}
//HasProtocol takes as input a string and
//checks if it has a protocol ( like in a
//URI/URL).
// HasProtocol takes as input a string and
// checks if it has a protocol ( like in a
// URI/URL).
func HasProtocol(input string) bool {
res := strings.Index(input, "://")
return res >= 0
}
//RemoveProtocol removes the protocol from
//the input string (something://...).
//If it's not present it returns the input.
// RemoveProtocol removes the protocol from
// the input string (something://...).
// If it's not present it returns the input.
func RemoveProtocol(input string) string {
res := strings.Index(input, "://")
if res >= 0 {
@@ -98,8 +98,8 @@ func RemoveProtocol(input string) string {
return input
}
//RemovePort removes port from the input string.
//If it's not present it returns the input.
// RemovePort removes port from the input string.
// If it's not present it returns the input.
func RemovePort(input string) string {
res := strings.Index(input, ":")
if res >= 0 {
@@ -109,11 +109,11 @@ func RemovePort(input string) string {
return input
}
//RetrieveParameters takes as input a string and
//if it's correctly url-formatted returns a slice
//of strings that are the parameters of the URL.
// RetrieveParameters takes as input a string and
// if it's correctly url-formatted returns a slice
// of strings that are the parameters of the URL.
func RetrieveParameters(input string) []string {
var result []string
result := []string{}
u, err := url.Parse(input)
if err != nil {
@@ -128,8 +128,8 @@ func RetrieveParameters(input string) []string {
return result
}
//AbsoluteURL takes as input a protocol, a domain and a path
//and returns the absolute URL with protocol + domain + path.
// AbsoluteURL takes as input a protocol, a domain and a path
// and returns the absolute URL with protocol + domain + path.
func AbsoluteURL(protocol string, target string, path string) string {
// if the path variable starts with a scheme, it means that the
// path is itself an absolute path.
@@ -144,7 +144,7 @@ func AbsoluteURL(protocol string, target string, path string) string {
return protocol + "://" + target + "/" + path
}
//SameDomain checks if two urls have the same domain.
// SameDomain checks if two urls have the same domain.
func SameDomain(url1 string, url2 string) bool {
u1, err := url.Parse(url1)
if err != nil {
@@ -163,8 +163,8 @@ func SameDomain(url1 string, url2 string) bool {
return u1.Host == u2.Host
}
//GetPath returns the path of the input string
//(if correctly URL-formatted).
// GetPath returns the path of the input string
// (if correctly URL-formatted).
func GetPath(input string) (string, error) {
u, err := url.Parse(input)
if err != nil {
@@ -174,7 +174,7 @@ func GetPath(input string) (string, error) {
return u.Path, nil
}
//IsEmailURL checks if the input string is a mail URL.
// IsEmailURL checks if the input string is a mail URL.
func IsEmailURL(input string) (bool, string) {
if input[:7] == "mailto:" {
return true, input[7:]