Skip to content

Commit

Permalink
Adding Content-Type to all output formats (#336) (#341)
Browse files Browse the repository at this point in the history
* adding content-type to csv and json output (#336)

* added to contributors and changelog

* changed 'type' to 'content-type'

* added content-type for html and md output

* updated changelog

Co-authored-by: layton <layton@desktop-manjaro.fritz.box>
Co-authored-by: Joona Hoikkala <joohoi@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 21, 2021
1 parent 825bd32 commit 0c99194
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
## Changelog
- master
- New
- All output file formats now include the `Content-Type`.
- Changed

- v1.2.1
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -29,3 +29,4 @@
* [seblw](https://github.com/seblw)
* [Shaked](https://github.com/Shaked)
* [SolomonSklash](https://github.com/SolomonSklash)
* [l4yton](https://github.com/l4yton)
2 changes: 2 additions & 0 deletions pkg/ffuf/response.go
Expand Up @@ -13,6 +13,7 @@ type Response struct {
ContentLength int64
ContentWords int64
ContentLines int64
ContentType string
Cancelled bool
Request *Request
Raw string
Expand Down Expand Up @@ -50,6 +51,7 @@ func NewResponse(httpresp *http.Response, req *Request) Response {
var resp Response
resp.Request = req
resp.StatusCode = int64(httpresp.StatusCode)
resp.ContentType = httpresp.Header.Get("Content-Type")
resp.Headers = httpresp.Header
resp.Cancelled = false
resp.Raw = ""
Expand Down
3 changes: 2 additions & 1 deletion pkg/output/file_csv.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ffuf/ffuf/pkg/ffuf"
)

var staticheaders = []string{"url", "redirectlocation", "position", "status_code", "content_length", "content_words", "content_lines", "resultfile"}
var staticheaders = []string{"url", "redirectlocation", "position", "status_code", "content_length", "content_words", "content_lines", "content_type", "resultfile"}

func writeCSV(config *ffuf.Config, res []Result, encode bool) error {

Expand Down Expand Up @@ -68,6 +68,7 @@ func toCSV(r Result) []string {
res = append(res, strconv.FormatInt(r.ContentLength, 10))
res = append(res, strconv.FormatInt(r.ContentWords, 10))
res = append(res, strconv.FormatInt(r.ContentLines, 10))
res = append(res, r.ContentType)
res = append(res, r.ResultFile)
return res
}
8 changes: 5 additions & 3 deletions pkg/output/file_html.go
Expand Up @@ -76,15 +76,16 @@ const (
<th>Position</th>
<th>Length</th>
<th>Words</th>
<th>Lines</th>
<th>Lines</th>
<th>Type</th>
<th>Resultfile</th>
</tr>
</thead>
<tbody>
{{range $result := .Results}}
<div style="display:none">
|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_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 }}|
</div>
<tr class="result-{{ $result.StatusCode }}" style="background-color: {{$result.HTMLColor}};">
<td><font color="black" class="status-code">{{ $result.StatusCode }}</font></td>
Expand All @@ -96,7 +97,8 @@ const (
<td>{{ $result.Position }}</td>
<td>{{ $result.ContentLength }}</td>
<td>{{ $result.ContentWords }}</td>
<td>{{ $result.ContentLines }}</td>
<td>{{ $result.ContentLines }}</td>
<td>{{ $result.ContentType }}</td>
<td>{{ $result.ResultFile }}</td>
</tr>
{{ end }}
Expand Down
2 changes: 2 additions & 0 deletions pkg/output/file_json.go
Expand Up @@ -22,6 +22,7 @@ type JsonResult struct {
ContentLength int64 `json:"length"`
ContentWords int64 `json:"words"`
ContentLines int64 `json:"lines"`
ContentType string `json:"content-type"`
RedirectLocation string `json:"redirectlocation"`
ResultFile string `json:"resultfile"`
Url string `json:"url"`
Expand Down Expand Up @@ -74,6 +75,7 @@ func writeJSON(config *ffuf.Config, res []Result) error {
ContentLength: r.ContentLength,
ContentWords: r.ContentWords,
ContentLines: r.ContentLines,
ContentType: r.ContentType,
RedirectLocation: r.RedirectLocation,
ResultFile: r.ResultFile,
Url: r.Url,
Expand Down
6 changes: 3 additions & 3 deletions pkg/output/file_md.go
Expand Up @@ -14,9 +14,9 @@ const (
Command line : ` + "`{{.CommandLine}}`" + `
Time: ` + "{{ .Time }}" + `
{{ range .Keys }}| {{ . }} {{ end }}| URL | Redirectlocation | Position | Status Code | Content Length | Content Words | Content Lines | ResultFile |
{{ range .Keys }}| :- {{ end }}| :-- | :--------------- | :---- | :------- | :---------- | :------------- | :------------ | :--------- |
{{range .Results}}{{ range $keyword, $value := .Input }}| {{ $value | printf "%s" }} {{ end }}| {{ .Url }} | {{ .RedirectLocation }} | {{ .Position }} | {{ .StatusCode }} | {{ .ContentLength }} | {{ .ContentWords }} | {{ .ContentLines }} | {{ .ResultFile }} |
{{ range .Keys }}| {{ . }} {{ end }}| URL | Redirectlocation | Position | Status Code | Content Length | Content Words | Content Lines | Content Type | ResultFile |
{{ range .Keys }}| :- {{ end }}| :-- | :--------------- | :---- | :------- | :---------- | :------------- | :------------ | :--------- | :----------- |
{{range .Results}}{{ range $keyword, $value := .Input }}| {{ $value | printf "%s" }} {{ end }}| {{ .Url }} | {{ .RedirectLocation }} | {{ .Position }} | {{ .StatusCode }} | {{ .ContentLength }} | {{ .ContentWords }} | {{ .ContentLines }} | {{ .ContentType }} | {{ .ResultFile }} |
{{end}}` // The template format is not pretty but follows the markdown guide
)

Expand Down
2 changes: 2 additions & 0 deletions pkg/output/stdout.go
Expand Up @@ -36,6 +36,7 @@ type Result struct {
ContentLength int64 `json:"length"`
ContentWords int64 `json:"words"`
ContentLines int64 `json:"lines"`
ContentType string `json:"content-type"`
RedirectLocation string `json:"redirectlocation"`
Url string `json:"url"`
ResultFile string `json:"resultfile"`
Expand Down Expand Up @@ -301,6 +302,7 @@ func (s *Stdoutput) Result(resp ffuf.Response) {
ContentLength: resp.ContentLength,
ContentWords: resp.ContentWords,
ContentLines: resp.ContentLines,
ContentType: resp.ContentType,
RedirectLocation: resp.GetRedirectLocation(false),
Url: resp.Request.Url,
ResultFile: resp.ResultFile,
Expand Down

0 comments on commit 0c99194

Please sign in to comment.