Debian Codegraph @

help.go

raw symbols SCIP
1 package main
2
3 import (
4 "flag"
5 "fmt"
6 "os"
7
8 "github.com/ffuf/ffuf/v2/pkg/ffuf"
9 )
10
11 type UsageSection struct {
12 Name string
13 Description string
14 Flags []UsageFlag
15 Hidden bool
16 ExpectedFlags []string
17 }
18
19 // PrintSection prints out the section name, description and each of the flags
20 func (u *UsageSection) PrintSection(max_length int, extended bool) {
21 // Do not print if extended usage not requested and section marked as hidden
22 if !extended && u.Hidden {
23 return
24 }
25 fmt.Printf("%s:\n", u.Name)
26 for _, f := range u.Flags {
27 f.PrintFlag(max_length)
28 }
29 fmt.Printf("\n")
30 }
31
32 type UsageFlag struct {
33 Name string
34 Description string
35 Default string
36 }
37
38 // PrintFlag prints out the flag name, usage string and default value
39 func (f *UsageFlag) PrintFlag(max_length int) {
40 // Create format string, used for padding
41 format := fmt.Sprintf(" -%%-%ds %%s", max_length)
42 if f.Default != "" {
43 format = format + " (default: %s)\n"
44 fmt.Printf(format, f.Name, f.Description, f.Default)
45 } else {
46 format = format + "\n"
47 fmt.Printf(format, f.Name, f.Description)
48 }
49 }
50
51 func Usage() {
52 u_http := UsageSection{
53 Name: "HTTP OPTIONS",
54 Description: "Options controlling the HTTP request and its parts.",
55 Flags: make([]UsageFlag, 0),
56 Hidden: false,
57 ExpectedFlags: []string{"cc", "ck", "H", "X", "b", "d", "r", "u", "raw", "recursion", "recursion-depth", "recursion-strategy", "replay-proxy", "timeout", "ignore-body", "x", "sni", "http2"},
58 }
59 u_general := UsageSection{
60 Name: "GENERAL OPTIONS",
61 Description: "",
62 Flags: make([]UsageFlag, 0),
63 Hidden: false,
64 ExpectedFlags: []string{"ac", "acc", "ack", "ach", "acs", "c", "config", "json", "maxtime", "maxtime-job", "noninteractive", "p", "rate", "scraperfile", "scrapers", "search", "s", "sa", "se", "sf", "t", "v", "V"},
65 }
66 u_compat := UsageSection{
67 Name: "COMPATIBILITY OPTIONS",
68 Description: "Options to ensure compatibility with other pieces of software.",
69 Flags: make([]UsageFlag, 0),
70 Hidden: true,
71 ExpectedFlags: []string{"compressed", "cookie", "data", "data-ascii", "data-binary", "i", "k"},
72 }
73 u_matcher := UsageSection{
74 Name: "MATCHER OPTIONS",
75 Description: "Matchers for the response filtering.",
76 Flags: make([]UsageFlag, 0),
77 Hidden: false,
78 ExpectedFlags: []string{"mmode", "mc", "ml", "mr", "ms", "mt", "mw"},
79 }
80 u_filter := UsageSection{
81 Name: "FILTER OPTIONS",
82 Description: "Filters for the response filtering.",
83 Flags: make([]UsageFlag, 0),
84 Hidden: false,
85 ExpectedFlags: []string{"fmode", "fc", "fl", "fr", "fs", "ft", "fw"},
86 }
87 u_input := UsageSection{
88 Name: "INPUT OPTIONS",
89 Description: "Options for input data for fuzzing. Wordlists and input generators.",
90 Flags: make([]UsageFlag, 0),
91 Hidden: false,
92 ExpectedFlags: []string{"D", "enc", "ic", "input-cmd", "input-num", "input-shell", "mode", "request", "request-proto", "e", "w"},
93 }
94 u_output := UsageSection{
95 Name: "OUTPUT OPTIONS",
96 Description: "Options for output. Output file formats, file names and debug file locations.",
97 Flags: make([]UsageFlag, 0),
98 Hidden: false,
99 ExpectedFlags: []string{"audit-log", "debug-log", "o", "of", "od", "or"},
100 }
101 sections := []UsageSection{u_http, u_general, u_compat, u_matcher, u_filter, u_input, u_output}
102
103 // Populate the flag sections
104 max_length := 0
105 flag.VisitAll(func(f *flag.Flag) {
106 found := false
107 for i, section := range sections {
108 if ffuf.StrInSlice(f.Name, section.ExpectedFlags) {
109 sections[i].Flags = append(sections[i].Flags, UsageFlag{
110 Name: f.Name,
111 Description: f.Usage,
112 Default: f.DefValue,
113 })
114 found = true
115 }
116 }
117 if !found {
118 fmt.Printf("DEBUG: Flag %s was found but not defined in help.go.\n", f.Name)
119 os.Exit(1)
120 }
121 if len(f.Name) > max_length {
122 max_length = len(f.Name)
123 }
124 })
125
126 fmt.Printf("Fuzz Faster U Fool - %s\n\n", ffuf.FormattedVersion())
127
128 // Print out the sections
129 for _, section := range sections {
130 section.PrintSection(max_length, false)
131 }
132
133 // Usage examples.
134 fmt.Printf("EXAMPLE USAGE:\n")
135
136 fmt.Printf(" Fuzz file paths from wordlist.txt, match all responses but filter out those with content-size 42.\n")
137 fmt.Printf(" Colored, verbose output.\n")
138 fmt.Printf(" ffuf -w wordlist.txt -u https://example.org/FUZZ -mc all -fs 42 -c -v\n\n")
139
140 fmt.Printf(" Fuzz Host-header, match HTTP 200 responses.\n")
141 fmt.Printf(" ffuf -w hosts.txt -u https://example.org/ -H \"Host: FUZZ\" -mc 200\n\n")
142
143 fmt.Printf(" Fuzz POST JSON data. Match all responses not containing text \"error\".\n")
144 fmt.Printf(" ffuf -w entries.txt -u https://example.org/ -X POST -H \"Content-Type: application/json\" \\\n")
145 fmt.Printf(" -d '{\"name\": \"FUZZ\", \"anotherkey\": \"anothervalue\"}' -fr \"error\"\n\n")
146
147 fmt.Printf(" Fuzz multiple locations. Match only responses reflecting the value of \"VAL\" keyword. Colored.\n")
148 fmt.Printf(" ffuf -w params.txt:PARAM -w values.txt:VAL -u https://example.org/?PARAM=VAL -mr \"VAL\" -c\n\n")
149
150 fmt.Printf(" More information and examples: https://github.com/ffuf/ffuf\n\n")
151 }