forked from attackplay/WPSploit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwpsploit.py
More file actions
executable file
·278 lines (251 loc) · 10.4 KB
/
wpsploit.py
File metadata and controls
executable file
·278 lines (251 loc) · 10.4 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python
# -*- Coding: UTF-8 -*-
#
# Copyright (c) 2017 @m4ll0k
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import os
import sys
import re
import glob
import fnmatch
import json
BANNER = r"""
__ ____________ _________ __ __ __
/ \ / \______ \/ _____/_____ | | ____ |__|_/ |__
\ \/\/ /| ___/\_____ \\____ \| | / _ \| |_ ___|
\ / | | / \ |_) | |_( (_) ) | | |
\__/\ / |____| /_______ / __/|____/\____/|__| |__|
\/ \/|__|
Aggressive Code Scanner for WordPress Themes/Plugins
Author: Momo (m4ll0k) Outaadi
Contributors: Filippo (b4dnewz) Conti
"""
class colors(object):
RED = "\033[1;31m"
GREEN = "\033[1;32m"
END = "\033[0m"
# Vulnerabilities References
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet
class wpsploit(object):
def main(self):
self.banner()
if len(sys.argv) <= 1:
self.usage()
result = []
source = sys.argv[1]
# Recursively test all files
if os.path.isdir(source):
print("Scanning directory: {}".format(source))
files = self.recursiveRead(source, '*.php')
print("Found {} files with php extension.\n".format(len(files)))
for file in files:
res = self.testFile(file)
result.append(res)
# Test single file
else:
file = self.control(source)
res = self.testFile(file)
result.append(res)
def printLine(self, line, label, value):
line = " {}[L{}]{}".format(colors.GREEN, line, colors.END)
label = "{}{}{}".format(colors.GREEN, label, colors.END)
value = "{}{}{}".format(colors.RED, value, colors.END)
print "{} Possibile {} ==> {}".format(line, label, value)
# Test file against common vulnerabilities
def testFile(self, path):
print("Testing file: {}".format(path))
res = {
"name": path,
"total": 0,
"data": {
"xss": [],
"sql": [],
"fid": [],
"fin": [],
"php": [],
"com": [],
"auth": [],
"pce": [],
"ope": [],
"csrf": []
}
}
try:
code = self.readfile(path)
res['data']['xss'] = self.xss(code)
res['data']['sql'] = self.sql(code)
res['data']['fid'] = self.fid(code)
res['data']['fin'] = self.fin(code)
res['data']['php'] = self.php(code)
res['data']['com'] = self.com(code)
res['data']['auth'] = self.auth(code)
res['data']['pce'] = self.pce(code)
res['data']['ope'] = self.ope(code)
res['data']['csfr'] = self.csrf(code)
# Get total possible vulnerabilities
res['total'] = sum(len(arr) for arr in res['data'].values())
return res
except Exception as e:
raise
# Check for Cross Site Request Forgery
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#cross-site-request-forgery-csrf
def csrf(self, code):
blacklist = [r'wp_nonce_field\(\S*\)', r'wp_nonce_url\(\S*\)',
r'wp_verify_nonce\(\S*\)', r'check_admin_referer\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "Cross-Site Request Forgery", pattern[0])
return vulns
# Check for Open Redirect
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#open-redirect
def ope(self, code):
vulns = []
for idx, cd in enumerate(code):
pattern = re.findall(r"wp_redirect\(\S*\)", cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "Open Redirect", pattern[0])
return vulns
# Check for PHP Code Execution
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#php-code-execution
def pce(self, code):
blacklist = [r'eval\(\S*\)', r'assert\(\S*\)', r'preg_replace\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "PHP Code Execution", pattern[0])
return vulns
# Check for Command Execution
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#command-execution
def com(self, code):
blacklist = [r'system\(\S*\)', r'exec\(\S*\)',
r'passthru\(\S*\)', r'shell_exec\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "Command Execution", pattern[0])
return vulns
# Check for Authorization Hole
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#authorisation
def auth(self, code):
blacklist = [r'is_admin\(\S*\)', r'is_user_admin\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "Authorization Hole", pattern[0])
return vulns
# Check for PHP Object Injection
def php(self, code):
vulns = []
for idx, cd in enumerate(code):
pattern = re.findall(r"unserialize\(\S*\)", cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "PHP Object Injection", pattern[0])
return vulns
# Check for File Inclusion
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#file-inclusion
def fin(self, code):
blacklist = [r'include\(\S*\)', r'require\(\S*\)',
r'include_once\(\S*\)', r'require_once\(\S*\)', r'fread\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "File Inclusion", pattern[0])
return vulns
# Check for File Download
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#file-download
def fid(self, code):
blacklist = [r'file\(\S*\)', r'readfile\(\S*\)',
r'file_get_contents\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "File Download", pattern[0])
return vulns
# Check for Sql Injection
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#sql-injection
def sql(self, code):
blacklist = [r'\$wpdb->query\(\S*\)', r'\$wpdb->get_var\(\S*\)', r'\$wpdb->get_row\(\S*\)', r'\$wpdb->get_col\(\S*\)',
r'\$wpdb->get_results\(\S*\)', r'\$wpdb->replace\(\S*\)', r'esc_sql\(\S*\)', r'escape\(\S*\)', r'esc_like\(\S*\)',
r'like_escape\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "Sql Injection", pattern[0])
return vulns
# Check for Cross-Site Scripting
# https://github.com/ethicalhack3r/wordpress_plugin_security_testing_cheat_sheet#cross-site-scripting-xss-tips
def xss(self, code):
blacklist = [r'\$_GET\[\S*\]', r'\$_POST\[\S*\]', r'\$_REQUEST\[\S*\]', r'\$_SERVER\[\S*\]', r'\$_COOKIE\[\S*\]',
r'add_query_arg\(\S*\)', r'remove_query_arg\(\S*\)']
vulns = []
for bl in blacklist:
for idx, cd in enumerate(code):
pattern = re.findall(bl, cd, re.I)
if pattern != []:
vulns.append({"line": idx, "match": pattern[0] })
self.printLine(idx, "Cross-Site Scripting", pattern[0])
return vulns
def control(self, filename):
if not filename.endswith('.php'):
self.usage()
else:
return filename
def readfile(self, filename):
codelist = []
try:
file = open(filename, "rb+")
for line in file.readlines():
line = line.split('\n')[0]
codelist.append(line)
return codelist
except IOError, e:
raise
def recursiveRead(self, rootdir, pattern):
matches = []
for root, dirnames, filenames in os.walk(rootdir):
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(root, filename))
return matches
def usage(self):
print("Usage: $ python wpsploit.py <file|dir> \n")
exit()
def banner(self):
print(BANNER)
# Run the script
if __name__ == "__main__":
try:
wpsploit().main()
except KeyboardInterrupt, e:
exit()