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/gather/enum_dns.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456class MetasploitModule < Msf::Auxiliary7include Msf::Exploit::Remote::DNS::Enumeration89def initialize(info = {})10super(update_info(info,11'Name' => 'DNS Record Scanner and Enumerator',12'Description' => %q(13This module can be used to gather information about a domain from a14given DNS server by performing various DNS queries such as zone15transfers, reverse lookups, SRV record brute forcing, and other techniques.16),17'Author' => [18'Carlos Perez <carlos_perez[at]darkoperator.com>',19'Nixawk'20],21'License' => MSF_LICENSE,22'References' => [23['CVE', '1999-0532'],24['OSVDB', '492']25]))2627register_options(28[29OptString.new('DOMAIN', [true, 'The target domain']),30OptBool.new('ENUM_AXFR', [true, 'Initiate a zone transfer against each NS record', true]),31OptBool.new('ENUM_BRT', [true, 'Brute force subdomains and hostnames via the supplied wordlist', false]),32OptBool.new('ENUM_A', [true, 'Enumerate DNS A record', true]),33OptBool.new('ENUM_CNAME', [true, 'Enumerate DNS CNAME record', true]),34OptBool.new('ENUM_MX', [true, 'Enumerate DNS MX record', true]),35OptBool.new('ENUM_NS', [true, 'Enumerate DNS NS record', true]),36OptBool.new('ENUM_SOA', [true, 'Enumerate DNS SOA record', true]),37OptBool.new('ENUM_TXT', [true, 'Enumerate DNS TXT record', true]),38OptBool.new('ENUM_RVL', [ true, 'Reverse lookup a range of IP addresses', false]),39OptBool.new('ENUM_TLD', [true, 'Perform a TLD expansion by replacing the TLD with the IANA TLD list', false]),40OptBool.new('ENUM_SRV', [true, 'Enumerate the most common SRV records', true]),41OptBool.new('STOP_WLDCRD', [true, 'Stops bruteforce enumeration if wildcard resolution is detected', false]),42OptAddressRange.new('IPRANGE', [false, "The target address range or CIDR identifier"]),43OptInt.new('THREADS', [false, 'Threads for ENUM_BRT', 1]),44OptPath.new('WORDLIST', [false, 'Wordlist of subdomains', ::File.join(Msf::Config.data_directory, 'wordlists', 'namelist.txt')])45])4647register_advanced_options(48[49OptInt.new('TIMEOUT', [false, 'DNS TIMEOUT', 8]),50OptInt.new('RETRY', [false, 'Number of times to try to resolve a record if no response is received', 2]),51OptInt.new('RETRY_INTERVAL', [false, 'Number of seconds to wait before doing a retry', 2]),52OptBool.new('TCP_DNS', [false, 'Run queries over TCP', false])53])54deregister_options('DnsClientUdpTimeout', 'DnsClientRetry', 'DnsClientRetryInterval', 'DnsClientTcpDns')55end5657def run58datastore['DnsClientUdpTimeout'] = datastore['TIMEOUT']59datastore['DnsClientRetry'] = datastore['RETRY']60datastore['DnsClientRetryInterval'] = datastore['RETRY_INTERVAL']61datastore['DnsClientTcpDns'] = datastore['TCP_DNS']6263begin64setup_resolver65rescue RuntimeError => e66fail_with(Failure::BadConfig, "Resolver setup failed - exception: #{e}")67end6869domain = datastore['DOMAIN']70is_wildcard = dns_wildcard_enabled?(domain)7172# All exceptions should be being handled by the library73# but catching here as well, just in case.74begin75dns_axfr(domain) if datastore['ENUM_AXFR']76rescue => e77print_error("AXFR failed: #{e}")78end79dns_get_a(domain) if datastore['ENUM_A']80dns_get_cname(domain) if datastore['ENUM_CNAME']81dns_get_ns(domain) if datastore['ENUM_NS']82dns_get_mx(domain) if datastore['ENUM_MX']83dns_get_soa(domain) if datastore['ENUM_SOA']84dns_get_txt(domain) if datastore['ENUM_TXT']85dns_get_tld(domain) if datastore['ENUM_TLD']86dns_get_srv(domain) if datastore['ENUM_SRV']87threads = datastore['THREADS']88dns_reverse(datastore['IPRANGE'], threads) if datastore['ENUM_RVL']8990return unless datastore['ENUM_BRT']91if is_wildcard92dns_bruteforce(domain, datastore['WORDLIST'], threads) unless datastore['STOP_WLDCRD']93else94dns_bruteforce(domain, datastore['WORDLIST'], threads)95end96end9798def save_note(target, type, records)99data = { 'target' => target, 'records' => records }100report_note(host: target, sname: 'dns', type: type, data: data, update: :unique_data)101end102end103104105