Skip to content

Commit

Permalink
Override to TCP when encountering UDP-unfriendly comms
Browse files Browse the repository at this point in the history
  • Loading branch information
smashery committed Nov 7, 2023
1 parent 21f3335 commit 7442655
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/msf/base/sessions/meterpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@ def create(param)
sock
end

def supports_udp?
true
end

#
# Get a string representation of the current session platform
#
Expand Down
4 changes: 4 additions & 0 deletions lib/msf/base/sessions/ssh_command_shell_bind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ def create(params)
sock
end

def supports_udp?
false
end

def create_server_channel(params)
msf_channel = nil
mutex = Mutex.new
Expand Down
7 changes: 7 additions & 0 deletions lib/msf/core/session/comm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ module Comm
def create(param)
raise NotImplementedError
end

#
# Does the Comm support sending UDP messages?
#
def supports_udp?
raise NotImplementedError
end
end

end
Expand Down
16 changes: 15 additions & 1 deletion lib/rex/proto/dns/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def send(argument, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
if use_tcp? or !(proxies.nil? or proxies.empty?) # User requested TCP
@logger.info "Sending #{packet_size} bytes using TCP due to tcp flag"
method = :send_tcp
elsif !supports_udp?(nameservers)
@logger.info "Sending #{packet_size} bytes using TCP due to the presence of a non-UDP-compatible comm channel"
method = :send_tcp
else # Finally use UDP
@logger.info "Sending #{packet_size} bytes using UDP"
method = :send_udp unless method == :send_tcp
Expand Down Expand Up @@ -334,7 +337,7 @@ def send_udp(packet,packet_data)
socket = Rex::Socket::Udp.create(config)
rescue
@logger.warn "UDP Socket could not be established to #{ns}:#{@config[:port]}"
return nil
throw :next_ds
end
@logger.info "Contacting nameserver #{ns} port #{@config[:port]}"
#socket.sendto(packet_data, ns.to_s, @config[:port].to_i, 0)
Expand Down Expand Up @@ -403,6 +406,17 @@ def query(name, type = Dnsruby::Types::A, cls = Dnsruby::Classes::IN)
return send(name,type,cls)

end

private

def supports_udp?(nameserver_results)
nameserver_results.each do |nameserver, socket_options|
comm = socket_options.fetch('Comm') { @config.fetch(:comm) { Rex::Socket::SwitchBoard.best_comm(ns) }}
next if comm.nil?
return false unless comm.supports_udp?
end
true
end
end # Resolver

end
Expand Down

0 comments on commit 7442655

Please sign in to comment.