forked from websecurify/docker-secapps-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·197 lines (132 loc) · 3.98 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
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
#!/usr/bin/env python
# ---
# ---
# ---
import argparse
parser = argparse.ArgumentParser(description='SecApps Driver')
parser.add_argument('tool', metavar='tool', type=str, choices=['foundation', 'scanner', 'recon', 'wpscanner'], help='the tool to be executed')
parser.add_argument('target', metavar='target', type=str, help='the target to be tested')
parser.add_argument('-d', '--debug', dest='debug', action='store_true', help='enable debug messages')
parser.add_argument('-r, ''--report-format', dest='report_format', type=str, choices=['csv', 'xml', 'html', 'json'], default=['html'], nargs='+', help='report format')
parser.add_argument('-a', '--access-token', dest='access_token', type=str, help='access token')
parser.add_argument('-b', '--display-backend', dest='display_backend', type=str, choices=['vnc'], default='', help='display backend')
args = parser.parse_args()
# ---
# ---
# ---
import logging
if args.debug:
logging.basicConfig(level=logging.DEBUG)
# ---
# ---
# ---
import os
import sys
# ---
# ---
# ---
from pyvirtualdisplay import Display
if args.display_backend == 'vnc':
display = Display(backend='xvnc')
else:
display = Display()
display.start()
if args.display_backend == 'vnc':
os.system('/usr/bin/fluxbox -display :{0!s} &'.format(display.display))
# ---
# ---
# ---
from time import sleep
# ---
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
# ---
# ---
# ---
mimes = [
'application/octet-stream',
'application/csv',
'text/csv'
'application/xml',
'text/xml'
'application/html',
'text/html',
'application/json',
'text/json'
]
mimes += ['data:{0!s}'.format(mime) for mime in mimes]
# ---
# ---
# ---
profile = webdriver.FirefoxProfile()
profile.add_extension(extension='/tmp/websecurify-5.5.0-fx.xpi')
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.helperApps.alwaysAsk.force', False)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/output')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ','.join(mimes))
# ---
# ---
# ---
browser=webdriver.Firefox(firefox_profile=profile)
browser.maximize_window()
# ---
# ---
# ---
def scanner():
browser.find_element_by_id('scan-url').send_keys(args.target, Keys.RETURN)
browser.find_element_by_id('scan-confirmation-label').click()
browser.find_element_by_id('scan-proceed').click()
# ---
while True:
status = browser.find_element_by_id('scan-status').text
# ---
sys.stdout.write('[*] ' + status + '\n')
sys.stdout.flush()
# ---
if status.find('100%') > 0:
break
# ---
sleep(5)
# ---
chain = ActionChains(browser)
# ---
chain.move_to_element(browser.find_element_by_id('toolbar-item-report')).perform()
for rf in args.report_format:
chain.move_to_element(browser.find_element_by_id('toolbar-item-export-' + rf)).click().perform()
# ---
sleep(1)
# ---
fls = os.listdir('/output')
if len(fls) == 0:
sys.stdout.write('[-] no reports generated\n')
sys.stdout.flush()
else:
for fl in fls:
sys.stdout.write('[*] report ' + fl + ' generated\n')
sys.stdout.flush()
# ---
# ---
# ---
if __name__ == '__main__':
try:
# Navigate to the selected tool, optionaly using the provided token.
browser.get('https://secapps.com/apps/' + args.tool + '/' + ('?access-token=' + args.access_token if args.access_token else ''))
# ---
# Get rid of any automatic popups such as help and welcome screens.
browser.execute_script('document.location.hash = "#"')
# ---
# Sleep for a bit to ensure that the environment is ready.
sleep(5)
# ---
# Execute selenium script based on the selected tool.
{
'foundation': scanner,
'scanner': scanner,
'recon': scanner,
'spider': scanner,
'wpscanner': scanner
}.get(args.tool)()
except (KeyboardInterrupt, SystemExit): pass
# ---