| 1 | package output |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "os" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/ffuf/ffuf/v2/pkg/ffuf" |
| 9 | ) |
| 10 | |
| 11 | type ejsonFileOutput struct { |
| 12 | CommandLine string `json:"commandline"` |
| 13 | Time string `json:"time"` |
| 14 | Results []ffuf.Result `json:"results"` |
| 15 | Config *ffuf.Config `json:"config"` |
| 16 | } |
| 17 | |
| 18 | type JsonResult struct { |
| 19 | Input map[string]string `json:"input"` |
| 20 | Position int `json:"position"` |
| 21 | StatusCode int64 `json:"status"` |
| 22 | ContentLength int64 `json:"length"` |
| 23 | ContentWords int64 `json:"words"` |
| 24 | ContentLines int64 `json:"lines"` |
| 25 | ContentType string `json:"content-type"` |
| 26 | RedirectLocation string `json:"redirectlocation"` |
| 27 | ScraperData map[string][]string `json:"scraper"` |
| 28 | Duration time.Duration `json:"duration"` |
| 29 | ResultFile string `json:"resultfile"` |
| 30 | Url string `json:"url"` |
| 31 | Host string `json:"host"` |
| 32 | } |
| 33 | |
| 34 | type jsonFileOutput struct { |
| 35 | CommandLine string `json:"commandline"` |
| 36 | Time string `json:"time"` |
| 37 | Results []JsonResult `json:"results"` |
| 38 | Config *ffuf.Config `json:"config"` |
| 39 | } |
| 40 | |
| 41 | func writeEJSON(filename string, config *ffuf.Config, res []ffuf.Result) error { |
| 42 | t := time.Now() |
| 43 | outJSON := ejsonFileOutput{ |
| 44 | CommandLine: config.CommandLine, |
| 45 | Time: t.Format(time.RFC3339), |
| 46 | Results: res, |
| 47 | } |
| 48 | |
| 49 | outBytes, err := json.Marshal(outJSON) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | err = os.WriteFile(filename, outBytes, 0644) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | return nil |
| 58 | } |
| 59 | |
| 60 | func writeJSON(filename string, config *ffuf.Config, res []ffuf.Result) error { |
| 61 | t := time.Now() |
| 62 | jsonRes := make([]JsonResult, 0) |
| 63 | for _, r := range res { |
| 64 | strinput := make(map[string]string) |
| 65 | for k, v := range r.Input { |
| 66 | strinput[k] = string(v) |
| 67 | } |
| 68 | jsonRes = append(jsonRes, JsonResult{ |
| 69 | Input: strinput, |
| 70 | Position: r.Position, |
| 71 | StatusCode: r.StatusCode, |
| 72 | ContentLength: r.ContentLength, |
| 73 | ContentWords: r.ContentWords, |
| 74 | ContentLines: r.ContentLines, |
| 75 | ContentType: r.ContentType, |
| 76 | RedirectLocation: r.RedirectLocation, |
| 77 | ScraperData: r.ScraperData, |
| 78 | Duration: r.Duration, |
| 79 | ResultFile: r.ResultFile, |
| 80 | Url: r.Url, |
| 81 | Host: r.Host, |
| 82 | }) |
| 83 | } |
| 84 | outJSON := jsonFileOutput{ |
| 85 | CommandLine: config.CommandLine, |
| 86 | Time: t.Format(time.RFC3339), |
| 87 | Results: jsonRes, |
| 88 | Config: config, |
| 89 | } |
| 90 | outBytes, err := json.Marshal(outJSON) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | err = os.WriteFile(filename, outBytes, 0644) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | return nil |
| 99 | } |