From 7025ddad33aba7c96c9ee7a44364306a0076b461 Mon Sep 17 00:00:00 2001 From: DoI <5291556+denandz@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:49:42 +1300 Subject: [PATCH] Add input wordlist functionality --- README.md | 5 ++++- cmd/pencode/main.go | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b96cb92..a40d3cf 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,10 @@ pencode - complex payload encoder v0.3 Usage: ./pencode FUNC1 FUNC2 FUNC3... -./pencode reads input from stdin, which is typically piped from another process. +./pencode reads input from stdin by default, which is typically piped from another process. + +OPTIONS: +-input reads input from a file, line by line. ENCODERS b64encode - Base64 encoder diff --git a/cmd/pencode/main.go b/cmd/pencode/main.go index 2a1a7a2..a281f66 100644 --- a/cmd/pencode/main.go +++ b/cmd/pencode/main.go @@ -13,10 +13,13 @@ import ( func main() { chain := pencode.NewChain() + inputWordlist := flag.String("input", "", "A wordlist to encode") + flag.Usage = func() { fmt.Printf("pencode - complex payload encoder v%s\n\n", pencode.VERSION) fmt.Printf("Usage: %s FUNC1 FUNC2 FUNC3...\n\n", os.Args[0]) - fmt.Printf("%s reads input from stdin, which is typically piped from another process.\n\n", os.Args[0]) + fmt.Printf("%s reads input from stdin by default, which is typically piped from another process.\n\n", os.Args[0]) + fmt.Printf("OPTIONS:\n-input reads input from a file, line by line.\n\n") chain.Usage() } @@ -34,19 +37,41 @@ func main() { os.Exit(1) } - err := chain.Initialize(os.Args[1:]) + err := chain.Initialize(flag.Args()) if err != nil { flag.Usage() fmt.Printf("\n[!] %s\n", err) os.Exit(1) } - input := readInput() - output, err := chain.Encode([]byte(input)) - if err != nil { - fmt.Printf(" [!] %s\n", err) + if *inputWordlist != "" { + // read the input wordlist and output to stdout + file, err := os.Open(*inputWordlist) + + if err != nil { + fmt.Println(err) + } + + defer file.Close() + + fs := bufio.NewScanner(file) + fs.Split(bufio.ScanLines) + + for fs.Scan() { + output, err := chain.Encode(fs.Bytes()) + if err != nil { + fmt.Printf(" [!] %s\n", err) + } + fmt.Println(string(output)) + } + } else { + input := readInput() + output, err := chain.Encode([]byte(input)) + if err != nil { + fmt.Printf(" [!] %s\n", err) + } + fmt.Print(string(output)) } - fmt.Print(string(output)) } func readInput() string {