Skip to content

Commit

Permalink
Updated reporting formats to include an array of new flavors (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Britton Hayes <[email protected]>
  • Loading branch information
brittonhayes and brittonhayes authored Mar 2, 2021
1 parent a58d4dd commit bde62a2
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 71 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
os: [ macos-latest, ubuntu-latest, windows-latest ]
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Install dependencies
run: go get ./...

Expand Down
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,75 @@ regex = '''(?i)([A-Za-z0-9!#$%&'*+\/=?^_{|.}~-]+@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9
tags = ["email", "User Info"]
```

### Built-in Output Formats

Pillager has a series of built-in output formats available. Pick your flavor!

#### Basic

```shell
pillager hunt .
```

#### JSON

```shell
pillager hunt ./example -f json | jq .
```

> *JSON output is designed to work seamlessly with*
> *the amazing [jq](https://github.com/stedolan/jq)*
> *utility for easy parsing.*
<details>
<summary>Click to view more output formats</summary>
<br>

#### YAML

```shell
pillager hunt . -f yaml
```

#### HTML

```shell
pillager hunt . -f html > results.html
```

#### HTML Table

```shell
pillager hunt . -f html-table > results.html
```

#### Markdown

```shell
pillager hunt . -f markdown > results.md
```

#### Markdown Table

```shell
pillager hunt . -f table > results.md
```

#### Custom Go Template

```shell
pillager hunt . --template "{{ range .Leaks}}Leak: {{.Line}}{{end}}"
```

#### Custom Go Template from File

```shell
pillager hunt . -t "$(cat templates/simple.tmpl)"
```

</details>


### Custom Templates

Pillager allows you to use powerful `go text/template` to customize the output format. Here are a few template examples.
Expand Down
37 changes: 23 additions & 14 deletions cmd/hunt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,29 @@ var huntCmd = &cobra.Command{
Short: "Hunt for loot",
Long: "Hunt inside the file system for valuable information",
Example: `
# Run a basic hunt
pillager hunt .
# Print out results in JSON format
pillager hunt ./example -f json
# Print out results in YAML format
pillager hunt . -f yaml
# Print out results with a custom inline template
pillager hunt . --template "{{ range .Leaks}}Leak: {{.Line}}{{end}}"
# Print out results with a custom template file
pillager hunt ./example --template "$(cat templates/simple.tmpl)"
Basic:
pillager hunt .
JSON Format:
pillager hunt ./example -f json
YAML Format:
pillager hunt . -f yaml
HTML Format:
pillager hunt . -f html > results.html
HTML Table Format:
pillager hunt . -f html-table > results.html
Markdown Table Format:
pillager hunt . -f table > results.md
Custom Go Template Format:
pillager hunt . --template "{{ range .Leaks}}Leak: {{.Line}}{{end}}"
Custom Go Template Format from Template File:
pillager hunt ./example --template "$(cat templates/simple.tmpl)"
`,
Args: cobra.ExactArgs(1),
RunE: startHunt(),
Expand Down
14 changes: 13 additions & 1 deletion hunter/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import "strings"
const (
JSONFormat Format = iota + 1
YAMLFormat
TableFormat
HTMLFormat
HTMLTableFormat
MarkdownFormat
CustomFormat
)

type Format int

func (f Format) String() string {
return [...]string{"json", "yaml", "custom"}[f]
return [...]string{"json", "yaml", "table", "html", "html-table", "markdown", "custom"}[f]
}

// StringToFormat takes in a string representation of the preferred
Expand All @@ -20,6 +24,14 @@ func StringToFormat(s string) Format {
switch strings.ToLower(s) {
case "yaml":
return YAMLFormat
case "table":
return TableFormat
case "html":
return HTMLFormat
case "html-table":
return HTMLTableFormat
case "markdown":
return MarkdownFormat
case "custom":
return CustomFormat
default:
Expand Down
11 changes: 10 additions & 1 deletion hunter/hound.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"

"github.com/brittonhayes/pillager/templates"
"github.com/ghodss/yaml"
"github.com/zricethezav/gitleaks/v7/scan"
)
Expand Down Expand Up @@ -56,9 +57,17 @@ func (h *Hound) Howl(findings scan.Report) {
return
}
fmt.Println(string(b))
case HTMLFormat:
RenderTemplate(os.Stdout, templates.HTML, findings)
case HTMLTableFormat:
RenderTemplate(os.Stdout, templates.HTMLTable, findings)
case MarkdownFormat:
RenderTemplate(os.Stdout, templates.Markdown, findings)
case TableFormat:
RenderTemplate(os.Stdout, templates.Table, findings)
case CustomFormat:
RenderTemplate(os.Stdout, h.Config.Template, findings)
default:
RenderTemplate(os.Stdout, DefaultTemplate, findings)
RenderTemplate(os.Stdout, templates.Simple, findings)
}
}
42 changes: 42 additions & 0 deletions templates/html-table.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pillager - Scan Results</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
</head>
<body>
<section class="section">
<div class="container">
<h1 class="title">
Pillager
</h1>
<h2 class="subtitle">
Results of your latest hunt
</h2>
<div class="table-container">
<table class="table is-fullwidth">
<thead>
<tr>
<th><abbr title="Filename">File</abbr></th>
<th><abbr title="Line Number">Line</abbr></th>
<th><abbr title="Offender">Leak</abbr></th>
</tr>
</thead>
<tbody>
{{ range .Leaks }}
<tr>
<th>{{.File}}</th>
<td>{{.LineNumber}}</td>
<td class="has-text-danger">{{.Offender}}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
</section>

</body>
</html>
60 changes: 5 additions & 55 deletions templates/table.tmpl
Original file line number Diff line number Diff line change
@@ -1,55 +1,5 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pillager - Scan Results</title>
<style type="text/css">
.offender {
-webkit-text-security: disc !important;
}

.offender:hover {
-webkit-text-security: none;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
</head>
<body>
<section class="hero is-black">
<div class="hero-body">
<p class="title">
Pillager
</p>
<p class="subtitle">
Results of your latest hunt
</p>
</div>
</section>
<section class="section">
<div class="container">
<div class="table-container">
<table class="table is-fullwidth">
<thead>
<tr>
<th><abbr title="Filename">File</abbr></th>
<th><abbr title="Line Number">Line</abbr></th>
<th><abbr title="Offender">Leak</abbr></th>
</tr>
</thead>
<tbody>
{{ range .Leaks }}
<tr>
<th>{{.File}}</th>
<td>{{.LineNumber}}</td>
<td class="has-text-danger">{{.Offender}}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
</div>
</section>

</body>
</html>
| File | Line | Offender |
| --------| ---------| -------- |
{{ range .Leaks -}}
| {{ .File }} | {{.LineNumber}} | {{.Offender}} |
{{ end -}}
20 changes: 20 additions & 0 deletions templates/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package templates

import _ "embed"

var (
//go:embed simple.tmpl
Simple string

//go:embed html.tmpl
HTML string

//go:embed markdown.tmpl
Markdown string

//go:embed table.tmpl
Table string

//go:embed html-table.tmpl
HTMLTable string
)

0 comments on commit bde62a2

Please sign in to comment.