package output import ( "html/template" "os" "time" "github.com/ffuf/ffuf/pkg/ffuf" ) type htmlFileOutput struct { CommandLine string Time string Results []Result } const ( htmlTemplate = ` FFUF Report -


FFUF Report

{{ .CommandLine }}
{{ .Time }}
|result_raw|StatusCode|Input|Position|ContentLength|ContentWords|
{{range .Results}}
|result_raw|{{ .StatusCode }}|{{ .Input }}|{{ .Position }}|{{ .ContentLength }}|{{ .ContentWords }}|
{{end}}
Status Input Position Length Words
{{ .StatusCode }}{{ .Input }}{{ .Position }}{{ .ContentLength }}{{ .ContentWords }}


` ) // colorizeResults returns a new slice with HTMLColor attribute func colorizeResults(results []Result) []Result { newResults := make([]Result, 0) for _, r := range results { result := r result.HTMLColor = "black" s := result.StatusCode if s >= 200 && s <= 299 { result.HTMLColor = "#adea9e" } if s >= 300 && s <= 399 { result.HTMLColor = "#bbbbe6" } if s >= 400 && s <= 499 { result.HTMLColor = "#d2cb7e" } if s >= 500 && s <= 599 { result.HTMLColor = "#de8dc1" } newResults = append(newResults, result) } return newResults } func writeHTML(config *ffuf.Config, results []Result) error { results = colorizeResults(results) ti := time.Now() outHTML := htmlFileOutput{ CommandLine: config.CommandLine, Time: ti.Format(time.RFC3339), Results: results, } f, err := os.Create(config.OutputFile) if err != nil { return err } defer f.Close() templateName := "output.html" t := template.New(templateName).Delims("{{", "}}") t.Parse(htmlTemplate) t.Execute(f, outHTML) return nil }