Joomla mini auth

  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
##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
#
# This module is just a test of Joomla authentication.
# CC-BY: hasherezade (hasherezade.net)
##
require 'msf/core'
class Metasploit4 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
# util:
def fetchMd5(my_string)
if my_string =~ /([0-9a-fA-F]{32})/
return $1
end
return nil
end
def send_request_login(url, cookie, user, pass, uniq_token)
print_status("Trying to auth as user: #{user}")
if not url or not user or not pass or not cookie or not uniq_token
print_error("Invalid params to sessin_request")
return nil
end
res = send_request_cgi(
'uri' => url,
'method' => 'POST',
'cookie' => cookie,
'headers' =>
{
'Referer' => url
},
'vars_post' => {
'username' => user,
'passwd' => pass,
'option' => 'com_login',
'task' => 'login',
'return' => 'aW5kZXgucGhw',
uniq_token => 1
}
)
return res
end
def establish_session(url, user, pass)
res = send_request_cgi({
'method' => 'GET',
'uri' => url
})
return nil if not res
print_status( "Initial res code: #{res.code}")
if res.code != 200
return nil
end
sess = res.get_cookies
print_status("Cookie: #{sess}")
token_pattern = /(<input type=\"hidden\" name=\"[a-zA-Z0-9]*\" value=\"1\")/
return nil if not res
uniq_token = ''
if res.body =~ token_pattern
uniq_token = $1
uniq_token = fetchMd5(uniq_token)
print_good( "Found token: #{uniq_token}")
end
res = send_request_login(url, sess, datastore["USERNAME"], datastore["PASSWORD"], uniq_token)
if not res
return nil
end
print_status( "Initial res code: #{res.code}")
res = send_request_cgi({
'method' => 'GET',
'uri' => url,
'cookie' => sess,
'headers' =>
{
'Referer' => url
}
})
print_status( "Final res code: #{res.code}")
if res.body =~ token_pattern
#login page appeared again
print_error("Unable to authenticate!")
return nil
end
# optionaly: doublecheck if really logged in
successp = datastore['SUCCESS_PATTERN']
if successp and "#{successp}".length() > 0
if res.body =~ successp
return sess
end
print_error('Success pattern NOT found')
return nil
end
return sess
end
# MSF api:
def initialize(info = {})
super(update_info(info,
'Name' => 'Joomla Mini Auth',
'Description' => %q{
This module is just a test of Joomla authentication.
},
'Author' =>
[
'hAsh'
],
'License' => MSF_LICENSE,
'References' =>
[
],
'Privileged' => false,
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Payload' =>
{
'BadChars' => "&\n=+%",
},
'Targets' =>
[
[ 'Automatic', { } ],
],
'DefaultTarget' => 0))
register_options(
[
OptString.new('TARGETURI', [ true, "Base Joomla directory path", 'joomla']),
OptString.new('USERNAME', [ true, "Username to authenticate with", 'admin']),
OptString.new('PASSWORD', [ false, "Password to authenticate with", 'admin']),
OptRegexp.new('SUCCESS_PATTERN', [false, 'Pattern returned in response on login success', '/Log out/'] ),
], self.class)
end
def exploit
admin_path = 'administrator/index.php'
proto = 'http'
if datastore['SSL'] == true
proto ='https'
end
url = "#{proto}:/" + normalize_uri("#{datastore['RHOST']}//#{datastore['TARGETURI']}//#{admin_path}")
print_status("GET url: #{url}")
sess = establish_session(url, datastore['USERNAME'], datastore['PASSWORD'])
if not sess
fail_with('Cannot establish session')
return nil
end
print_good("Logged as: #{datastore['USERNAME']}, Cookie: #{sess}")
end
end