forked from DedSecInside/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
161 lines (143 loc) · 5.94 KB
/
main.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
"""
Core
"""
import argparse
import sys
from .modules import link_io
from .modules.linktree import LinkTree
from .modules.color import color
from .modules.updater import check_version
from .modules.savefile import saveJson
from .modules.info import execute_all
from .modules.collect_data import collect_data
from .modules.nlp import main
from . import version
# TorBot CLI class
class TorBot:
def __init__(self, args):
self.args = args
def get_header(self):
license_msg = color("LICENSE: GNU Public License v3", "red")
banner = r"""
__ ____ ____ __ ______
/ /_/ __ \/ __ \/ /_ ____/_ __/
/ __/ / / / /_/ / __ \/ __ \/ /
/ /_/ /_/ / _, _/ /_/ / /_/ / /
\__/\____/_/ |_/_____/\____/_/ V{VERSION}
""".format(VERSION=version.__version__)
banner = color(banner, "red")
title = r"""
{banner}
#######################################################
# TorBot - Dark Web OSINT Tool #
# GitHub : https://github.com/DedsecInside/TorBot #
# Help : use -h for help text #
#######################################################
{license_msg}
"""
title = title.format(license_msg=license_msg, banner=banner)
print(title)
def handle_json_args(self, args):
"""
Outputs JSON file for data
"""
# -m/--mail
if args.mail:
email_json = link_io.print_emails(args.url)
if args.save:
saveJson('Emails', email_json)
# -p/--phone
if args.phone:
phone_json = link_io.print_phones(args.url)
if args.save:
saveJson('Phones', phone_json)
# -s/--save
else:
node_json = link_io.print_json(args.url, args.depth)
saveJson("Links", node_json)
def handle_tree_args(self, args):
"""
Outputs tree visual for data
"""
tree = LinkTree(args.url, args.depth)
# -v/--visualize
if args.visualize:
tree.show()
# -d/--download
if args.download:
file_name = str(input("File Name (.txt): "))
tree.save(file_name)
def perform_action(self):
args = self.args
if args.gather:
collect_data(args.url)
return
# 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:" + self.__version__)
sys.exit()
if args.update:
check_version()
sys.exit()
if not args.quiet:
self.get_header()
# If url flag is set then check for accompanying flag set. Only one
# additional flag can be set with -u/--url flag
if not args.url:
print("usage: See run.py -h for possible arguments.")
link_io.print_tor_ip_address()
if args.classify:
result = main.classify(args.url)
print("Website Classification: " + result[0], "| Accuracy: " + str(result[1]))
if args.visualize or args.download:
self.handle_tree_args(args)
# raise NotImplementedError("Tree visualization and download is not available yet.")
elif args.save or args.mail or args.phone:
self.handle_json_args(args)
# -i/--info
elif args.info:
execute_all(args.url)
else:
if args.url:
link_io.print_tree(args.url, args.depth, args.classifyAll)
print("\n\n")
def get_args():
"""
Parses user flags passed to TorBot
"""
parser = argparse.ArgumentParser(prog="TorBot", usage="Gather and analayze data from Tor sites.")
parser.add_argument("--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("-p", "--phone", action="store_true", help="Get phone numbers from the crawled sites")
parser.add_argument("--depth", help="Specifiy max depth of crawler (default 1)", default=1)
parser.add_argument("--gather", action="store_true", help="Gather data for analysis")
parser.add_argument("-v", "--visualize", action="store_true", help="Visualizes tree of data gathered.")
parser.add_argument("-d", "--download", action="store_true", help="Downloads tree of data gathered.")
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("-c", "--classify", action="store_true", help="Classify the webpage using NLP module")
parser.add_argument(
"-cAll", "--classifyAll", action="store_true", help="Classify all the obtained webpages using NLP module"
)
parser.add_argument(
"-i", "--info", action="store_true", help=' '.join(("Info displays basic info of the scanned site"))
)
return parser.parse_args()
if __name__ == '__main__':
try:
args = get_args()
torbot = TorBot(args)
torbot.perform_action()
except KeyboardInterrupt:
print("Interrupt received! Exiting cleanly...")