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/post/multi/gather/dns_bruteforce.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Multi Gather DNS Forward Lookup Bruteforce',12'Description' => %q{13Brute force subdomains and hostnames via wordlist.14},15'License' => MSF_LICENSE,16'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],17'Platform' => %w[bsd linux osx solaris win],18'SessionTypes' => [ 'meterpreter', 'shell' ]19)20)21register_options(22[2324OptString.new('DOMAIN', [true, 'Domain to do a forward lookup bruteforce against.']),25OptPath.new('NAMELIST', [26true, 'List of hostnames or subdomains to use.',27::File.join(Msf::Config.data_directory, 'wordlists', 'namelist.txt')28])2930]31)32end3334# Run Method for when run command is issued35def run36domain = datastore['DOMAIN']37hostlst = datastore['NAMELIST']38a = []3940print_status("Performing DNS Forward Lookup Bruteforce for Domain #{domain}")4142name_list = []43if ::File.exist?(hostlst)44::File.open(hostlst).each do |n|45name_list << n46end47end4849case session.platform50when 'windows'51cmd = 'nslookup'52when 'solaris'53cmd = '/usr/sbin/host '54else55cmd = '/usr/bin/host '56end5758while !name_list.nil? && !name_list.empty?591.upto session.max_threads do60a << framework.threads.spawn("Module(#{refname})", false, name_list.shift) do |n|61next if n.nil?6263vprint_status("Trying #{n.strip}.#{domain}")64r = cmd_exec(cmd, "#{n.strip}.#{domain}")6566case session.platform67when 'windows'68proccess_win(r, "#{n.strip}.#{domain}")69else70process_nix(r, "#{n.strip}.#{domain}")71end72end73a.map(&:join)74end75end76end7778# Process the data returned by nslookup79def proccess_win(data, ns_opt)80if data =~ /Name/81# Remove unnecessary data and get the section with the addresses82returned_data = data.split(/Name:/)[1]83# check each element of the array to see if they are IP84returned_data.gsub(/\r\n\t |\r\n|Aliases:|Addresses:/, ' ').split(' ').each do |e|85if Rex::Socket.dotted_ip?(e)86print_good("#{ns_opt} #{e}")87report_host(host: e, name: ns_opt.strip)88end89end90end91end9293# Process the data returned by the host command94def process_nix(r, ns_opt)95r.each_line do |l|96data = l.scan(/(\S*) has address (\S*)$/)97next if data.empty?9899data.each do |e|100print_good("#{ns_opt} #{e[1]}")101report_host(host: e[1], name: ns_opt.strip)102end103end104end105end106107108