forked from DedSecInside/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
torBot.py
189 lines (167 loc) · 7.84 KB
/
torBot.py
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
import argparse
import socket
import socks
from modules import (bcolors, getemails, pagereader, getweblinks, updater,
info, savefile)
LOCALHOST = "127.0.0.1"
PORT = 9050
# TorBot VERSION
__VERSION = "1.2"
def connect(address, port):
""" Establishes connection to port
Assumes port is bound to localhost, if host that port is bound to changes
then change the port
Args:
address: address for port to bound to
port: Establishes connect to this port
"""
socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, address, port)
socket.socket = socks.socksocket # Monkey Patch our socket to tor socket
def getaddrinfo(*args):
"""
Overloads socket function for std socket library
Check socket.getaddrinfo() documentation to understand parameters.
Simple description below:
argument - explanation (actual value)
socket.AF_INET - the type of address the socket can speak to (IPV4)
sock.SOCK_STREAM - creates a stream connecton rather than packets
6 - protocol being used is TCP
Last two arguments should be a tuple containing the address and port
"""
return [(socket.AF_INET, socket.SOCK_STREAM, 6,
'', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo
def header():
"""
Prints out header ASCII art
"""
b_color = bcolors.Bcolors()
D3DSEC = b_color.FAIL + " D3DSEC " + b_color.WHITE
INS1DE = b_color.FAIL + " INS1DE " + b_color.WHITE
header = r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.'OWMMMMM
MMMMMMMMMNl,ONNN0OXNNNNNXXNKOkOK0xkl':c::::::;.;KMMMMM
MMMMMMMMM0,lNWXO0NNNNXKKXXNXO0Ok0Oxl',:;;;;;;;..dMMMMM
MMMMMMMMMk,xWNOONNNX00XNNNWKOO0OkOxc'';;,,,,,,'.cMMMMM
MMMMMMMMMx,xWKkKWNXOKNWNNNX0xxOKxxx:..,,,,,''''.cMMMMM
MMMMMMMMM0,oWXkOWXOKNNNNN00Xkdx0kdd;..,'''''''..oMMMMM
MMMMMMMMMNl;0W0kKKkKWNNN0ONNOxdOOll,..'''......,0MMMMM
MMMMMMMMMMK::KN0kKOkNNWXk0WX0kdxkc:............xWMMMMM
MMMMMMMMMMMKl:kX0k0kONWNOONX0koxd:,..........'kWMMMMMM
MMMMMMMMMMMMNxccxOkkxkKWKx0NOoooc'..........lKWMMMMMMM
MMMMMMMMMMMMMWNklccclldk0OxOdcc;. .......;oKWWMMMMMMMM
MMMMMMMMMMMMMMMMWXOdl:::;cc;'... ..',:lx0NMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMNKOkxddolloodk0XWMMMMMMMMMMMMMMMM
{FAIL} + {BOLD}
__ ____ ____ __ ______
/ /_/ __ \/ __ \/ /_ ____/_ __/
/ __/ / / / /_/ / __ \/ __ \/ /
/ /_/ /_/ / _, _/ /_/ / /_/ / /
\__/\____/_/ |_/_____/\____/_/ V{VERSION}
{FAIL} + {On_Black}
#######################################################
# TorBot - A python Tor Crawler #
# GitHub : https://github.com/DedsecInside/TorBot #
# Help : use -h for help text #
#######################################################
{FAIL} + "LICENSE: GNU Public License" + {END}""".format(
D3DSEC=D3DSEC, INS1DE=INS1DE, FAIL=b_color.FAIL,
BOLD=b_color.BOLD, VERSION=__VERSION, END=b_color.ENDC,
On_Black=b_color.On_Black, WHITE=b_color.WHITE
)
print(header)
def main(conn=False):
if conn:
connect(LOCALHOST, PORT)
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--version",
action="store_true",
help="Show current version of TorBot.")
parser.add_argument("--update",
action="store_true",
help="Update TorBot to the latest stable version")
parser.add_argument("-q", "--quiet",
action="store_true")
parser.add_argument("-u", "--url",
help="Specifiy a website link to crawl")
parser.add_argument("-s", "--save",
action="store_true",
help="Save results in a file")
parser.add_argument("-m", "--mail",
action="store_true",
help="Get e-mail addresses from the crawled sites")
parser.add_argument("-e", "--extension",
action='append',
dest='extension',
default=[],
help=' '.join(("Specifiy additional website extensions",
"to the list(.com , .org etc)")))
parser.add_argument("-l", "--live",
action="store_true",
help="Check if websites are live or not (slow)")
parser.add_argument("-i", "--info",
action="store_true",
help=' '.join(("Info displays basic info of the",
"scanned site, (very slow)")))
args = parser.parse_args()
link = args.url
# If flag is -v, --update, -q/--quiet then user only runs that operation
# because these are single flags only
if args.version:
print("TorBot Version:" + __VERSION)
exit()
if args.update:
updater.updateTor()
exit()
if not args.quiet:
header()
# If url flag is set then check for accompanying flag set. Only one
# additional flag can be set with -u/--url flag
if args.url:
print("Tor IP Address :", pagereader.get_ip())
html_content = pagereader.read_first_page(link)
# -m/--mail
if args.mail:
emails = getemails.getMails(html_content)
print(emails)
if args.save:
savefile.saveJson('Emails', emails)
# -i/--info
elif args.info:
info.executeAll(link, html_content)
if args.save:
print('Nothing to save.\n')
else:
links = getweblinks.get_links(soup=html_content,
live=args.live,
ext=args.extension)
if args.save:
savefile.saveJson("Links", links)
else:
print("usage: torBot.py [-h] [-v] [--update] [-q] [-u URL] [-s] [-m] [-e EXTENSION] [-l] [-i]")
print("\n\n")
if __name__ == '__main__':
try:
main(conn=True)
except KeyboardInterrupt:
print("Interrupt received! Exiting cleanly...")