Skip to content

Commit 7442655

Browse files
committed
Override to TCP when encountering UDP-unfriendly comms
1 parent 21f3335 commit 7442655

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

lib/msf/base/sessions/meterpreter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ def create(param)
593593
sock
594594
end
595595

596+
def supports_udp?
597+
true
598+
end
599+
596600
#
597601
# Get a string representation of the current session platform
598602
#

lib/msf/base/sessions/ssh_command_shell_bind.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def create(params)
287287
sock
288288
end
289289

290+
def supports_udp?
291+
false
292+
end
293+
290294
def create_server_channel(params)
291295
msf_channel = nil
292296
mutex = Mutex.new

lib/msf/core/session/comm.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ module Comm
2222
def create(param)
2323
raise NotImplementedError
2424
end
25+
26+
#
27+
# Does the Comm support sending UDP messages?
28+
#
29+
def supports_udp?
30+
raise NotImplementedError
31+
end
2532
end
2633

2734
end

lib/rex/proto/dns/resolver.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def send(argument, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
159159
if use_tcp? or !(proxies.nil? or proxies.empty?) # User requested TCP
160160
@logger.info "Sending #{packet_size} bytes using TCP due to tcp flag"
161161
method = :send_tcp
162+
elsif !supports_udp?(nameservers)
163+
@logger.info "Sending #{packet_size} bytes using TCP due to the presence of a non-UDP-compatible comm channel"
164+
method = :send_tcp
162165
else # Finally use UDP
163166
@logger.info "Sending #{packet_size} bytes using UDP"
164167
method = :send_udp unless method == :send_tcp
@@ -334,7 +337,7 @@ def send_udp(packet,packet_data)
334337
socket = Rex::Socket::Udp.create(config)
335338
rescue
336339
@logger.warn "UDP Socket could not be established to #{ns}:#{@config[:port]}"
337-
return nil
340+
throw :next_ds
338341
end
339342
@logger.info "Contacting nameserver #{ns} port #{@config[:port]}"
340343
#socket.sendto(packet_data, ns.to_s, @config[:port].to_i, 0)
@@ -403,6 +406,17 @@ def query(name, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
403406
return send(name,type,cls)
404407

405408
end
409+
410+
private
411+
412+
def supports_udp?(nameserver_results)
413+
nameserver_results.each do |nameserver, socket_options|
414+
comm = socket_options.fetch('Comm') { @config.fetch(:comm) { Rex::Socket::SwitchBoard.best_comm(ns) }}
415+
next if comm.nil?
416+
return false unless comm.supports_udp?
417+
end
418+
true
419+
end
406420
end # Resolver
407421

408422
end

0 commit comments

Comments
 (0)