class Subdomain_enum

Attributes

cache_file[RW]
max_thread[RW]
out[RW]
show_cache[RW]
show_cache_without_d[RW]
show_new[RW]
target[RW]
timeout[RW]
verbose[RW]
wordlist[RW]

Public Class Methods

new() click to toggle source
# File lib/m4dh4v45b1n/enum-subdomain.rb, line 50
def initialize
  @timeout = TIME_OUT
  @max_thread = MAX_THREAD
  @wordlist = WORDLIST
  @verbose = false
  @outb=""
  @show_cache = false
  @show_new = true
  @show_cache_without_d = true
end

Public Instance Methods

brut() click to toggle source
# File lib/m4dh4v45b1n/enum-subdomain.rb, line 138
def brut
  already_have = check_cache_domain
  if @show_cache
    exit
  end
  if Resolv.getaddresses(@target).length == 0
    print "enum-subdomain.rb: No Dns records found for #{@target}.\nDo you wana exit ? "
    tmp = STDIN.gets.chomp
    if ["yes", 'y'].include? tmp
      print "\e[1A#{" "*60}\r"
      exit
    end
    print "\e[1A#{" "*60}\r"
  end
  if further_checkup
    tmp = STDIN.gets.chomp
    if ["yes", 'y'].include? tmp
      print "\e[1A#{" "*60}\r"
      exit
    end
    print "\e[1A#{" "*60}\r"
  end
  if !CACHE.nil?
    @cache_file = File.open(CACHE+"/#{@target}.cache", "a")
  end
  if @out
    @out = File.open(@out, "w")
  end
  wordlist_ = File.open(@wordlist).readlines.uniq
  if @show_cache_without_d
    already_have.map do |a|
      wordlist_.delete(a)
    end
  end
  wordlist_.map do |line|
    Thread::new do
      if !already_have.include? line.chomp
        print_domain(
          [line.chomp, @target.strip].join(".")
        )
      end
    end
    sleep 0.03
    while Thread::list.length > @max_thread;end
  end
  while Thread::list.length > 1;end
  if Thread::list.length == 1
    sleep 0.6
  end
end
check_cache_domain() click to toggle source
# File lib/m4dh4v45b1n/enum-subdomain.rb, line 101
def check_cache_domain
  if !CACHE.nil?
    if !File.file? CACHE+"/#{@target}.cache"
      File.open(CACHE+"/#{@target}.cache", "a")
    else
      File.open(CACHE+"/#{@target}.cache") do |f|
        data_ = f.read.split("\x7")
        data_ = data_.uniq
        data_.map do |s|
          if @show_new
            if @show_cache
              $stdout.print s+target+"\n"
            else
              puts "\e[32m#{s+@target}\e[0m"
            end
          end
        end
        File.open(CACHE+"/#{@target}.cache", "w") do |f2|
          f2.write(data_.join("\x7"))
        end
        return data_.map {|a| a[0,a.length-1] }
      end
    end
  end
  return []
end
further_checkup() click to toggle source
# File lib/m4dh4v45b1n/enum-subdomain.rb, line 127
def further_checkup
  begin
    req = Net::HTTP::get_response(URI("http://#{@target}"), {"User-Agent":rand_user_agent})
    if req.header["Location"][0,28] == "https://www.hugedomains.com/"
      print "enum-subdomain.rb: It redirect to #{req.header['Location'][0,28]}.The domain is under hugedomains for sale.\nDo you wanna exit ? "
      return true
    end
  rescue => e
  end
  return false
end
get_domain(domain) click to toggle source
# File lib/m4dh4v45b1n/enum-subdomain.rb, line 69
def get_domain(domain)
  NAME_SERVERS.keys.shuffle.map do |dns|
    begin
      Timeout::timeout(@timeout) do
        addrs = Resolv::new(
          loader(NAME_SERVERS[dns])
        ).getaddresses(domain)
        if addrs.length > 0
          return addrs
        end
      end  
    rescue Timeout::Error => e
    end
  end
  return []
end
loader(list) click to toggle source
# File lib/m4dh4v45b1n/enum-subdomain.rb, line 60
def loader(list)
  return Resolv::DefaultResolver.replace_resolvers([
    Resolv::Hosts.new,
    Resolv::DNS.new(
      nameserver: list,
      ndots: 1
    )
  ])
end
print_domain(domain) click to toggle source