| 1 | package output |
| 2 | |
| 3 | import ( |
| 4 | "html" |
| 5 | "html/template" |
| 6 | "os" |
| 7 | "time" |
| 8 | |
| 9 | "github.com/ffuf/ffuf/v2/pkg/ffuf" |
| 10 | ) |
| 11 | |
| 12 | type htmlResult struct { |
| 13 | Input map[string]string |
| 14 | Position int |
| 15 | StatusCode int64 |
| 16 | ContentLength int64 |
| 17 | ContentWords int64 |
| 18 | ContentLines int64 |
| 19 | ContentType string |
| 20 | RedirectLocation string |
| 21 | ScraperData string |
| 22 | Duration time.Duration |
| 23 | ResultFile string |
| 24 | Url string |
| 25 | Host string |
| 26 | HTMLColor string |
| 27 | FfufHash string |
| 28 | } |
| 29 | |
| 30 | type htmlFileOutput struct { |
| 31 | CommandLine string |
| 32 | Time string |
| 33 | Keys []string |
| 34 | Results []htmlResult |
| 35 | } |
| 36 | |
| 37 | const ( |
| 38 | htmlTemplate = ` |
| 39 | <!DOCTYPE html> |
| 40 | <html> |
| 41 | <head> |
| 42 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 43 | <meta |
| 44 | name="viewport" |
| 45 | content="width=device-width, initial-scale=1, maximum-scale=1.0" |
| 46 | /> |
| 47 | <title>FFUF Report - </title> |
| 48 | |
| 49 | <!-- CSS --> |
| 50 | <link |
| 51 | href="https://fonts.googleapis.com/icon?family=Material+Icons" |
| 52 | rel="stylesheet" |
| 53 | /> |
| 54 | <link |
| 55 | rel="stylesheet" |
| 56 | href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" |
| 57 | /> |
| 58 | <link |
| 59 | rel="stylesheet" |
| 60 | type="text/css" |
| 61 | href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css" |
| 62 | /> |
| 63 | |
| 64 | </head> |
| 65 | |
| 66 | <body> |
| 67 | <nav> |
| 68 | <div class="nav-wrapper"> |
| 69 | <a href="#" class="brand-logo">FFUF</a> |
| 70 | <ul id="nav-mobile" class="right hide-on-med-and-down"> |
| 71 | </ul> |
| 72 | </div> |
| 73 | </nav> |
| 74 | |
| 75 | <main class="section no-pad-bot" id="index-banner"> |
| 76 | <div class="container"> |
| 77 | <br /><br /> |
| 78 | <h1 class="header center ">FFUF Report</h1> |
| 79 | <div class="row center"> |
| 80 | |
| 81 | <pre>{{ .CommandLine }}</pre> |
| 82 | <pre>{{ .Time }}</pre> |
| 83 | |
| 84 | <table id="ffufreport"> |
| 85 | <thead> |
| 86 | <div style="display:none"> |
| 87 | |result_raw|StatusCode{{ range $keyword := .Keys }}|{{ $keyword | printf "%s" }}{{ end }}|Url|RedirectLocation|Position|ContentLength|ContentWords|ContentLines|ContentType|Duration|Resultfile|ScraperData|FfufHash| |
| 88 | </div> |
| 89 | <tr> |
| 90 | <th>Status</th> |
| 91 | {{ range .Keys }} <th>{{ . }}</th>{{ end }} |
| 92 | <th>URL</th> |
| 93 | <th>Redirect location</th> |
| 94 | <th>Position</th> |
| 95 | <th>Length</th> |
| 96 | <th>Words</th> |
| 97 | <th>Lines</th> |
| 98 | <th>Type</th> |
| 99 | <th>Duration</th> |
| 100 | <th>Resultfile</th> |
| 101 | <th>Scraper data</th> |
| 102 | <th>Ffuf Hash</th> |
| 103 | </tr> |
| 104 | </thead> |
| 105 | |
| 106 | <tbody> |
| 107 | {{range $result := .Results}} |
| 108 | <div style="display:none"> |
| 109 | |result_raw|{{ $result.StatusCode }}{{ range $keyword, $value := $result.Input }}|{{ $value | printf "%s" }}{{ end }}|{{ $result.Url }}|{{ $result.RedirectLocation }}|{{ $result.Position }}|{{ $result.ContentLength }}|{{ $result.ContentWords }}|{{ $result.ContentLines }}|{{ $result.ContentType }}|{{ $result.Duration }}|{{ $result.ResultFile }}|{{ $result.ScraperData }}|{{ $result.FfufHash }}| |
| 110 | </div> |
| 111 | <tr class="result-{{ $result.StatusCode }}" style="background-color: {{ $result.HTMLColor }};"> |
| 112 | <td><font color="black" class="status-code">{{ $result.StatusCode }}</font></td> |
| 113 | {{ range $keyword, $value := $result.Input }} |
| 114 | <td>{{ $value | printf "%s" }}</td> |
| 115 | {{ end }} |
| 116 | <td><a href="{{ $result.Url }}">{{ $result.Url }}</a></td> |
| 117 | <td><a href="{{ $result.RedirectLocation }}">{{ $result.RedirectLocation }}</a></td> |
| 118 | <td>{{ $result.Position }}</td> |
| 119 | <td>{{ $result.ContentLength }}</td> |
| 120 | <td>{{ $result.ContentWords }}</td> |
| 121 | <td>{{ $result.ContentLines }}</td> |
| 122 | <td>{{ $result.ContentType }}</td> |
| 123 | <td>{{ $result.Duration }}</td> |
| 124 | <td>{{ $result.ResultFile }}</td> |
| 125 | <td>{{ $result.ScraperData }}</td> |
| 126 | <td>{{ $result.FfufHash }}</td> |
| 127 | </tr> |
| 128 | {{ end }} |
| 129 | </tbody> |
| 130 | </table> |
| 131 | |
| 132 | </div> |
| 133 | <br /><br /> |
| 134 | </div> |
| 135 | </main> |
| 136 | |
| 137 | <!--JavaScript at end of body for optimized loading--> |
| 138 | <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> |
| 139 | <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> |
| 140 | <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script> |
| 141 | <script> |
| 142 | $(document).ready(function() { |
| 143 | $('#ffufreport').DataTable( |
| 144 | { |
| 145 | "aLengthMenu": [ |
| 146 | [250, 500, 1000, 2500, -1], |
| 147 | [250, 500, 1000, 2500, "All"] |
| 148 | ] |
| 149 | } |
| 150 | ) |
| 151 | $('select').formSelect(); |
| 152 | }); |
| 153 | </script> |
| 154 | <style> |
| 155 | body { |
| 156 | display: flex; |
| 157 | min-height: 100vh; |
| 158 | flex-direction: column; |
| 159 | } |
| 160 | |
| 161 | main { |
| 162 | flex: 1 0 auto; |
| 163 | } |
| 164 | </style> |
| 165 | </body> |
| 166 | </html> |
| 167 | |
| 168 | ` |
| 169 | ) |
| 170 | |
| 171 | // colorizeResults returns a new slice with HTMLColor attribute |
| 172 | func colorizeResults(results []ffuf.Result) []ffuf.Result { |
| 173 | newResults := make([]ffuf.Result, 0) |
| 174 | |
| 175 | for _, r := range results { |
| 176 | result := r |
| 177 | result.HTMLColor = "black" |
| 178 | |
| 179 | s := result.StatusCode |
| 180 | |
| 181 | if s >= 200 && s <= 299 { |
| 182 | result.HTMLColor = "#adea9e" |
| 183 | } |
| 184 | |
| 185 | if s >= 300 && s <= 399 { |
| 186 | result.HTMLColor = "#bbbbe6" |
| 187 | } |
| 188 | |
| 189 | if s >= 400 && s <= 499 { |
| 190 | result.HTMLColor = "#d2cb7e" |
| 191 | } |
| 192 | |
| 193 | if s >= 500 && s <= 599 { |
| 194 | result.HTMLColor = "#de8dc1" |
| 195 | } |
| 196 | |
| 197 | newResults = append(newResults, result) |
| 198 | } |
| 199 | |
| 200 | return newResults |
| 201 | } |
| 202 | |
| 203 | func writeHTML(filename string, config *ffuf.Config, results []ffuf.Result) error { |
| 204 | results = colorizeResults(results) |
| 205 | |
| 206 | ti := time.Now() |
| 207 | |
| 208 | keywords := make([]string, 0) |
| 209 | for _, inputprovider := range config.InputProviders { |
| 210 | keywords = append(keywords, inputprovider.Keyword) |
| 211 | } |
| 212 | htmlResults := make([]htmlResult, 0) |
| 213 | |
| 214 | for _, r := range results { |
| 215 | ffufhash := "" |
| 216 | strinput := make(map[string]string) |
| 217 | for k, v := range r.Input { |
| 218 | if k == "FFUFHASH" { |
| 219 | ffufhash = string(v) |
| 220 | } else { |
| 221 | strinput[k] = string(v) |
| 222 | } |
| 223 | } |
| 224 | strscraper := "" |
| 225 | for k, v := range r.ScraperData { |
| 226 | if len(v) > 0 { |
| 227 | strscraper = strscraper + "<p><b>" + html.EscapeString(k) + ":</b><br />" |
| 228 | firstval := true |
| 229 | for _, val := range v { |
| 230 | if !firstval { |
| 231 | strscraper += "<br />" |
| 232 | } |
| 233 | strscraper += html.EscapeString(val) |
| 234 | firstval = false |
| 235 | } |
| 236 | strscraper += "</p>" |
| 237 | } |
| 238 | } |
| 239 | hres := htmlResult{ |
| 240 | Input: strinput, |
| 241 | Position: r.Position, |
| 242 | StatusCode: r.StatusCode, |
| 243 | ContentLength: r.ContentLength, |
| 244 | ContentWords: r.ContentWords, |
| 245 | ContentLines: r.ContentLines, |
| 246 | ContentType: r.ContentType, |
| 247 | RedirectLocation: r.RedirectLocation, |
| 248 | ScraperData: strscraper, |
| 249 | Duration: r.Duration, |
| 250 | ResultFile: r.ResultFile, |
| 251 | Url: r.Url, |
| 252 | Host: r.Host, |
| 253 | HTMLColor: r.HTMLColor, |
| 254 | FfufHash: ffufhash, |
| 255 | } |
| 256 | htmlResults = append(htmlResults, hres) |
| 257 | } |
| 258 | outHTML := htmlFileOutput{ |
| 259 | CommandLine: config.CommandLine, |
| 260 | Time: ti.Format(time.RFC3339), |
| 261 | Results: htmlResults, |
| 262 | Keys: keywords, |
| 263 | } |
| 264 | |
| 265 | f, err := os.Create(filename) |
| 266 | if err != nil { |
| 267 | return err |
| 268 | } |
| 269 | defer f.Close() |
| 270 | |
| 271 | templateName := "output.html" |
| 272 | t := template.New(templateName).Delims("{{", "}}") |
| 273 | _, err = t.Parse(htmlTemplate) |
| 274 | if err != nil { |
| 275 | return err |
| 276 | } |
| 277 | err = t.Execute(f, outHTML) |
| 278 | return err |
| 279 | } |