Class: Snackhack2::Subdomains

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/subdomains.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wordlist: nil) ⇒ Subdomains

Returns a new instance of Subdomains.



9
10
11
12
# File 'lib/snackhack2/subdomains.rb', line 9

def initialize(wordlist: nil)
  @site     = site
  @wordlist = wordlist
end

Instance Attribute Details

#site ⇒ Object

Returns the value of attribute site.



8
9
10
# File 'lib/snackhack2/subdomains.rb', line 8

def site
  @site
end

Instance Method Details

#brute ⇒ Object



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
# File 'lib/snackhack2/subdomains.rb', line 25

def brute
  found = ''
  # loops through each of the subdomains and adds it to
  # the site which checks if it returns a `200` status code or `300` status code
  unless @site.nil?
    @site = @site.gsub("https://", "")
  end
  File.readlines(wordlist).each do |l|
    s = "#{l.strip}.#{@site}"
    p File.join('https://', s)
    begin
      g = Snackhack2.get(File.join('https://', s))
      if g.code == 200
        found += "#{s}\n"
      elsif g.code == 300
        found += "#{s}\n"
      else
        puts "HTTP Code: #{g.code}"
      end
    rescue StandardError => e
      puts e
    end
  end
  Snackhack2.file_save(@site, 'subdomain_brute', found)
end

#resolv(sd) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/snackhack2/subdomains.rb', line 51

def resolv(sd)
  # NOTE: this is really slow & multi thread does not work
  # due to resolv
  active = []
  subdomains = []
  Resolv::DNS.open do |dns|
    ress = dns.getresources "#{sd}.#{@site}", Resolv::DNS::Resource::IN::A
    unless ress.map(&:address).empty?
      address = ress.map(&:address)
      unless active.include?(address)
        active << address
        subdomains << "#{sd}.#{@site}" unless subdomains.include?(sd)
      end
    end
  end
  host = URI.parse(@site).host
  File.open("#{host}_subdomains.txt", 'w+') { |file| file.write(subdomains.join("\n")) }
  File.open("#{host}_ips.txt", 'w+') { |file| file.write(active.join("\n")) }
end

#run ⇒ Object



19
20
21
22
23
# File 'lib/snackhack2/subdomains.rb', line 19

def run
  File.readlines(wordlist).each do |sd|
    resolv(sd)
  end
end

#wordlist ⇒ Object



14
15
16
17
# File 'lib/snackhack2/subdomains.rb', line 14

def wordlist
  # gets the location of the subdomains list
  File.join(__dir__, 'lists', 'subdomains.txt')
end