File: main.go

package info (click to toggle)
golang-github-ffuf-pencode 0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: makefile: 2; sh: 1
file content (87 lines) | stat: -rw-r--r-- 1,701 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"strings"

	"github.com/ffuf/pencode/pkg/pencode"
)

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 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()
	}

	var listMode bool
	flag.BoolVar(&listMode, "list", false, "list available encoders")
	flag.Parse()

	if listMode {
		fmt.Println(strings.Join(chain.GetEncoders(), "\n"))
		os.Exit(1)
	}

	if len(os.Args) < 2 {
		flag.Usage()
		os.Exit(1)
	}

	err := chain.Initialize(flag.Args())
	if err != nil {
		flag.Usage()
		fmt.Printf("\n[!] %s\n", err)
		os.Exit(1)
	}

	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))
	}
}

func readInput() string {
	input := os.Stdin
	defer input.Close()
	reader := bufio.NewScanner(input)

	data := ""
	for reader.Scan() {
		data = data + reader.Text()
	}
	return data
}