-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
101 lines (84 loc) · 2.18 KB
/
main.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"bufio"
"flag"
"fmt"
carpetbomb "github.com/s1kx/carpetbomb/lib"
"math/rand"
"os"
"strings"
"time"
)
const (
DefaultConcurrency = 10
DefaultWordlistBuffer = 1000
)
func init() {
flag.Usage = func() {
fmt.Println("Usage: carpetbomb [options] <domain>")
flag.PrintDefaults()
}
// Set random seed
rand.Seed(time.Now().UTC().UnixNano())
}
func main() {
var concurrency int
var wordlistPath string
var outputPath string
var ignoreAddressesFlag string
ignoreAddresses := make([]string, 0, 10)
flag.IntVar(&concurrency, "concurrency", DefaultConcurrency, "Number of max parallel requests")
flag.StringVar(&wordlistPath, "wordlist", "", "File path of dictionary to use as subdomains")
flag.StringVar(&outputPath, "output", "", "File path to write results to")
flag.StringVar(&ignoreAddressesFlag, "ignore", "", "Comma-separated list of IP address masks to ignore (e.g. 192.168.*,213.254.18.59,127.0.0.*)")
flag.Parse()
args := flag.Args()
if len(args) == 0 {
flag.Usage()
os.Exit(1)
}
domain := args[0]
// Determine output path
if outputPath == "" {
// By default, use <domain>-hosts.txt
outputPath = fmt.Sprintf("%s-hosts.txt", domain)
}
// Determine wordlist
var wordlist []string
if wordlistPath == "" {
// Load default wordlist
wordlist = carpetbomb.DefaultWordlist[:]
} else {
// Load user-specified wordlist
list, err := loadWordlist(wordlistPath)
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
wordlist = list
}
// Determine ignored IP addresses
if ignoreAddressesFlag != "" {
parts := strings.Split(ignoreAddressesFlag, ",")
ignoreAddresses = append(ignoreAddresses, parts...)
}
session, err := carpetbomb.CreateSession(domain, concurrency, wordlist, ignoreAddresses, outputPath)
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
session.Start()
}
func loadWordlist(path string) (wordlist []string, err error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
lines := make([]string, 0, DefaultWordlistBuffer)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}