ronin-listener-dns 0.1.0.rc1

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: dfdeec510bf6a894dc6e5392ea245df64b1154402fdc8f251093f3362eacdbc5
4
+ data.tar.gz: 39d2ca68960e2a0782e415b3fe57a31ae387a835323576870f118a4d1ff2eac9
5
+ SHA512:
6
+ metadata.gz: f01b414046eacec88340d3a4989e4bf930c53a89984ae926d560266f0f7db6715999a67a98748d3882b158f8a4893c036270efc401fbff0bcd80e5c7a50b86df
7
+ data.tar.gz: 47fd7dd94812775fa6382e0e597993e4c40602d369cf8af8fd0005c53e2deb7c0e942bd4856b6bbc9d8318752efb5e158088e071122131e99ea5764a467a5f2e
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ -
3
+ ChangeLog.md
4
+ COPYING.txt
@@ -0,0 +1,47 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - '3.0'
13
+ - '3.1'
14
+ - '3.2'
15
+ - '3.3'
16
+ # - jruby
17
+ # - truffleruby
18
+ name: Ruby ${{ matrix.ruby }}
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ # - name: Install dependencies
27
+ # run: |
28
+ # sudo apt update -y && \
29
+ # sudo apt install -y --no-install-recommends --no-install-suggests FIXME
30
+ - name: Install dependencies
31
+ run: bundle install --jobs 4 --retry 3
32
+ - name: Run tests
33
+ run: bundle exec rake test
34
+
35
+ # rubocop linting
36
+ rubocop:
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ - name: Set up Ruby
41
+ uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: 3.1
44
+ - name: Install dependencies
45
+ run: bundle install --jobs 4 --retry 3
46
+ - name: Run rubocop
47
+ run: bundle exec rubocop --parallel
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /coverage
2
+ /doc
3
+ /pkg
4
+ /man/*.[1-9]
5
+ /vendor/bundle
6
+ /Gemfile.lock
7
+ /.bundle
8
+ /.yardoc
9
+ .DS_Store
10
+ *.db
11
+ *.log
12
+ *.swp
13
+ *~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ SuggestExtensions: false
4
+ TargetRubyVersion: 3.1
5
+
6
+ inherit_gem:
7
+ rubocop-ronin: rubocop.yml
8
+
9
+ #
10
+ # ronin-listener-dns specific exceptions
11
+ #
12
+ Layout/SpaceInsideBlockBraces:
13
+ Exclude:
14
+ - 'spec/server_spec.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.1
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title 'Ronin::Listener::DNS Documentation' --protected
data/COPYING.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/ChangeLog.md ADDED
@@ -0,0 +1,6 @@
1
+ ### 0.1.0 / 2024-XX-XX
2
+
3
+ * Initial release:
4
+ * Supports receiving any DNS query for a given domain.
5
+ * Always returns with `NXDOMAIN` to prevent DNS caching.
6
+
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ gem 'rubygems-tasks', '~> 0.2'
10
+
11
+ gem 'rspec', '~> 3.0'
12
+ gem 'simplecov', '~> 0.20'
13
+
14
+ gem 'kramdown', '~> 2.0'
15
+ gem 'redcarpet', platform: :mri
16
+ gem 'yard', '~> 0.9'
17
+ gem 'yard-spellcheck', require: false
18
+
19
+ gem 'dead_end', require: false
20
+ gem 'sord', require: false, platform: :mri
21
+ gem 'stackprof', require: false, platform: :mri
22
+ gem 'rubocop', require: false, platform: :mri
23
+ gem 'rubocop-ronin', require: false, platform: :mri
24
+ end
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # ronin-listener-dns
2
+
3
+ [![CI](https://github.com/ronin-rb/ronin-listener-dns/actions/workflows/ruby.yml/badge.svg)](https://github.com/ronin-rb/ronin-listener-dns/actions/workflows/ruby.yml)
4
+ [![Code Climate](https://codeclimate.com/github/ronin-rb/ronin-listener-dns.svg)](https://codeclimate.com/github/ronin-rb/ronin-listener-dns)
5
+
6
+ * [Website](https://ronin-rb.dev/)
7
+ * [Source](https://github.com/ronin-rb/ronin-listener-dns)
8
+ * [Issues](https://github.com/ronin-rb/ronin-listener-dns/issues)
9
+ * [Documentation](https://ronin-rb.dev/docs/ronin-listener-dns)
10
+ * [Discord](https://discord.gg/6WAb3PsVX9) |
11
+ [Mastodon](https://infosec.exchange/@ronin_rb)
12
+
13
+ ## Description
14
+
15
+ ronin-listener-dns is a DNS server for receiving exfiltrated data sent via DNS
16
+ queries. ronin-listener-dns can be used to test for XML external entity (XXE)
17
+ injection.
18
+
19
+ ## Features
20
+
21
+ * Supports receiving any DNS query for a given domain.
22
+ * Always returns with `NXDOMAIN` to prevent DNS caching.
23
+
24
+ ## Examples
25
+
26
+ ```ruby
27
+ require 'ronin/listener/dns'
28
+
29
+ Ronin::Listener::DNS.listen('example.com', host: '127.0.0.1', port: 5553) do |query|
30
+ puts "Received query for #{query.type} #{query.label} from #{query.source}"
31
+ end
32
+ ```
33
+
34
+ Then try running `host -p 5553 s3cr3t.example.com 127.0.0.1` to test the server.
35
+
36
+ ```
37
+ Received query for A s3cr3t.example.com from 127.0.0.1:59042
38
+ ```
39
+
40
+ **Note:** if you wish to run the server on `0.0.0.0` and port `53`, the ruby
41
+ script must be ran as `root`.
42
+
43
+ ## Requirements
44
+
45
+ * [Ruby] >= 3.0.0
46
+ * [async-dns] ~> 1.0
47
+
48
+ ## Install
49
+
50
+ ```shell
51
+ $ gem install ronin-listener-dns
52
+ ```
53
+
54
+ ### Gemfile
55
+
56
+ ```ruby
57
+ gem 'ronin-listener-dns', '~> 0.1'
58
+ ```
59
+
60
+ ### gemspec
61
+
62
+ ```ruby
63
+ gem.add_dependency 'ronin-listener-dns', '~> 0.1'
64
+ ```
65
+
66
+ ## Development
67
+
68
+ 1. [Fork It!](https://github.com/ronin-rb/ronin-listener-dns/fork)
69
+ 2. Clone It!
70
+ 3. `cd ronin-listener-dns/`
71
+ 4. `bundle install`
72
+ 5. `git checkout -b my_feature`
73
+ 6. Code It!
74
+ 7. `bundle exec rake spec`
75
+ 8. `git push origin my_feature`
76
+
77
+ ## License
78
+
79
+ Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
80
+
81
+ ronin-listener-dns is free software: you can redistribute it and/or modify
82
+ it under the terms of the GNU Lesser General Public License as published
83
+ by the Free Software Foundation, either version 3 of the License, or
84
+ (at your option) any later version.
85
+
86
+ ronin-listener-dns is distributed in the hope that it will be useful,
87
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
88
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89
+ GNU Lesser General Public License for more details.
90
+
91
+ You should have received a copy of the GNU Lesser General Public License
92
+ along with ronin-listener-dns. If not, see <https://www.gnu.org/licenses/>.
93
+
94
+ [Ruby]: https://www.ruby-lang.org
95
+ [async-dns]: https://github.com/socketry/async-dns#readme
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler'
5
+ rescue LoadError => e
6
+ warn e.message
7
+ warn "Run `gem install bundler` to install Bundler"
8
+ exit(-1)
9
+ end
10
+
11
+ begin
12
+ Bundler.setup(:development)
13
+ rescue Bundler::BundlerError => e
14
+ warn e.message
15
+ warn "Run `bundle install` to install missing gems"
16
+ exit e.status_code
17
+ end
18
+
19
+ require 'rake'
20
+
21
+ require 'rubygems/tasks'
22
+ Gem::Tasks.new(sign: {checksum: true, pgp: true})
23
+
24
+ require 'rspec/core/rake_task'
25
+ RSpec::Core::RakeTask.new
26
+ task :test => :spec
27
+ task :default => :spec
28
+
29
+ require 'yard'
30
+ YARD::Rake::YardocTask.new
31
+ task :docs => :yard
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ronin/listener/dns'
6
+
7
+ puts "Listening on 127.0.0.1:5553 for *.example.com ..."
8
+ puts "Try running `host -p 5553 s3cr3t.example.com 127.0.0.1` to test"
9
+ puts
10
+
11
+ begin
12
+ Ronin::Listener::DNS.listen('example.com', host: '127.0.0.1', port: 5553) do |query|
13
+ puts "Received query for #{query.type} #{query.label} from #{query.source}"
14
+ end
15
+ rescue Interrupt
16
+ exit(127)
17
+ end
data/gemspec.yml ADDED
@@ -0,0 +1,27 @@
1
+ name: ronin-listener-dns
2
+ summary: A DNS listener that listens for exfiltrated data via DNS queries.
3
+ description: |
4
+ ronin-listener-dns is a DNS server for receiving exfiltrated data sent via DNS
5
+ queries. ronin-listener-dns can be used to test for XML external entity (XXE)
6
+ injection.
7
+
8
+ license: LGPL-3.0
9
+ authors: Postmodern
10
+ email: postmodern.mod3@gmail.com
11
+ homepage: https://ronin-rb.dev/
12
+ has_yard: true
13
+
14
+ metadata:
15
+ documentation_uri: https://ronin-rb.dev/docs/ronin-listener-dns
16
+ source_code_uri: https://github.com/ronin-rb/ronin-listener-dns
17
+ bug_tracker_uri: https://github.com/ronin-rb/ronin-listener-dns/issues
18
+ changelog_uri: https://github.com/ronin-rb/ronin-listener-dns/blob/main/ChangeLog.md
19
+ rubygems_mfa_required: 'true'
20
+
21
+ required_ruby_version: ">= 3.0.0"
22
+
23
+ dependencies:
24
+ async-dns: ~> 1.0
25
+
26
+ development_dependencies:
27
+ bundler: ~> 2.0
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-dns - A DNS server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-dns is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-listener-dns is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-listener-dns. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'json'
22
+ require 'csv'
23
+
24
+ module Ronin
25
+ module Listener
26
+ module DNS
27
+ #
28
+ # Represents a received DNS query.
29
+ #
30
+ class Query
31
+
32
+ # The desired record type.
33
+ #
34
+ # @return [:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS]
35
+ attr_reader :type
36
+
37
+ # The domain label (ex: `example.com` or `www.example.com`).
38
+ #
39
+ # @return [String]
40
+ attr_reader :label
41
+
42
+ alias name label
43
+
44
+ # The remote IP address and port that sent the query.
45
+ #
46
+ # @return [Addrinfo]
47
+ attr_reader :source_addr
48
+
49
+ #
50
+ # Initializes the query.
51
+ #
52
+ # @param [:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS] type
53
+ # The queried record type.
54
+ #
55
+ # @param [String] label
56
+ # The queried domain label.
57
+ #
58
+ # @param [Addrinfo] source_addr
59
+ # The remote IP address and port that sent the query.
60
+ #
61
+ # @api private
62
+ #
63
+ def initialize(type,label,source_addr)
64
+ @type = type
65
+ @label = label
66
+
67
+ @source_addr = source_addr
68
+ end
69
+
70
+ #
71
+ # The source IP address that sent the query.
72
+ #
73
+ # @return [String]
74
+ #
75
+ def source_ip
76
+ @source_addr.ip_address
77
+ end
78
+
79
+ #
80
+ # The source port the query was sent from.
81
+ #
82
+ # @return [Integer]
83
+ #
84
+ def source_port
85
+ @source_addr.ip_port
86
+ end
87
+
88
+ #
89
+ # The source of the query.
90
+ #
91
+ # @return [String]
92
+ # The source IP:port pair as a String.
93
+ #
94
+ def source
95
+ "#{source_ip}:#{source_port}"
96
+ end
97
+
98
+ #
99
+ # Converts the query to a String.
100
+ #
101
+ # @return [String]
102
+ # The String containing the {#source}, {#type}, and {#label}.
103
+ #
104
+ def to_s
105
+ "#{source} #{@type} #{@label}"
106
+ end
107
+
108
+ #
109
+ # Converts the query into an Array.
110
+ #
111
+ # @return [(String, Integer, Symbol, String)]
112
+ # The {#source_ip}, {#source_port}, {#type}, and {#label}.
113
+ #
114
+ def to_a
115
+ [source_ip, source_port, @type, @label]
116
+ end
117
+
118
+ #
119
+ # Converts the query into a Hash.
120
+ #
121
+ # @return [Hash{Symbol => String,Integer,Symbol}]
122
+ # The Hash containing {#source_ip}, {#source_port}, {#type}, and
123
+ # {#label}.
124
+ #
125
+ def to_h
126
+ {
127
+ source_ip: source_ip,
128
+ source_port: source_port,
129
+ type: @type,
130
+ label: @label
131
+ }
132
+ end
133
+
134
+ #
135
+ # Converts the DNS query to a CSV row.
136
+ #
137
+ # @return [String]
138
+ # The CSV row.
139
+ #
140
+ def to_csv
141
+ to_a.to_csv
142
+ end
143
+
144
+ alias as_json to_h
145
+
146
+ #
147
+ # Converts the DNS query into JSON.
148
+ #
149
+ # @param [Array] args
150
+ # Additional arguments for `Hash#to_json`.
151
+ #
152
+ # @return [String]
153
+ # The raw JSON string.
154
+ #
155
+ def to_json(*args)
156
+ as_json.to_json(*args)
157
+ end
158
+
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-dns - A DNS server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-dns is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-listener-dns is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-listener-dns. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/listener/dns/query'
22
+
23
+ require 'async/dns'
24
+
25
+ module Ronin
26
+ module Listener
27
+ module DNS
28
+ #
29
+ # A simple DNS server for receiving exfiltrated DNS queries.
30
+ #
31
+ class Server < Async::DNS::Server
32
+
33
+ # The domain to accept queries for.
34
+ #
35
+ # @return [String]
36
+ attr_reader :domain
37
+
38
+ # The host the server will listen on.
39
+ #
40
+ # @return [String]
41
+ attr_reader :host
42
+
43
+ # The port the server will listen on.
44
+ #
45
+ # @return [Integer]
46
+ attr_reader :port
47
+
48
+ # The callback which will be passed all received queries.
49
+ #
50
+ # @return [Proc]
51
+ #
52
+ # @api private
53
+ attr_reader :callback
54
+
55
+ #
56
+ # Initializes the DNS listener server.
57
+ #
58
+ # @param [String, Regexp] domain
59
+ # The domain to accept queries for (ex: `example.com`).
60
+ #
61
+ # @param [String] host
62
+ # The interface to listen on.
63
+ #
64
+ # @param [Integer] port
65
+ # The local port to listen on.
66
+ #
67
+ # @yield [query]
68
+ # The given block will be passed each received query.
69
+ #
70
+ # @yieldparam [Query] query
71
+ # The received DNS query object.
72
+ #
73
+ # @raise [ArgumentError]
74
+ # No callback block was given.
75
+ #
76
+ def initialize(domain, host: '0.0.0.0',
77
+ port: 53,
78
+ &callback)
79
+ unless callback
80
+ raise(ArgumentError,"#{self.class}#initialize requires a callback block")
81
+ end
82
+
83
+ @domain = domain
84
+ @suffix = ".#{domain}"
85
+
86
+ @host = host
87
+ @port = port
88
+
89
+ super([[:udp, host, port]])
90
+
91
+ @callback = callback
92
+ end
93
+
94
+ # Mapping of Resolv resource classes to Symbols.
95
+ #
96
+ # @api private
97
+ RECORD_TYPES = {
98
+ Resolv::DNS::Resource::IN::A => :A,
99
+ Resolv::DNS::Resource::IN::AAAA => :AAAA,
100
+ Resolv::DNS::Resource::IN::ANY => :ANY,
101
+ Resolv::DNS::Resource::IN::CNAME => :CNAME,
102
+ Resolv::DNS::Resource::IN::HINFO => :HINFO,
103
+ Resolv::DNS::Resource::IN::LOC => :LOC,
104
+ Resolv::DNS::Resource::IN::MINFO => :MINFO,
105
+ Resolv::DNS::Resource::IN::MX => :MX,
106
+ Resolv::DNS::Resource::IN::NS => :NS,
107
+ Resolv::DNS::Resource::IN::PTR => :PTR,
108
+ Resolv::DNS::Resource::IN::SOA => :SOA,
109
+ Resolv::DNS::Resource::IN::SRV => :SRV,
110
+ Resolv::DNS::Resource::IN::TXT => :TXT,
111
+ Resolv::DNS::Resource::IN::WKS => :WKS
112
+ }
113
+
114
+ #
115
+ # Processes an incoming query.
116
+ #
117
+ # @param [String] label
118
+ # The queried domain label (ex: `www.example.com`).
119
+ #
120
+ # @param [Class<Resolv::DNS::Resource>] resource_class
121
+ # The resource class (ex: `Resolv::DNS::Resource::IN::A`).
122
+ #
123
+ # @param [Async::DNS::Transaction] transaction
124
+ # The DNS transaction object.
125
+ #
126
+ # @api private
127
+ #
128
+ def process(label,resource_class,transaction)
129
+ # filter out queries for all other domains
130
+ if label.end_with?(@suffix)
131
+ # map the `Resolv::DNS::Resource::IN` class to a Symbol
132
+ query_type = RECORD_TYPES.fetch(resource_class)
133
+
134
+ # extract the remote address
135
+ source_addr = transaction.options[:remote_address]
136
+
137
+ @callback.call(Query.new(query_type,label,source_addr))
138
+ end
139
+
140
+ # always respond with an error to prevent DNS caching
141
+ transaction.fail!(:NXDomain)
142
+ end
143
+
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-dns - A DNS server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-dns is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-listener-dns is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-listener-dns. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module Listener
23
+ module DNS
24
+ # ronin-listener-dns version
25
+ VERSION = '0.1.0.rc1'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-dns - A DNS server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-dns is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-listener-dns is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-listener-dns. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/listener/dns/server'
22
+
23
+ module Ronin
24
+ module Listener
25
+ #
26
+ # Top-level methods for {Ronin::Listener::DNS}.
27
+ #
28
+ module DNS
29
+ #
30
+ # Starts the DNS listener server.
31
+ #
32
+ # @param [String] domain
33
+ # The domain to accept queries for (ex: `example.com`).
34
+ #
35
+ # @param [Hash{Symbol => Object}] kwargs
36
+ # Additional keyword arguments for {Server#initialize}.
37
+ #
38
+ # @option kwargs [String] :host ('0.0.0.0')
39
+ # The interface to listen on.
40
+ #
41
+ # @option kwargs [Integer] :port (53)
42
+ # The local port to listen on.
43
+ #
44
+ # @yield [query_type,query_name]
45
+ # The given block will be passed each received query.
46
+ #
47
+ # @yieldparam [:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS] query_type
48
+ # The type of the query.
49
+ #
50
+ # @yieldparam [String] query_name
51
+ # The hostname being queried.
52
+ #
53
+ # @raise [ArgumentError]
54
+ # No callback block was given.
55
+ #
56
+ # @example
57
+ # Ronin::Listener::DNS.listen('0.0.0.0',53) do |query_type,query_name|
58
+ # puts "Received query #{query_type} #{query_name}"
59
+ # end
60
+ #
61
+ def self.listen(domain,**kwargs,&callback)
62
+ server = Server.new(domain,**kwargs,&callback)
63
+ server.run
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
7
+
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
+
13
+ require 'ronin/listener/dns/version'
14
+ Ronin::Listener::DNS::VERSION
15
+ end
16
+
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
23
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
24
+
25
+ glob = ->(patterns) { gem.files & Dir[*patterns] }
26
+
27
+ gem.files = `git ls-files`.split($/)
28
+ gem.files = glob[gemspec['files']] if gemspec['files']
29
+ gem.files += Array(gemspec['generated_files'])
30
+ # exclude test files from the packages gem
31
+ gem.files -= glob[gemspec['test_files'] || 'spec/{**/}*']
32
+
33
+ gem.executables = gemspec.fetch('executables') do
34
+ glob['bin/*'].map { |path| File.basename(path) }
35
+ end
36
+
37
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
38
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
39
+
40
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
41
+ %w[ext lib].select { |dir| File.directory?(dir) }
42
+ })
43
+
44
+ gem.requirements = gemspec['requirements']
45
+ gem.required_ruby_version = gemspec['required_ruby_version']
46
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
47
+ gem.post_install_message = gemspec['post_install_message']
48
+
49
+ split = ->(string) { string.split(/,\s*/) }
50
+
51
+ if gemspec['dependencies']
52
+ gemspec['dependencies'].each do |name,versions|
53
+ gem.add_dependency(name,split[versions])
54
+ end
55
+ end
56
+
57
+ if gemspec['development_dependencies']
58
+ gemspec['development_dependencies'].each do |name,versions|
59
+ gem.add_development_dependency(name,split[versions])
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ronin-listener-dns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-dns
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: |
42
+ ronin-listener-dns is a DNS server for receiving exfiltrated data sent via DNS
43
+ queries. ronin-listener-dns can be used to test for XML external entity (XXE)
44
+ injection.
45
+ email: postmodern.mod3@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files:
49
+ - COPYING.txt
50
+ - ChangeLog.md
51
+ - README.md
52
+ files:
53
+ - ".document"
54
+ - ".github/workflows/ruby.yml"
55
+ - ".gitignore"
56
+ - ".rspec"
57
+ - ".rubocop.yml"
58
+ - ".ruby-version"
59
+ - ".yardopts"
60
+ - COPYING.txt
61
+ - ChangeLog.md
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - examples/server.rb
66
+ - gemspec.yml
67
+ - lib/ronin/listener/dns.rb
68
+ - lib/ronin/listener/dns/query.rb
69
+ - lib/ronin/listener/dns/server.rb
70
+ - lib/ronin/listener/dns/version.rb
71
+ - ronin-listener-dns.gemspec
72
+ homepage: https://ronin-rb.dev/
73
+ licenses:
74
+ - LGPL-3.0
75
+ metadata:
76
+ documentation_uri: https://ronin-rb.dev/docs/ronin-listener-dns
77
+ source_code_uri: https://github.com/ronin-rb/ronin-listener-dns
78
+ bug_tracker_uri: https://github.com/ronin-rb/ronin-listener-dns/issues
79
+ changelog_uri: https://github.com/ronin-rb/ronin-listener-dns/blob/main/ChangeLog.md
80
+ rubygems_mfa_required: 'true'
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.3.27
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A DNS listener that listens for exfiltrated data via DNS queries.
100
+ test_files: []