Class: Dert::BRT

Inherits:
Object
  • Object
show all
Defined in:
lib/dert/methods/brt.rb

Class Method Summary collapse

Class Method Details

.query(domain, wordlist, dns_type) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dert/methods/brt.rb', line 6

def self.query(domain, wordlist, dns_type)
  results = []
  default_ip = ''
  wildcard = false

  # Check if domain has wildcard DNS enabled.
  if self.wildcard?(domain)
    wildcard = true
    rendsub = rand(10000).to_s
    ret = @res.query("#{rendsub}.#{domain}", dns_type)
    default_ip = ret.answer[0].address.to_s
  end

  wordlist.each do |a|

    # A
    begin
      Timeout::timeout(5) {
        ret = @res.query("#{a}.#{domain}", dns_type)
        ret.answer.each do |x|
          unless x.address.to_s == default_ip
            results << {
                address: x.address.to_s,
                type: x.type.to_s,
                hostname: x.name.to_s,
                ttl: x.ttl.to_s,
                klass: x.klass.to_s
            }
          end
        end
      }
    rescue => e
      #
    end
  end

  if wildcard
    results << {
        address: default_ip,
        type: 'A',
        hostname: "*.#{domain}"
    }
  end

  results
end

.wildcard?(domain) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dert/methods/brt.rb', line 53

def self.wildcard?(domain)
  rendsub = rand(10000).to_s
  # A
  begin
    ret = @res.query("#{rendsub}.#{domain}", Dnsruby::Types.A)
  rescue
    return false
  end

  if ret.answer.length != 0
    true
  else
    false
  end
end