Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/bnat/bnat_scan.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Auxiliary::Scanner7include Msf::Exploit::Capture89def initialize10super(11'Name' => 'BNAT Scanner',12'Description' => %q{13This module is a scanner which can detect Broken NAT (network address translation)14implementations, which could result in an inability to reach ports on remote15machines. Typically, these ports will appear in nmap scans as 'filtered'/'closed'.16},17'Author' =>18[19'bannedit',20'Jonathan Claudius <jclaudius[at]trustwave.com>',21],22'License' => MSF_LICENSE,23'References' =>24[25[ 'URL', 'https://github.com/claudijd/bnat'],26[ 'URL', 'http://www.slideshare.net/claudijd/dc-skytalk-bnat-hijacking-repairing-broken-communication-channels']27]28)2930register_options(31[32OptString.new('PORTS', [true, "Ports to scan (e.g. 22-25,80,110-900)", "21,22,23,80,443"]),33OptString.new('INTERFACE', [true, "The name of the interface", "eth0"]),34OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500])35])3637deregister_options('FILTER','PCAPFILE','SNAPLEN')3839end4041def probe_reply(pcap, to)42reply = nil43begin44Timeout.timeout(to) do45pcap.each do |r|46pkt = PacketFu::Packet.parse(r)47next unless pkt.is_tcp?48reply = pkt49break50end51end52rescue Timeout::Error53end54return reply55end5657def generate_probe(ip)58ftypes = %w{windows, linux, freebsd}59@flavor = ftypes[rand(ftypes.length)]60config = PacketFu::Utils.whoami?(:iface => datastore['INTERFACE'])61p = PacketFu::TCPPacket.new(:config => config)62p.ip_daddr = ip63p.tcp_flags.syn = 164return p65end6667def run_host(ip)68open_pcap6970to = (datastore['TIMEOUT'] || 500).to_f / 1000.07172p = generate_probe(ip)73pcap = self.capture7475ports = Rex::Socket.portspec_crack(datastore['PORTS'])7677if ports.empty?78raise Msf::OptionValidateError.new(['PORTS'])79end8081ports.each_with_index do |port,i|82p.tcp_dst = port83p.tcp_src = rand(64511)+102484p.tcp_seq = rand(64511)+102485p.recalc8687ackbpf = "tcp [8:4] == 0x#{(p.tcp_seq + 1).to_s(16)}"88pcap.setfilter("tcp and tcp[13] == 18 and not host #{ip} and src port #{p.tcp_dst} and dst port #{p.tcp_src} and #{ackbpf}")89break unless capture_sendto(p, ip)90reply = probe_reply(pcap, to)91next if reply.nil?9293print_status("[BNAT RESPONSE] Requested IP: #{ip} Responding IP: #{reply.ip_saddr} Port: #{reply.tcp_src}")94end9596close_pcap97end98end99100101