Class: DCDetector::App

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

Overview

DCDetector main class

Instance Method Summary collapse

Constructor Details

#initialize(ad_domain, dns_opts = nil) ⇒ App

Create the DCDetector object.

Examples:

dcd = DCDetector::App.new('spookysec.local', nameserver: ['10.10.197.59'])
dcd = DCDetector::App.new('za.tryhackme.com', nameserver: ['10.200.28.101'])

Parameters:

Options Hash (dns_opts):

  • :nameserver (Array|String)

    the DNS server to contact



20
21
22
23
# File 'lib/dcdetector.rb', line 20

def initialize(ad_domain, dns_opts = nil)
  @ad_domain = ad_domain
  @dns_opts = dns_opts
end

Instance Method Details

#dc_fqdnArray

Get DC(s) FQDN

Examples:

dcd.dc_fqdn
# => ["THMDC.za.tryhackme.com"]

Returns:

  • (Array)

    the list of FQDN of all DCs

See Also:



31
32
33
34
35
36
37
38
39
40
# File 'lib/dcdetector.rb', line 31

def dc_fqdn
  Resolv::DNS.open(@dns_opts) do |dns|
    # _kerberos._tcp, _kpasswd._tcp, _ldap._tcp works too but are not MS only
    # _kerberos._tcp.dc._msdcs
    # _ldap._tcp.pdc._msdcs, _gc._tcp
    # _udp variants
    ress = dns.getresources "_ldap._tcp.dc._msdcs.#{@ad_domain}", Resolv::DNS::Resource::IN::ANY
    ress.map { |x| x.target.to_s }
  end
end

#dc_ipArray

Get DC(s) IP address

Examples:

dcd.dc_ip
# => ["10.10.10.101", "10.200.28.101"]

Returns:

  • (Array)

    the list of IP address of all DCs



56
57
58
59
60
61
# File 'lib/dcdetector.rb', line 56

def dc_ip
  Resolv::DNS.open(@dns_opts) do |dns|
    ress = dns.getresources "gc._msdcs.#{@ad_domain}", Resolv::DNS::Resource::IN::A
    ress.map { |x| x.address.to_s }
  end
end

#dc_nameArray

Get DC(s) computer name

Examples:

dcd.dc_name
# => ["THMDC"]

Returns:

  • (Array)

    the list of computer name of all DCs



47
48
49
# File 'lib/dcdetector.rb', line 47

def dc_name
  dc_fqdn.map { |x| x[...-@ad_domain.size - 1] }
end