Skip to content

Commit

Permalink
added verbose flag and flag for roots.txt. Also fixed some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldencybersec committed Mar 15, 2024
1 parent ec96133 commit f5dcbe2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ go install github.com/g0ldencybersec/gungnir/gungnir@latest
```

## Usage
# Options
```sh
Usage of gungnir:
-r string Path to the list of root domains to filter against
-v Output go logs (500/429 errors) to command line
```

To run the tool, use a text file of root domains you want to monitor: `roots.txt`. Then, run the `gungnir` module:

```sh
./gungnir roots.txt
./gungnir -r roots.txt
```

Once the tool starts and initializes, it will print domains to stdout. So feel free to pipe the output into your favorite tool!
Expand Down
56 changes: 45 additions & 11 deletions gungnir/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"flag"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -35,8 +36,24 @@ var (
matchSubjectRegex = `^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}|localhost)$` // Regex to match CN/SAN

rootDomains map[string]bool
sLogger = SilentLogger{}
bLogger = basicLogger{}
)

// SilentLogger is a custom logger that does nothing
type SilentLogger struct{}

// Printf method for SilentLogger that does nothing
func (l *SilentLogger) Printf(format string, v ...interface{}) {
// Intentionally left blank to not log anything
}

type basicLogger struct{}

func (bl *basicLogger) Printf(msg string, args ...interface{}) {
log.Printf(msg, args...)
}

func getLogUrls() ([]string, error) {
var logList []string
client := &http.Client{
Expand Down Expand Up @@ -166,14 +183,24 @@ func createMatcherFromFlags() (interface{}, error) {
PrecertificateSubjectRegex: precertRegex}, nil
}

func scanLog(ctx context.Context, logURI string, wg *sync.WaitGroup, httpClient *http.Client) {
func scanLog(ctx context.Context, logURI string, wg *sync.WaitGroup, httpClient *http.Client, verbose bool) {
defer wg.Done()

var logClient *client.LogClient
var err error
log.Printf("Starting continuous scan for log: %s", logURI)
logClient, err := client.New(logURI, httpClient, jsonclient.Options{UserAgent: "ct-go-scanlog/1.0"})
if err != nil {
log.Printf("Failed to create client for log %s: %v", logURI, err)
return
if verbose {
logClient, err = client.New(logURI, httpClient, jsonclient.Options{UserAgent: "ct-go-scanlog/1.0", Logger: &bLogger})
if err != nil {
log.Printf("Failed to create client for log %s: %v", logURI, err)
return
}
} else {
logClient, err = client.New(logURI, httpClient, jsonclient.Options{UserAgent: "ct-go-scanlog/1.0", Logger: &sLogger})
if err != nil {
log.Printf("Failed to create client for log %s: %v", logURI, err)
return
}
}

sth, err := logClient.GetSTH(ctx)
Expand All @@ -187,8 +214,6 @@ func scanLog(ctx context.Context, logURI string, wg *sync.WaitGroup, httpClient
log.Printf("Failed to create matcher for log %s: %v", logURI, err)
return
}
time.Sleep(time.Second * 10)
// Continous Scanning Loop

certScanner := scanner.NewScanner(logClient, scanner.ScannerOptions{
FetcherOptions: scanner.FetcherOptions{
Expand All @@ -208,15 +233,24 @@ func scanLog(ctx context.Context, logURI string, wg *sync.WaitGroup, httpClient
log.Printf("Failed to scan log %s: %v", logURI, err)
// Consider whether to continue or break/return based on the type of error.
}

}

func main() {
if len(os.Args) > 1 {
var rootList string
var verbose bool
flag.StringVar(&rootList, "r", "", "Path to the list of root domains to filter against")
flag.BoolVar(&verbose, "v", false, "Output go logs (500/429 errors) to command line")

flag.Parse()

if rootList != "" {
loadRootDomains(os.Args[1])
} else {
fmt.Println("Please run with a roots.txt file...")
fmt.Println("ex: ./gungnir roots.txt")
os.Exit(1)
flag.PrintDefaults()
fmt.Println("ex: ./gungnir -r roots.txt")
os.Exit(0)
}

logURIs, err := getLogUrls()
Expand All @@ -232,7 +266,7 @@ func main() {

for _, logURI := range logURIs {
wg.Add(1)
go scanLog(ctx, logURI, &wg, httpClient)
go scanLog(ctx, logURI, &wg, httpClient, verbose)
}

wg.Wait()
Expand Down

0 comments on commit f5dcbe2

Please sign in to comment.