-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
182 lines (156 loc) · 3.83 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"net"
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"
)
type Result struct {
Found bool
Address string
}
var (
inputFile string
outputFile string
domain string
stdin bool
validChars bool
threads int
client *http.Client
headers map[string]string
)
func init() {
flag.StringVar(&inputFile, "i", "", "List of accounts to test")
flag.StringVar(&outputFile, "o", "", "Output file (default: Stdout)")
flag.StringVar(&domain, "d", "gmail.com", "Append domain to every address (empty to no append)")
flag.BoolVar(&stdin, "stdin", false, "Read accounts from stdin")
flag.BoolVar(&validChars, "r", false, "Remove gmail address' invalid chars")
flag.IntVar(&threads, "t", 10, "Number of threads")
flag.Parse()
if inputFile == "" && !stdin {
flag.Usage()
os.Exit(1)
}
client = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
// MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
headers = map[string]string{
"User-Agent": `Mozilla/5.0 (Windows NT 6.1; rv:61.0) Gecko/20100101 Firefox/61.0`,
"Accept-Language": `en-US,en;q=0.5`,
}
}
// TestAddress checks if a given address is valid using the glitch described here: https://blog.0day.rocks/abusing-gmail-to-get-previously-unlisted-e-mail-addresses-41544b62b2
func TestAddress(addr string, resChan chan<- Result) {
URL := fmt.Sprintf("https://mail.google.com/mail/gxlu?email=%s", url.QueryEscape(addr))
req, err := http.NewRequest(http.MethodGet, URL, nil)
if err != nil {
return
}
// Add headers
for key, val := range headers {
req.Header.Set(key, val)
}
// Make request
resp, err := client.Do(req)
if err != nil {
return
}
resp.Body.Close()
found := len(resp.Cookies()) > 0
resChan <- Result{found, addr}
}
func main() {
addrChan := make(chan string, threads)
resultsChan := make(chan Result)
// Group to wait for all threads (routines) to finish
threadsG := new(sync.WaitGroup)
var input *os.File
if stdin {
input = os.Stdin
inputFile = "stdin"
} else {
f, err := os.Open(inputFile)
if err != nil {
fmt.Printf("[!] Error opening file '%s'\n", inputFile)
return
}
input = f
defer f.Close()
}
out, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE, os.ModeAppend)
if err != nil {
out = os.Stdout
}
defer out.Close()
// TODO: Put some fancy ascii art here??
fmt.Println("--- Starting bruteforce --")
fmt.Printf("| Input: %s\n", inputFile)
fmt.Printf("| Threads: %d\n\n", threads)
// Start all threads (routines)
for i := 0; i < threads; i++ {
go func() {
for addr := range addrChan {
if addr == "" {
break
}
// Append domain to address
if domain != "" {
addr += "@" + domain
}
if validChars {
addr = RemoveInvalidChars(addr)
}
TestAddress(addr, resultsChan)
}
threadsG.Done()
}()
threadsG.Add(1)
}
scanner := bufio.NewScanner(input)
scanner.Split(bufio.ScanLines)
go func() {
for scanner.Scan() {
addr := strings.TrimSpace(scanner.Text())
// Skip comments and empty lines
if !strings.HasPrefix(addr, "#") && addr != "" {
addrChan <- addr
}
}
close(addrChan)
threadsG.Wait()
close(resultsChan)
}()
tested, found := 0, 0
for result := range resultsChan {
tested++
if result.Found {
found++
if out == os.Stdout {
// 'Flush' stdout
fmt.Printf("%100s\r", "")
}
fmt.Fprintln(out, result.Address)
}
fmt.Printf("[*] Tested: %d, Found: %d\r", tested, found)
}
}