-
Notifications
You must be signed in to change notification settings - Fork 3
/
owtf.py
executable file
·258 lines (227 loc) · 9.68 KB
/
owtf.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
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
#!/usr/bin/env python2
"""
This is the command-line front-end:
In charge of processing arguments and call the framework.
"""
from __future__ import print_function
import os
import sys
import logging
from framework.core import Core
from framework.dependency_management.component_initialiser import ComponentInitialiser, DatabaseNotRunningException
from framework.dependency_management.dependency_resolver import ServiceLocator
from framework import update
from framework.lib.cli_options import usage, parse_options, parse_update_options
def banner():
print("""\033[92m
_____ _ _ _ _____ _____
| | | | |_ _| __|
| | | | | | | | | __|
|_____|_____| |_| |__|
@owtfp
http://owtf.org
\033[0m""")
def get_plugins_from_arg(arg):
plugins = arg.split(',')
plugin_groups = ServiceLocator.get_component("db_plugin").GetGroupsForPlugins(plugins)
if len(plugin_groups) > 1:
usage("The plugins specified belong to several Plugin Groups: '%s'" % str(plugin_groups))
return [plugins, plugin_groups]
def process_options(user_args):
try:
db_plugin = ServiceLocator.get_component("db_plugin")
valid_groups = db_plugin.GetAllGroups()
valid_types = db_plugin.GetAllTypes() + ['all', 'quiet']
arg = parse_options(user_args, valid_groups, valid_types)
except KeyboardInterrupt as e:
usage("Invalid OWTF option(s) %s" % e)
# Default settings:
profiles = {}
plugin_group = arg.PluginGroup
if arg.CustomProfile: # Custom profiles specified
# Quick pseudo-validation check
for profile in arg.CustomProfile.split(','):
chunks = profile.split(':')
if len(chunks) != 2 or not os.path.exists(chunks[1]):
usage("Invalid Profile")
else: # profile "ok" :)
profiles[chunks[0]] = chunks[1]
if arg.OnlyPlugins:
arg.OnlyPlugins, plugin_groups = get_plugins_from_arg(arg.OnlyPlugins)
try:
# Set Plugin Group according to plugin list specified
plugin_group = plugin_groups[0]
except IndexError:
usage("Please use either OWASP/OWTF codes or Plugin names")
logging.info("Defaulting Plugin Group to '%s' based on list of plugins supplied" % plugin_group)
if arg.ExceptPlugins:
arg.ExceptPlugins, plugin_groups = get_plugins_from_arg(arg.ExceptPlugins)
if arg.TOR_mode:
arg.TOR_mode = arg.TOR_mode.split(":")
if(arg.TOR_mode[0] == "help"):
from framework.http.proxy.tor_manager import TOR_manager
TOR_manager.msg_configure_tor()
exit(0)
if len(arg.TOR_mode) == 1:
if arg.TOR_mode[0] != "help":
usage("Invalid argument for TOR-mode")
elif len(arg.TOR_mode) != 5:
usage("Invalid argument for TOR-mode")
else:
# Enables OutboundProxy.
if arg.TOR_mode[0] == '':
outbound_proxy_ip = "127.0.0.1"
else:
outbound_proxy_ip = arg.TOR_mode[0]
if arg.TOR_mode[1] == '':
outbound_proxy_port = "9050" # default TOR port
else:
outbound_proxy_port = arg.TOR_mode[1]
arg.OutboundProxy = "socks://%s:%s" % (outbound_proxy_ip, outbound_proxy_port)
if arg.Botnet_mode: # Checking arguments
arg.Botnet_mode = arg.Botnet_mode.split(":")
if arg.Botnet_mode[0] == "miner" and len(arg.Botnet_mode) != 1:
usage("Invalid argument for Botnet mode\n Mode must be miner or list")
if arg.Botnet_mode[0] == "list":
if len(arg.Botnet_mode) != 2:
usage("Invalid argument for Botnet mode\n Mode must be miner or list")
if not os.path.isfile(os.path.expanduser(arg.Botnet_mode[1])):
usage("Error Proxy List not found! Please check the path.")
if arg.OutboundProxy:
arg.OutboundProxy = arg.OutboundProxy.split('://')
if len(arg.OutboundProxy) == 2:
arg.OutboundProxy = arg.OutboundProxy + arg.OutboundProxy.pop().split(':')
if arg.OutboundProxy[0] not in ["socks", "http"]:
usage("Invalid argument for Outbound Proxy")
else:
arg.OutboundProxy = arg.OutboundProxy.pop().split(':')
# OutboundProxy should be type://ip:port
if (len(arg.OutboundProxy) not in [2, 3]):
usage("Invalid argument for Outbound Proxy")
else: # Check if the port is an int.
try:
int(arg.OutboundProxy[-1])
except ValueError:
usage("Invalid port provided for Outbound Proxy")
if arg.InboundProxy:
arg.InboundProxy = arg.InboundProxy.split(':')
# InboundProxy should be (ip:)port:
if len(arg.InboundProxy) not in [1, 2]:
usage("Invalid argument for Inbound Proxy")
else:
try:
int(arg.InboundProxy[-1])
except ValueError:
usage("Invalid port for Inbound Proxy")
plugin_types_for_group = db_plugin.GetTypesForGroup(plugin_group)
if arg.PluginType == 'all':
arg.PluginType = plugin_types_for_group
elif arg.PluginType == 'quiet':
arg.PluginType = ['passive', 'semi_passive']
scope = arg.Targets or [] # Arguments at the end are the URL target(s)
num_targets = len(scope)
if plugin_group != 'auxiliary' and num_targets == 0 and not arg.list_plugins:
# TODO: Fix this
pass
elif num_targets == 1: # Check if this is a file
if os.path.isfile(scope[0]):
logging.info("Scope file: trying to load targets from it ..")
new_scope = []
for target in open(scope[0]).read().split("\n"):
CleanTarget = target.strip()
if not CleanTarget:
continue # Skip blank lines
new_scope.append(CleanTarget)
if len(new_scope) == 0: # Bad file
usage("Please provide a scope file (1 target x line)")
scope = new_scope
for target in scope:
if target[0] == "-":
usage("Invalid Target: " + target)
args = ''
if plugin_group == 'auxiliary':
# For auxiliary plugins, the scope are the parameters.
args = scope
# auxiliary plugins do not have targets, they have metasploit-like parameters.
scope = ['auxiliary']
return {
'list_plugins': arg.list_plugins,
'Force_Overwrite': arg.ForceOverwrite,
'Interactive': arg.Interactive == 'yes',
'Simulation': arg.Simulation,
'Scope': scope,
'argv': sys.argv,
'PluginType': arg.PluginType,
'OnlyPlugins': arg.OnlyPlugins,
'ExceptPlugins': arg.ExceptPlugins,
'InboundProxy': arg.InboundProxy,
'OutboundProxy': arg.OutboundProxy,
'OutboundProxyAuth': arg.OutboundProxyAuth,
'Profiles': profiles,
'PluginGroup': plugin_group,
'RPort': arg.RPort,
'PortWaves': arg.PortWaves,
'ProxyMode': arg.ProxyMode,
'TOR_mode': arg.TOR_mode,
'Botnet_mode': arg.Botnet_mode,
'nowebui': arg.nowebui,
'Args': args
}
def run_owtf(core, args):
try:
if core.start(args):
# Only if Start is for real (i.e. not just listing plugins, etc)
core.finish() # Not Interrupted or Crashed.
except KeyboardInterrupt:
# NOTE: The user chose to interact: interactivity check redundant here:
logging.warning("OWTF was aborted by the user:")
logging.info("Please check report/plugin output files for partial results")
# Interrupted. Must save the DB to disk, finish report, etc.
core.finish()
except SystemExit:
pass # Report already saved, framework tries to exit.
finally: # Needed to rename the temp storage dirs to avoid confusion.
core.clean_temp_storage_dirs()
def main(args):
banner()
# Get tool path from script path:
root_dir = os.path.dirname(os.path.abspath(args[0])) or '.'
owtf_pid = os.getpid()
if "--update" not in args[1:]:
try:
ComponentInitialiser.initialisation_phase_1(root_dir, owtf_pid)
except DatabaseNotRunningException:
exit(-1)
args = process_options(args[1:])
ServiceLocator.get_component("config").ProcessOptionsPhase1(args)
ComponentInitialiser.initialisation_phase_2(args)
# Initialise Framework.
core = Core()
logging.warn(
"OWTF Version: %s, Release: %s " % (
ServiceLocator.get_component("config").FrameworkConfigGet('VERSION'),
ServiceLocator.get_component("config").FrameworkConfigGet('RELEASE'))
)
run_owtf(core, args)
else:
# First confirming that --update flag is present in args and then
# creating a different parser for parsing the args.
try:
arg = parse_update_options(args[1:])
except Exception as e:
usage("Invalid OWTF option(s) %s" % e)
# Updater class is imported
updater = update.Updater(root_dir)
# If outbound proxy is set, those values are added to updater.
if arg.OutboundProxy:
if arg.OutboundProxyAuth:
updater.set_proxy(arg.OutboundProxy, proxy_auth=arg.OutboundProxyAuth)
else:
updater.set_proxy(arg.OutboundProxy)
# Update method called to perform update.
updater.update()
if __name__ == "__main__":
if os.getcwd().find(os.path.dirname(os.path.abspath(sys.argv[0]))) == 0:
usage("Start owtf in a different directory. 'cd path/to/pentest/directory; ./path/to/owtf.py'")
sys.exit("Can`t start owtf in current directory",1)
main(sys.argv)