forked from elcodigok/wphardening
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wphardening.py
executable file
·193 lines (177 loc) · 7.16 KB
/
wphardening.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
#!/usr/bin/env python
"""
wphardening.py
Copyright 2013 Daniel Maldonado
This file is part of WPHardening project.
WPHardening 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, either version 3 of the License, or
(at your option) any later version.
WPHardening 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.
You should have received a copy of the GNU General Public License
along with WPHardening. If not, see <http://www.gnu.org/licenses/>.
"""
from optparse import OptionParser, OptionGroup
from lib.checkWordpress import checkWordpress
from lib.chmodWordPress import chmodWordPress
from lib.removeWordPress import removeWordPress
from lib.robotsWordPress import robotsWordPress
from lib.deleteVersionWordPress import deleteVersionWordPress
from lib.fingerprintingWordPress import fingerprintingWordPress
from lib.pluginsWordPress import pluginsWordPress
from lib.indexesWordPress import indexesWordPress
from lib.wpconfigWordPress import wpconfigWordPress
from lib.termcolor import colored, cprint
from lib.registerLog import registerLog
import os
import sys
import urllib2
def main():
usage = "usage: %prog [options] arg"
version = colored('WP Hardening', 'green') + ' version' + \
colored(' 1.1', 'yellow')
parser = OptionParser(usage, version=version)
parser.add_option(
"-v", "--verbose", action="store_true", dest="verbose",
help="active verbose mode output results",
)
group1 = OptionGroup(
parser, "Target",
"This option must be specified to modify the package WordPress."
)
group1.add_option(
"-d", "--dir", dest="path",
help="**REQUIRED** - Working Directory.", metavar="DIRECTORY"
)
parser.add_option_group(group1)
group2 = OptionGroup(
parser, "Hardening", "Different tools to hardening WordPress."
)
group2.add_option(
"-c", "--chmod", action="store_true", dest="chmod",
help="Chmod 755 in directory and 644 in files."
)
group2.add_option(
"-r", "--remove", action="store_true", dest="remove",
help="Remove files and directory."
)
group2.add_option(
"-b", "--robots", action="store_true", dest="robots",
help="Create file robots.txt"
)
group2.add_option(
"-f", "--fingerprinting", action="store_true",
dest="finger", help="Deleted fingerprinting WordPress."
)
group2.add_option(
"--wp-config", action="store_true", dest="wpconfig",
help="Generated wp-config.php"
)
group2.add_option(
"--delete-version", action="store_true",
dest="delete_version", help="Deleted version WordPress."
)
group2.add_option(
"--plugins", action="store_true", dest="plugins",
help="Download Plugins Security."
)
group2.add_option(
"--proxy", action="store", type="string", dest="proxy",
help="Use a HTTP proxy to connect to the target url for --plugins and \
--wp-config."
)
group2.add_option(
"--indexes", action="store_true", dest="indexes",
help="It allows you to display the contents of directories."
)
parser.add_option_group(group2)
group3 = OptionGroup(
parser, "Miscellaneous",
)
group3.add_option(
"-o", "--output", help="Write log report to FILE.log", metavar="FILE",
dest="output"
)
parser.add_option_group(group3)
(options, args) = parser.parse_args()
if options.output is None:
filename = 'wphardening.log'
else:
filename = options.output
log = registerLog(filename)
log.setConfigure()
if options.path is None:
log.add("Did not specify a working directory.")
parser.print_help()
sys.exit()
options.path = os.path.abspath(options.path)
if os.path.exists(options.path):
wordpress = checkWordpress(options.path)
if wordpress.isWordPress():
log.add(options.path + " This project directory is a WordPress.")
print colored(options.path, 'yellow') + ' -', \
colored('\nThis project directory is a WordPress.', 'green')
if options.delete_version is not None:
asdf = deleteVersionWordPress(options.path)
asdf.delete()
if options.chmod is not None:
asdf = chmodWordPress(options.path)
asdf.changePermisions()
if options.remove is not None:
qwer = removeWordPress(options.path)
qwer.delete()
if options.robots is not None:
zxcv = robotsWordPress(options.path)
zxcv.createRobots()
if options.finger is not None:
asdf = fingerprintingWordPress(options.path)
asdf.searchStaticFile()
if options.wpconfig is not None:
if options.proxy is not None:
protocolo, rest = urllib2.splittype(options.proxy)
if protocolo is None:
raise ValueError("unknown URL type: %s") % \
(options.proxy)
host, rest = urllib2.splithost(rest)
host, port = urllib2.splitport(host)
if port is None:
raise ValueError("unknown protocol for %s") % \
(options.proxy)
puerto = int(port)
asdf = wpconfigWordPress(options.path, options.proxy)
else:
asdf = wpconfigWordPress(options.path, options.proxy)
asdf.createConfig()
if options.indexes is not None:
asdf = indexesWordPress(options.path)
asdf.createIndexes()
if options.plugins is not None:
if options.proxy is not None:
protocolo, rest = urllib2.splittype(options.proxy)
if protocolo is None:
raise ValueError("unknown URL type: %s") % \
(options.proxy)
host, rest = urllib2.splithost(rest)
host, port = urllib2.splitport(host)
if port is None:
raise ValueError("unknown protocol for %s") % \
(options.proxy)
puerto = int(port)
asdf = pluginsWordPress(options.path, options.proxy)
else:
asdf = pluginsWordPress(options.path, options.proxy)
asdf.questions()
else:
log.add(
options.path + " This Project directory is not a WordPress."
)
print colored(options.path, 'yellow') + ' -', \
colored('This Project directory is not a WordPress.\n', 'red')
else:
log.add("Could not find the specified directory.")
print colored('\nCould not find the specified directory.\n', 'red')
if __name__ == "__main__":
main()