-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpwndb
executable file
·281 lines (197 loc) · 7.17 KB
/
pwndb
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/dev python3
"""Python module for making API requests to PWNDB"""
# Used for scripts arguments and tool description
import argparse
from argparse import RawTextHelpFormatter
# Used in script loading animation
import itertools
import threading
import time
# Used in request response parsing
import json
# Used to check email input
import re
# Used to request pwndb URL
import requests
# Declaring the colors available for the program's console output when running
DEBUG = '\033[95m'
WARNING = '\033[93m'
ERROR = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
ANIMATION = False
# Constants defined when parsing arguments
EMAIL = None
LOCALPART = None
DOMAIN = None
PASSWORD = None
PROXY = "http://127.0.0.1:9050"
WITHOUT_PROXY = False
PWNDB_URL = "http://pwndb2am4tzkvold.onion/"
def error(message):
"""Error message on the console output"""
return ERROR + "[ERROR] " + ENDC + message
def warning(message):
"""Warning message on the console output"""
return WARNING + "[WARNING] " + ENDC + message
def debug(message):
"""Debug message on the console output"""
return DEBUG + "[DEBUG] " + ENDC + message
def bold(message):
"""Bold message on the console output"""
return BOLD + "[PROGRAM] " + ENDC + message
def loading_animation():
"""Load animation while waiting for VirusTotal response"""
for character in itertools.cycle(['|', '/', '-', '\\']):
if ANIMATION:
break
print(BOLD + "[PROGRAM] " + ENDC + "Waiting for the query answer " + character, end='\r', flush=True)
time.sleep(0.1)
def argument_parser():
""""Parse argument provided to the script"""
DESCRIPTION = """
Pwndb API\n\n
You can use '%' as wildcard in your request.
"""
parser = argparse.ArgumentParser(description=DESCRIPTION, formatter_class=RawTextHelpFormatter)
parser.add_argument("--email",
help="email to send to pwndb")
parser.add_argument("--domain",
type=str,
help="Search with just email domain")
parser.add_argument("--localpart",
type=str,
help="Search with just email localpart")
parser.add_argument("--password",
type=str,
help="Search with just a password")
parser.add_argument("-p", "--proxy",
type=str,
help="Tor proxy URL to use (default: http://127.0.0.1:9050)")
parser.add_argument("--without_proxy",
action="store_true",
help="Launch app in a tor proxyfied network")
args = parser.parse_args()
if args.email and not args.password and not args.localpart and not args.domain:
global EMAIL
EMAIL = args.email
elif args.password and not args.email and not args.localpart and not args.domain:
global PASSWORD
PASSWORD = args.password
elif args.localpart and not args.password and not args.email and not args.domain:
global LOCALPART
LOCALPART = args.localpart
elif args.domain and not args.password and not args.email and not args.localpart:
global DOMAIN
DOMAIN = args.domain
else:
parser.error("[--email | --localpart | --domain | --password] VALUE is needed")
exit(-1)
if args.proxy:
global PROXY
PROXY = args.proxy
if args.without_proxy:
global WITHOUT_PROXY
WITHOUT_PROXY = True
def email_request(proxy_url):
"""Request with an email"""
global ANIMATION
email_regex = re.compile(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
if not re.match(email_regex, EMAIL):
print(error("Your argument isn't a valid email"))
exit(-1)
data = {'luser': EMAIL.split('@')[0], 'domain': EMAIL.split('@')[1], 'luseropr': 1, 'domainopr': 1, 'submitform': 'em'}
animate_thread = threading.Thread(target=loading_animation)
animate_thread.start()
try:
response = requests.post(PWNDB_URL, proxies=proxy_url, data=data)
except requests.exceptions.RequestException as request_error:
print(error("Problem when sending request to pwndb"))
print(error(str(request_error)))
ANIMATION = True
exit(-1)
ANIMATION = True
return response.text
def localpart_request(proxy_url):
"""Request with a localpart"""
global ANIMATION
data = {'luser': LOCALPART, 'luseropr': 1, 'submitform': 'em'}
animate_thread = threading.Thread(target=loading_animation)
animate_thread.start()
try:
response = requests.post(PWNDB_URL, proxies=proxy_url, data=data)
except requests.exceptions.RequestException as request_error:
print(error("Problem when sending request to pwndb"))
print(error(str(request_error)))
ANIMATION = True
exit(-1)
ANIMATION = True
return response.text
def domain_request(proxy_url):
"""Request with a localpart"""
global ANIMATION
data = {'domain': DOMAIN, 'domainopr': 1, 'submitform': 'em'}
animate_thread = threading.Thread(target=loading_animation)
animate_thread.start()
try:
response = requests.post(PWNDB_URL, proxies=proxy_url, data=data)
except requests.exceptions.RequestException as request_error:
print(error("Problem when sending request to pwndb"))
print(error(str(request_error)))
ANIMATION = True
exit(-1)
ANIMATION = True
return response.text
def password_request(proxy_url):
"""Request with a password"""
global ANIMATION
data = {'password': PASSWORD, 'submitform': 'pw'}
animate_thread = threading.Thread(target=loading_animation)
animate_thread.start()
try:
response = requests.post(PWNDB_URL, proxies=proxy_url, data=data)
except requests.exceptions.RequestException as request_error:
print(error("Problem when sending request to pwndb"))
print(error(str(request_error)))
ANIMATION = True
exit(-1)
ANIMATION = True
return response.text
def response_parser(response):
"""Parse pwndb response"""
results = response.split('Array')
data = {}
data['results'] = []
for result in results[1:]:
data['results'].append(
{
"id": result.split('[id] => ')[1].split('\n')[0],
"email": result.split('[luser] => ')[1].split('\n')[0] + '@' + result.split('[domain] => ')[1].split('\n')[0],
"password": result.split('[password] => ')[1].split('\n')[0]
}
)
data['found'] = len(data['results'])
return data
def main():
"""Main program"""
argument_parser()
if WITHOUT_PROXY:
proxy_url = None
else:
proxy_url = {"http": PROXY}
if EMAIL:
response = email_request(proxy_url)
elif PASSWORD:
response = password_request(proxy_url)
elif LOCALPART:
response = localpart_request(proxy_url)
elif DOMAIN:
response = domain_request(proxy_url)
else:
exit(-1)
data = response_parser(response)
json_data = json.dumps(data, indent=2, separators=(',', ': '))
print(json_data)
return 0
if __name__ == "__main__":
main()