Path: blob/master/modules/auxiliary/gather/enum_dns.rb
21537 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::DNS::Enumeration78def initialize(info = {})9super(10update_info(11info,12'Name' => 'DNS Record Scanner and Enumerator',13'Description' => %q{14This module can be used to gather information about a domain from a15given DNS server by performing various DNS queries such as zone16transfers, reverse lookups, SRV record brute forcing, and other techniques.17},18'Author' => [19'Carlos Perez <carlos_perez[at]darkoperator.com>',20'Nixawk'21],22'License' => MSF_LICENSE,23'References' => [24['CVE', '1999-0532'],25['OSVDB', '492']26],27'Notes' => {28'Reliability' => UNKNOWN_RELIABILITY,29'Stability' => UNKNOWN_STABILITY,30'SideEffects' => UNKNOWN_SIDE_EFFECTS31}32)33)3435register_options(36[37OptString.new('DOMAIN', [true, 'The target domain']),38OptBool.new('ENUM_AXFR', [true, 'Initiate a zone transfer against each NS record', true]),39OptBool.new('ENUM_BRT', [true, 'Brute force subdomains and hostnames via the supplied wordlist', false]),40OptBool.new('ENUM_A', [true, 'Enumerate DNS A record', true]),41OptBool.new('ENUM_CNAME', [true, 'Enumerate DNS CNAME record', true]),42OptBool.new('ENUM_MX', [true, 'Enumerate DNS MX record', true]),43OptBool.new('ENUM_NS', [true, 'Enumerate DNS NS record', true]),44OptBool.new('ENUM_SOA', [true, 'Enumerate DNS SOA record', true]),45OptBool.new('ENUM_TXT', [true, 'Enumerate DNS TXT record', true]),46OptBool.new('ENUM_RVL', [ true, 'Reverse lookup a range of IP addresses', false]),47OptBool.new('ENUM_TLD', [true, 'Perform a TLD expansion by replacing the TLD with the IANA TLD list', false]),48OptBool.new('ENUM_SRV', [true, 'Enumerate the most common SRV records', true]),49OptBool.new('STOP_WLDCRD', [true, 'Stops bruteforce enumeration if wildcard resolution is detected', false]),50OptAddressRange.new('IPRANGE', [false, "The target address range or CIDR identifier"]),51OptInt.new('THREADS', [false, 'Threads for ENUM_BRT', 1]),52OptPath.new('WORDLIST', [false, 'Wordlist of subdomains', ::File.join(Msf::Config.data_directory, 'wordlists', 'namelist.txt')])53]54)5556register_advanced_options(57[58OptInt.new('TIMEOUT', [false, 'DNS TIMEOUT', 8]),59OptInt.new('RETRY', [false, 'Number of times to try to resolve a record if no response is received', 2]),60OptInt.new('RETRY_INTERVAL', [false, 'Number of seconds to wait before doing a retry', 2]),61OptBool.new('TCP_DNS', [false, 'Run queries over TCP', false])62]63)64deregister_options('DnsClientUdpTimeout', 'DnsClientRetry', 'DnsClientRetryInterval', 'DnsClientTcpDns')65end6667def run68datastore['DnsClientUdpTimeout'] = datastore['TIMEOUT']69datastore['DnsClientRetry'] = datastore['RETRY']70datastore['DnsClientRetryInterval'] = datastore['RETRY_INTERVAL']71datastore['DnsClientTcpDns'] = datastore['TCP_DNS']7273begin74setup_resolver75rescue RuntimeError => e76fail_with(Failure::BadConfig, "Resolver setup failed - exception: #{e}")77end7879domain = datastore['DOMAIN']80is_wildcard = dns_wildcard_enabled?(domain)8182# All exceptions should be being handled by the library83# but catching here as well, just in case.84begin85dns_axfr(domain) if datastore['ENUM_AXFR']86rescue => e87print_error("AXFR failed: #{e}")88end89dns_get_a(domain) if datastore['ENUM_A']90dns_get_cname(domain) if datastore['ENUM_CNAME']91dns_get_ns(domain) if datastore['ENUM_NS']92dns_get_mx(domain) if datastore['ENUM_MX']93dns_get_soa(domain) if datastore['ENUM_SOA']94dns_get_txt(domain) if datastore['ENUM_TXT']95dns_get_tld(domain) if datastore['ENUM_TLD']96dns_get_srv(domain) if datastore['ENUM_SRV']97threads = datastore['THREADS']98dns_reverse(datastore['IPRANGE'], threads) if datastore['ENUM_RVL']99100return unless datastore['ENUM_BRT']101102if is_wildcard103dns_bruteforce(domain, datastore['WORDLIST'], threads) unless datastore['STOP_WLDCRD']104else105dns_bruteforce(domain, datastore['WORDLIST'], threads)106end107end108109def save_note(target, type, records)110data = { 'target' => target, 'records' => records }111report_note(host: target, sname: 'dns', type: type, data: data, update: :unique_data)112end113end114115116