Skip to content

Commit f5768e7

Browse files
committed
gate session reported when using bind udp
While this method here is somewhat noisy on the network it eliminates a poor user experience when the handler is started but the payload is not yet running on the target. When a target is sent a udp packet and it is not rejected push down an initial "echo syn" command that will respond with output. This allows framework to be aware that the payload is what is running on the server port instead of assuming a non-existent target is a valid session.
1 parent d56111a commit f5768e7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/msf/core/handler/bind_udp.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def start_handler
8181
# Maximum number of seconds to run the handler
8282
ctimeout = 150
8383

84+
# Maximum number of seconds to await initial udp response
85+
rtimeout = 5
86+
8487
if (exploit_config and exploit_config['active_timeout'])
8588
ctimeout = exploit_config['active_timeout'].to_i
8689
end
@@ -131,7 +134,21 @@ def start_handler
131134
end
132135

133136
client.extend(Rex::IO::Stream)
134-
break if client
137+
begin
138+
# If a connection was acknowledged, request a basic response before promoting as a session
139+
if client
140+
message = 'syn'
141+
client.write("echo #{message}\n")
142+
response = client.get(rtimeout)
143+
break if response && response.include?(message)
144+
client.close()
145+
client = nil
146+
end
147+
rescue Errno::ECONNREFUSED
148+
client.close()
149+
client = nil
150+
wlog("Connection failed in udp bind handler continuing attempts: #{$!.class} #{$!}")
151+
end
135152

136153
# Wait a second before trying again
137154
Rex::ThreadSafe.sleep(0.5)

0 commit comments

Comments
 (0)