dcdetector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 185e37f0c3bf087e6f16b120cb14cba36efecf6e22592c3324ce1dfde731c54c
4
+ data.tar.gz: 38f62817debd7e11c1515de87e618e218d4689886783fe923b140c970df08830
5
+ SHA512:
6
+ metadata.gz: 75496810b4479c2cc3963b486ecfb7e2e337a9179d2e70570194a6a914347b387aca1c5360f005f0e525bca81d0b29bb1298328f034d35134843552e5c5545d2
7
+ data.tar.gz: a7ea224de15c6f84efb802e6b5b87a52a5aa368061e327b141ed45816445ac2cf2e5967e4af64d47bff3f24f403ca8d87e6f67a55018d07397959bd691e46808
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Alexandre ZANNI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/bin/dcd ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Ruby internal
5
+ # Project internal
6
+ require 'dcdetector'
7
+ require 'dcdetector/cli'
8
+ # External
9
+
10
+ DCDetector::CLI
data/bin/dcdetector ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Ruby internal
5
+ # Project internal
6
+ require 'dcdetector'
7
+ require 'dcdetector/cli'
8
+ # External
9
+
10
+ DCDetector::CLI
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby internal
4
+ # Project internal
5
+ # External
6
+ require 'docopt'
7
+ require 'paint'
8
+
9
+ module DCDetector
10
+ # module use for the CLI binary only, not required by teh library
11
+ module CLI
12
+ doc = <<~DOCOPT
13
+ DCDetector v#{DCDetector::VERSION}
14
+
15
+ Usage:
16
+ dcdetector -d <domain.tld> [-s <ip_address>] [--no-color --debug]
17
+ dcdetector -h | --help
18
+ dcdetector --version
19
+
20
+ Options:
21
+ -d <domain.tld>, --domain <domain.tld> Active Directory domain
22
+ -s <ip_address>, --nameserver <ip_address> The IP address of the domain DNS server. If not provided use your system DNS.
23
+ --no-color Disable colorized output
24
+ --debug Display arguments
25
+ -h, --help Show this screen
26
+ --version Show version
27
+ DOCOPT
28
+
29
+ begin
30
+ args = Docopt.docopt(doc, version: DCDetector::VERSION)
31
+ Paint.mode = 0 if args['--no-color']
32
+ pp args if args['--debug']
33
+ if args['--domain']
34
+ dns_opts = args['--nameserver'].nil? ? nil : { nameserver: [args['--nameserver']] }
35
+ dcd = DCDetector::App.new(args['--domain'], dns_opts)
36
+ puts Paint['DC(s) name', :underline, :bold, 'dark turquoise']
37
+ dcd.dc_name.each do |name|
38
+ puts Paint["🔍 #{name}"]
39
+ end
40
+ puts Paint["\nDC(s) FQDN", :underline, :bold, 'cyan']
41
+ dcd.dc_fqdn.each do |fqdn|
42
+ puts Paint["🔍 #{fqdn}"]
43
+ end
44
+ puts Paint["\nDC(s) IP address", :underline, :bold, 'aquamarine']
45
+ dcd.dc_ip.each do |ip|
46
+ puts Paint["🔍 #{ip}"]
47
+ end
48
+ end
49
+ rescue Docopt::Exit => e
50
+ puts e.message
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DCDetector
4
+ # Version of DCDetector library and app
5
+ VERSION = '0.0.1'
6
+ end
data/lib/dcdetector.rb ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby internal
4
+ require 'resolv'
5
+ # Project internal
6
+ require 'dcdetector/version'
7
+ # External
8
+
9
+ # DCDetector module
10
+ module DCDetector
11
+ # DCDetector main class
12
+ class App
13
+ # Create the DCDetector object.
14
+ # @param ad_domain [String] the Active Directory domain to work on.
15
+ # @param dns_opts [Hash] options for the DNS resolver. See [Resolv::DNS.new](https://ruby-doc.org/3.2.0/stdlibs/resolv/Resolv/DNS.html#method-c-new).
16
+ # @option dns_opts [Array|String] :nameserver the DNS server to contact
17
+ # @example
18
+ # dcd = DCDetector::App.new('spookysec.local', nameserver: ['10.10.197.59'])
19
+ # dcd = DCDetector::App.new('za.tryhackme.com', nameserver: ['10.200.28.101'])
20
+ def initialize(ad_domain, dns_opts = nil)
21
+ @ad_domain = ad_domain
22
+ @dns_opts = dns_opts
23
+ end
24
+
25
+ # Get DC(s) FQDN
26
+ # @return [Array] the list of FQDN of all DCs
27
+ # @example
28
+ # dcd.dc_fqdn
29
+ # # => ["THMDC.za.tryhackme.com"]
30
+ # @see https://learn.microsoft.com/en-us/troubleshoot/windows-server/identity/how-domain-controllers-are-located
31
+ def dc_fqdn
32
+ Resolv::DNS.open(@dns_opts) do |dns|
33
+ # _kerberos._tcp, _kpasswd._tcp, _ldap._tcp works too but are not MS only
34
+ # _kerberos._tcp.dc._msdcs
35
+ # _ldap._tcp.pdc._msdcs, _gc._tcp
36
+ # _udp variants
37
+ ress = dns.getresources "_ldap._tcp.dc._msdcs.#{@ad_domain}", Resolv::DNS::Resource::IN::ANY
38
+ ress.map { |x| x.target.to_s }
39
+ end
40
+ end
41
+
42
+ # Get DC(s) computer name
43
+ # @return [Array] the list of computer name of all DCs
44
+ # @example
45
+ # dcd.dc_name
46
+ # # => ["THMDC"]
47
+ def dc_name
48
+ dc_fqdn.map { |x| x[...-@ad_domain.size - 1] }
49
+ end
50
+
51
+ # Get DC(s) IP address
52
+ # @return [Array] the list of IP address of all DCs
53
+ # @example
54
+ # dcd.dc_ip
55
+ # # => ["10.10.10.101", "10.200.28.101"]
56
+ def dc_ip
57
+ Resolv::DNS.open(@dns_opts) do |dns|
58
+ ress = dns.getresources "gc._msdcs.#{@ad_domain}", Resolv::DNS::Resource::IN::A
59
+ ress.map { |x| x.address.to_s }
60
+ end
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcdetector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre ZANNI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ description: Find computer name, FQDN, and IP address(es) of all DCs.
42
+ email: alexandre.zanni@europe.com
43
+ executables:
44
+ - dcd
45
+ - dcdetector
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - bin/dcd
51
+ - bin/dcdetector
52
+ - lib/dcdetector.rb
53
+ - lib/dcdetector/cli.rb
54
+ - lib/dcdetector/version.rb
55
+ homepage: https://noraj.github.io/dcdetector/
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ yard.run: yard
60
+ bug_tracker_uri: https://github.com/noraj/DCDetector/issues
61
+ changelog_uri: https://noraj.github.io/DCDetector/yard/file.CHANGELOG.html
62
+ documentation_uri: https://noraj.github.io/DCDetector/yard/file.Usage.html
63
+ homepage_uri: https://noraj.github.io/DCDetector/yard/
64
+ source_code_uri: https://github.com/noraj/DCDetector/
65
+ rubygems_mfa_required: 'true'
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.0.0
75
+ - - "<"
76
+ - !ruby/object:Gem::Version
77
+ version: '4.0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.4.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Spot all domain controllers in a Microsoft Active Directory environment.
88
+ test_files: []