Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HTML and Markdown output support (#63)
* Added HTML and Markdown output support * Add HTML color code in HTML template * Added changelog entry * Fixed copy paste mistake * Changed the html report to be grepable :) * Grepable output fixed
- Loading branch information
Showing
5 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package output | ||
|
||
import ( | ||
"html/template" | ||
"os" | ||
"time" | ||
|
||
"github.com/ffuf/ffuf/pkg/ffuf" | ||
) | ||
|
||
type htmlFileOutput struct { | ||
CommandLine string | ||
Time string | ||
Results []Result | ||
} | ||
|
||
const ( | ||
htmlTemplate = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1, maximum-scale=1.0" | ||
/> | ||
<title>FFUF Report - </title> | ||
<!-- CSS --> | ||
<link | ||
href="https://fonts.googleapis.com/icon?family=Material+Icons" | ||
rel="stylesheet" | ||
/> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" | ||
/> | ||
</head> | ||
<body> | ||
<nav> | ||
<div class="nav-wrapper"> | ||
<a href="#" class="brand-logo">FFUF</a> | ||
<ul id="nav-mobile" class="right hide-on-med-and-down"> | ||
</ul> | ||
</div> | ||
</nav> | ||
<main class="section no-pad-bot" id="index-banner"> | ||
<div class="container"> | ||
<br /><br /> | ||
<h1 class="header center ">FFUF Report</h1> | ||
<div class="row center"> | ||
<pre>{{ .CommandLine }}</pre> | ||
<pre>{{ .Time }}</pre> | ||
<table> | ||
<thead> | ||
<div style="display:none"> | ||
|result_raw|StatusCode|Input|Position|ContentLength|ContentWords| | ||
</div> | ||
<tr> | ||
<th>Status</th> | ||
<th>Input</th> | ||
<th>Position</th> | ||
<th>Length</th> | ||
<th>Words</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{range .Results}} | ||
<div style="display:none"> | ||
|result_raw|{{ .StatusCode }}|{{ .Input }}|{{ .Position }}|{{ .ContentLength }}|{{ .ContentWords }}| | ||
</div> | ||
<tr class="result-{{ .StatusCode }}" style="background-color: {{.HTMLColor}};"><td><font color="black" class="status-code">{{ .StatusCode }}</font></td><td>{{ .Input }}</td><td>{{ .Position }}</td><td>{{ .ContentLength }}</td><td>{{ .ContentWords }}</td></tr> | ||
{{end}} | ||
</tbody> | ||
</table> | ||
</div> | ||
<br /><br /> | ||
</div> | ||
</main> | ||
<!--JavaScript at end of body for optimized loading--> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> | ||
<style> | ||
body { | ||
display: flex; | ||
min-height: 100vh; | ||
flex-direction: column; | ||
} | ||
main { | ||
flex: 1 0 auto; | ||
} | ||
</style> | ||
</body> | ||
</html> | ||
` | ||
) | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package output | ||
|
||
import ( | ||
"html/template" | ||
"os" | ||
"time" | ||
|
||
"github.com/ffuf/ffuf/pkg/ffuf" | ||
) | ||
|
||
type markdownFileOutput struct { | ||
CommandLine string | ||
Time string | ||
Results []Result | ||
} | ||
|
||
const ( | ||
markdownTemplate = `# FFUF Report | ||
Command line : ` + "`{{.CommandLine}}`" + ` | ||
Time: ` + "{{ .Time }}" + ` | ||
| Input | Position | Status Code | Content Length | Content Words | | ||
| :---- | :------- | :---------- | :------------- | :------------ | | ||
{{range .Results}}| {{ .Input }} | {{ .Position }} | {{ .StatusCode }} | {{ .ContentLength }} | {{ .ContentWords }} | | ||
{{end}} | ||
` // The template format is not pretty but follows the markdown guide | ||
) | ||
|
||
func writeMarkdown(config *ffuf.Config, res []Result) error { | ||
|
||
ti := time.Now() | ||
|
||
outHTML := htmlFileOutput{ | ||
CommandLine: config.CommandLine, | ||
Time: ti.Format(time.RFC3339), | ||
Results: res, | ||
} | ||
|
||
f, err := os.Create(config.OutputFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
templateName := "output.md" | ||
t := template.New(templateName).Delims("{{", "}}") | ||
t.Parse(markdownTemplate) | ||
t.Execute(f, outHTML) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters