Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input wordlist functionality #33

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 32 additions & 7 deletions cmd/pencode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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 {
Expand Down