Skip to content

Commit

Permalink
Add wordlist generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jrozner committed Feb 22, 2016
1 parent 3c2b4a8 commit 045ed69
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.*swp
cmd/sonar/sonar
words.go
2 changes: 1 addition & 1 deletion cmd/sonar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
case (brute == true):
var wl sonar.Wordlist
if wordlist == "" {
wl = sonar.NewInternal(sonar.InternalWords)
wl = sonar.NewInternal(sonar.InternalWordlist)
} else {
fp, err := os.Open(wordlist)
if err != nil {
Expand Down
39 changes: 39 additions & 0 deletions cmd/wordlist_generator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"bytes"
"flag"
"io/ioutil"
"log"
"strings"
)

func main() {
var wordlist, pkg, output string

flag.StringVar(&wordlist, "wordlist", "", "word list to generate from")
flag.StringVar(&pkg, "package", "sonar", "package to generate for")
flag.StringVar(&output, "output", "words.go", "file output source to")
flag.Parse()

if wordlist == "" {
log.Fatal("no wordlist specified")
}

words, err := ioutil.ReadFile(wordlist)
if err != nil {
log.Fatal(err)
}

wordSlice := strings.Split(string(words), "\n")
out := bytes.NewBuffer([]byte{})
_, err = out.Write([]byte("package " + pkg + "\n\nvar InternalWordlist = []string{\"" + strings.Join(wordSlice, "\", \"") + "\"}\n"))
if err != nil {
log.Fatal(err)
}

err = ioutil.WriteFile(output, out.Bytes(), 0600)
if err != nil {
log.Fatal(err)
}
}
3 changes: 1 addition & 2 deletions wordlist.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate wordlist_generator -wordlist wordlist.txt
package sonar

import (
Expand All @@ -6,8 +7,6 @@ import (
"strings"
)

var InternalWords = []string{"www", "beta", "mail", "demo", "test"}

type Wordlist interface {
readWords()
GetChannel() <-chan string
Expand Down

0 comments on commit 045ed69

Please sign in to comment.