Gobuster is the main entry point for the CLI
(ctx context.Context, opts *libgobuster.Options, plugin libgobuster.GobusterPlugin, log *libgobuster.Logger)
| 136 | |
| 137 | // Gobuster is the main entry point for the CLI |
| 138 | func Gobuster(ctx context.Context, opts *libgobuster.Options, plugin libgobuster.GobusterPlugin, log *libgobuster.Logger) error { |
| 139 | // Sanity checks |
| 140 | if opts == nil { |
| 141 | return errors.New("please provide valid options") |
| 142 | } |
| 143 | |
| 144 | if plugin == nil { |
| 145 | return errors.New("please provide a valid plugin") |
| 146 | } |
| 147 | |
| 148 | ctxCancel, cancel := context.WithCancel(ctx) |
| 149 | defer cancel() |
| 150 | |
| 151 | gobuster, err := libgobuster.NewGobuster(opts, plugin, log) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | if !opts.Quiet { |
| 157 | log.Println(ruler) |
| 158 | log.Printf("Gobuster v%s\n", libgobuster.VERSION) |
| 159 | log.Println("by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)") |
| 160 | log.Println(ruler) |
| 161 | c, err := gobuster.GetConfigString() |
| 162 | if err != nil { |
| 163 | return fmt.Errorf("error on creating config string: %w", err) |
| 164 | } |
| 165 | log.Println(c) |
| 166 | log.Println(ruler) |
| 167 | gobuster.Logger.Printf("Starting gobuster in %s mode", plugin.Name()) |
| 168 | if opts.WordlistOffset > 0 { |
| 169 | gobuster.Logger.Printf("Skipping the first %d elements...", opts.WordlistOffset) |
| 170 | } |
| 171 | log.Println(ruler) |
| 172 | } |
| 173 | |
| 174 | fi, err := os.Stdout.Stat() |
| 175 | if err != nil { |
| 176 | return err |
| 177 | } |
| 178 | // check if we are not in a terminal. If so, disable output |
| 179 | if (fi.Mode() & os.ModeCharDevice) != os.ModeCharDevice { |
| 180 | opts.NoProgress = true |
| 181 | } |
| 182 | |
| 183 | // our waitgroup for all goroutines |
| 184 | // this ensures all goroutines are finished |
| 185 | // when we call wg.Wait() |
| 186 | var wg sync.WaitGroup |
| 187 | |
| 188 | wg.Add(1) |
| 189 | go resultWorker(gobuster, opts.OutputFilename, &wg) |
| 190 | |
| 191 | wg.Add(1) |
| 192 | go errorWorker(gobuster, &wg) |
| 193 | |
| 194 | wg.Add(1) |
| 195 | go messageWorker(gobuster, &wg) |