Skip to content

Commit

Permalink
Merge pull request #20 from koenrh/koenrh/multiple-names
Browse files Browse the repository at this point in the history
Add support for multiple names
  • Loading branch information
koenrh authored Jun 13, 2019
2 parents 5872edc + 4cef724 commit 26e22ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

var (
threads int
baseName string
names []string
wordListFile string
preAndSuffixesFile string
)
Expand All @@ -17,7 +17,7 @@ const version = "0.0.1"
const usage = `s3enum
Usage:
s3enum --wordlist wl.txt --suffixlist sl.txt [--threads 2] <name>
s3enum --wordlist wl.txt --suffixlist sl.txt [--threads 2] <name>...
s3enum -h | --help
s3enum --version
Expand All @@ -38,7 +38,7 @@ func main() {
os.Exit(0)
}

baseName = opts["<name>"].(string)
names = opts["<name>"].([]string)
preAndSuffixesFile = opts["--suffixlist"].(string)
wordListFile = opts["--wordlist"].(string)
threads, _ = opts.Int("--threads")
Expand Down Expand Up @@ -74,7 +74,7 @@ func main() {
os.Exit(1)
}

producer.ProduceWordList(baseName, wordListFile)
producer.ProduceWordList(names, wordListFile)

// NOTE: producer closes their own channel
<-wordDone
Expand Down
20 changes: 12 additions & 8 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func NewProducer(preAndSuffixesFile string, wordChannel chan string, quit chan b
}

// ProduceWordList produces candidate bucket names to the channel.
func (p *Producer) ProduceWordList(basename string, list string) {
p.channel <- basename
func (p *Producer) ProduceWordList(names []string, list string) {
for _, n := range names {
p.channel <- n
}

file, err := os.Open(list)
if err != nil {
Expand All @@ -47,26 +49,28 @@ func (p *Producer) ProduceWordList(basename string, list string) {

for scanner.Scan() {
line := scanner.Text()
p.Produce(basename, line)
for _, n := range names {
p.Produce(n, line)
}
}

close(p.channel)
}

// Produce produces candidates
func (p *Producer) Produce(basename string, word string) {
for _, ca := range p.PrepareCandidateBucketNames(basename, word) {
func (p *Producer) Produce(name, word string) {
for _, ca := range p.PrepareCandidateBucketNames(name, word) {
p.channel <- ca
}
}

// PrepareCandidateBucketNames creates all candidate pairs
func (p *Producer) PrepareCandidateBucketNames(basename string, word string) []string {
func (p *Producer) PrepareCandidateBucketNames(name, word string) []string {
result := []string{}

for _, del := range p.delimiters {
cand1 := fmt.Sprintf("%s%s%s", basename, del, word)
cand2 := fmt.Sprintf("%s%s%s", word, del, basename)
cand1 := fmt.Sprintf("%s%s%s", name, del, word)
cand2 := fmt.Sprintf("%s%s%s", word, del, name)

result = append(result, cand1)
result = append(result, cand2)
Expand Down

0 comments on commit 26e22ca

Please sign in to comment.