Skip to content

Commit 2189c6d

Browse files
committed
Pass timeouts to clients and correctly patch timeouts
Timeouts are correctly passed through to the client instances from the handlers. The cilent also passes those values through to the RDI code so that the binaries are correctly patched.
1 parent 9f1e035 commit 2189c6d

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

lib/msf/core/handler/bind_tcp.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,21 @@ def start_handler
141141
# Increment the has connection counter
142142
self.pending_connections += 1
143143

144+
# Timeout and datastore options need to be passed through to the client
145+
opts = {
146+
:datastore => datastore,
147+
:expiration => datastore['SessionExpirationTimeout'].to_i,
148+
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
149+
:retry_total => datastore['SessionRetryTotal'].to_i,
150+
:retry_wait => datastore['SessionRetryWait'].to_i
151+
}
152+
144153
# Start a new thread and pass the client connection
145154
# as the input and output pipe. Client's are expected
146155
# to implement the Stream interface.
147156
conn_threads << framework.threads.spawn("BindTcpHandlerSession", false, client) { |client_copy|
148157
begin
149-
handle_connection(wrap_aes_socket(client_copy), { datastore: datastore })
158+
handle_connection(wrap_aes_socket(client_copy), opts)
150159
rescue
151160
elog("Exception raised from BindTcp.handle_connection: #{$!}")
152161
end

lib/msf/core/handler/reverse_tcp.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,21 @@ def start_handler
169169
break
170170
end
171171

172+
# Timeout and datastore options need to be passed through to the client
173+
opts = {
174+
:datastore => datastore,
175+
:expiration => datastore['SessionExpirationTimeout'].to_i,
176+
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
177+
:retry_total => datastore['SessionRetryTotal'].to_i,
178+
:retry_wait => datastore['SessionRetryWait'].to_i
179+
}
180+
172181
if datastore['ReverseListenerThreaded']
173182
self.conn_threads << framework.threads.spawn("ReverseTcpHandlerSession-#{local_port}-#{client.peerhost}", false, client) { |client_copy|
174-
handle_connection(wrap_aes_socket(client_copy), { datastore: datastore })
183+
handle_connection(wrap_aes_socket(client_copy), opts)
175184
}
176185
else
177-
handle_connection(wrap_aes_socket(client), { datastore: datastore })
186+
handle_connection(wrap_aes_socket(client), opts)
178187
end
179188
rescue ::Exception
180189
elog("Exception raised from handle_connection: #{$!.class}: #{$!}\n\n#{$@.join("\n")}")

lib/rex/post/meterpreter/client_core.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ def generate_windows_stub(process)
639639
end
640640
migrate_stager.datastore['DLL'] = dll
641641

642+
# Pass the timeout information to the RDI loader so that it correctly
643+
# patches the timeouts into the binary.
644+
migrate_stager.datastore['SessionExpirationTimeout'] = self.client.expiration
645+
migrate_stager.datastore['SessionCommunicationTimeout'] = self.client.comm_timeout
646+
migrate_stager.datastore['SessionRetryTotal'] = self.client.retry_total
647+
migrate_stager.datastore['SessionRetryWait'] = self.client.retry_wait
648+
642649
blob = migrate_stager.stage_payload
643650

644651
if client.passive_service
@@ -656,14 +663,6 @@ def generate_windows_stub(process)
656663
:proxy_type => client.exploit_datastore['PayloadProxyType'],
657664
:proxy_user => client.exploit_datastore['PayloadProxyUser'],
658665
:proxy_pass => client.exploit_datastore['PayloadProxyPass'])
659-
# This should be done by the reflective loader payloads
660-
#else
661-
# # Just patch the timeouts, which are consistent on each of the payloads.
662-
# Rex::Payloads::Meterpreter::Patch.patch_timeouts!(blob,
663-
# :expiration => self.client.expiration,
664-
# :comm_timeout => self.client.comm_timeout,
665-
# :retry_total => self.client.retry_total,
666-
# :retry_wait => self.client.retry_wait)
667666
end
668667

669668
blob

0 commit comments

Comments
 (0)