-
Notifications
You must be signed in to change notification settings - Fork 42
/
webcve.py
executable file
·217 lines (173 loc) · 7.72 KB
/
webcve.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
#!/usr/bin/env python3
"""
webcve - A simple framework for sending test payloads for known web CVEs.
"""
import os
import sys
import json
import argparse
import requests
import urllib3
from termcolor import cprint
# suppress insecure warnings (urllib3):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
DETECTED_CODE = 406
TESTS_PATH = 'tests/'
CVE_TESTS = os.listdir(TESTS_PATH)
RESULTS = []
def get_data_file(localfile, mode='r'):
"""
Get data file contents
"""
with open(localfile, mode=mode) as datafile:
contents = datafile.read()
return contents
if __name__ == '__main__':
PARSER = argparse.ArgumentParser(description='Web CVE Tests.')
PARSER.add_argument('-v',
'--verbose',
help='Dsiplay verbose output',
default=False,
action="store_true")
PARSER.add_argument('-u',
'--url',
help='Target URL to send payloads to, e.g. https://mytest-site.com.',
required=False)
PARSER.add_argument('-s',
'--status-code',
help='The server response status code that indicates the payload was \
succesfully detected.',
default="403")
PARSER.add_argument('-c',
'--cve',
help='Test specified CVE only, format: CVE-XXXX-XXXXX.')
PARSER.add_argument('-g',
'--group',
help='Test group of CVEs (groups defined in groups.json). \
This will override --cve')
PARSER.add_argument('-t',
'--type',
help='Test type of CVEs (types defined in groups.json). \
This will ovverride --group')
PARSER.add_argument('-l',
'--list',
help='List available groups or types.',
choices=['group', 'type'])
PARSER.add_argument('-j',
'--json',
help='Write output in JSON format to file.',)
PARSER.add_argument('-i',
'--insecure',
help='Allow insecure connections (do not verify TLS certificates).',
action='store_false',
default=True)
ARGS = PARSER.parse_args()
BASE_URL = ARGS.url
if ARGS.list is not None:
if not os.path.isfile('groups.json'):
cprint("groups.json not found!", "red")
sys.exit(1)
with open('groups.json') as f:
GROUPS = json.load(f)
DEDUP = []
for group in GROUPS:
if ARGS.list == 'group':
value = group['name']
if ARGS.list == 'type':
value = group['type']
if value not in DEDUP:
print(value)
DEDUP.append(value)
sys.exit()
if ARGS.status_code is not None:
DETECTED_CODE = ARGS.status_code
if ARGS.cve is not None:
CVE_TESTS = [ARGS.cve]
if ARGS.group is not None:
CVE_TESTS.clear()
if not os.path.isfile('groups.json'):
cprint("groups.json not found!", "red")
sys.exit(1)
with open('groups.json') as f:
GROUPS = json.load(f)
for group in GROUPS:
if group['name'] == ARGS.group.lower():
CVE_TESTS.extend(group['cves'])
if ARGS.type is not None:
CVE_TESTS.clear()
if not os.path.isfile('groups.json'):
cprint("groups.json not found!", "red")
sys.exit(1)
with open('groups.json') as f:
GROUPS = json.load(f)
for group in GROUPS:
if group['type'] == ARGS.type.lower():
CVE_TESTS.extend(group['cves'])
for name in CVE_TESTS:
if ARGS.url is None:
PARSER.print_help()
print('webcve.py: error: the following arguments are required: -u/--url')
sys.exit(1)
description = ''
reference = ''
cprint("{}".format(name), "yellow")
result = {}
result[name] = []
if ARGS.verbose is True:
if os.path.isfile('tests/{}/description.txt'.format(name)):
with open('tests/{}/description.txt'.format(name)) as f:
description = f.read()
cprint(description, "white")
if not os.path.isfile('tests/{}/test.json'.format(name)):
cprint("\tTests not found for {}".format(name), "red")
else:
with open('tests/{}/test.json'.format(name)) as f:
tests = json.load(f)
for test in tests:
if test['Method'].upper() == 'POST':
if 'Data' in test:
data = test['Data']
if 'Data-File' in test:
data = get_data_file('tests/{}/{}'.format(name,
test['Data-File']))
if 'Data-Binary-File' in test:
data = get_data_file('tests/{}/{}'.format(name,
test['Data-Binary-File']), 'rb')
if 'File-Upload-File' in test:
data = get_data_file('tests/{}/{}'.format(name,
test['File-Upload-File']))
response = requests.post('{}{}'.format(BASE_URL, test['URI']),
headers=test['Headers'],
files={'files[]': (test['File-Upload-Name'],
data)},
allow_redirects=False,
verify=ARGS.insecure)
else:
response = requests.post('{}{}'.format(BASE_URL, test['URI']),
headers=test['Headers'],
data=data,
allow_redirects=False,
verify=ARGS.insecure)
elif test['Method'].upper() == 'GET':
if 'Data-File' in test:
data = get_data_file('tests/{}/{}'.format(name, test['Data-File']))
response = requests.get('{}{}'.format(BASE_URL, test['URI']),
headers=test['Headers'],
data=data,
allow_redirects=False,
verify=ARGS.insecure)
else:
response = requests.get('{}{}'.format(BASE_URL, test['URI']),
headers=test['Headers'],
allow_redirects=False,
verify=ARGS.insecure)
if response.status_code == int(DETECTED_CODE):
cprint("\tTest passed ({})".format(response.status_code), "green")
result[name].append("Pass")
else:
cprint("\tTest failed ({})".format(response.status_code), "red")
result[name].append("Fail")
RESULTS.append(result)
if ARGS.json is not None:
with open(ARGS.json, "w") as outfile:
json.dump(RESULTS, outfile)