ronin-listener-http 0.1.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5adf81fa9ced6ab4fd65074de117b81415c1404928f92454232c2062ff758548
4
+ data.tar.gz: 07e253fe463c655429521a42e2e79aeafe8a69389d58c606ea01d11a230271d7
5
+ SHA512:
6
+ metadata.gz: e1fdba946028f0696559f874f2264b3116c073398bd3dbc704b19d67a26cc73e02524177f2280c9fcb9ad42d51082b99ca809fd9da73258c794cafc26a9ab592
7
+ data.tar.gz: 950be8ff0f2f62488e39d32d4d4d70d775ba72f926e0470ba4907e60168646e148b357f98472ccb120a66eaa1e37d3106e6259377d1af8519bf9478bc4857aac
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.0
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-http specific exceptions
11
+ #
12
+ Style/CaseEquality:
13
+ Exclude:
14
+ - 'lib/ronin/listener/http/server.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.1
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title 'Ronin::Listener::HTTP 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 HTTP requests.
5
+ * Supports filtering HTTP requests by path or `Host` header.
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,93 @@
1
+ # ronin-listener-http
2
+
3
+ [![CI](https://github.com/ronin-rb/ronin-listener-http/actions/workflows/ruby.yml/badge.svg)](https://github.com/ronin-rb/ronin-listener-http/actions/workflows/ruby.yml)
4
+ [![Code Climate](https://codeclimate.com/github/ronin-rb/ronin-listener-http.svg)](https://codeclimate.com/github/ronin-rb/ronin-listener-http)
5
+
6
+ * [Website](https://ronin-rb.dev/)
7
+ * [Source](https://github.com/ronin-rb/ronin-listener-http)
8
+ * [Issues](https://github.com/ronin-rb/ronin-listener-http/issues)
9
+ * [Documentation](https://ronin-rb.dev/docs/ronin-listener-http)
10
+ * [Discord](https://discord.gg/6WAb3PsVX9) |
11
+ [Mastodon](https://infosec.exchange/@ronin_rb)
12
+
13
+ ## Description
14
+
15
+ ronin-listener-http is a DNS server for receiving exfiltrated data sent via HTTP
16
+ requests. ronin-listener-http can be used to test for Server-Side Request
17
+ Forgery (SSRF) or XML external entity (XXE) injection.
18
+
19
+ ## Features
20
+
21
+ * Supports receiving HTTP requests.
22
+ * Supports filtering HTTP requests by path or `Host` header.
23
+
24
+ ## Examples
25
+
26
+ ```ruby
27
+ require 'ronin/listener/http'
28
+
29
+ Ronin::Listener::HTTP.listen(host: '127.0.0.1', port: 8080) do |request|
30
+ puts "#{request.method} #{request.path} #{request.version}"
31
+
32
+ request.headers.each do |name,value|
33
+ puts "#{name}: #{value}"
34
+ end
35
+
36
+ puts request.body if request.body
37
+ puts
38
+ end
39
+ ```
40
+
41
+ ## Requirements
42
+
43
+ * [Ruby] >= 3.0.0
44
+ * [async-http] ~> 1.0
45
+
46
+ ## Install
47
+
48
+ ```shell
49
+ $ gem install ronin-listener-http
50
+ ```
51
+
52
+ ### Gemfile
53
+
54
+ ```ruby
55
+ gem 'ronin-listener-http', '~> 0.1'
56
+ ```
57
+
58
+ ### gemspec
59
+
60
+ ```ruby
61
+ gem.add_dependency 'ronin-listener-http', '~> 0.1'
62
+ ```
63
+
64
+ ## Development
65
+
66
+ 1. [Fork It!](https://github.com/ronin-rb/ronin-listener-http/fork)
67
+ 2. Clone It!
68
+ 3. `cd ronin-listener-http/`
69
+ 4. `bundle install`
70
+ 5. `git checkout -b my_feature`
71
+ 6. Code It!
72
+ 7. `bundle exec rake spec`
73
+ 8. `git push origin my_feature`
74
+
75
+ ## License
76
+
77
+ Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
78
+
79
+ ronin-listener-http is free software: you can redistribute it and/or modify
80
+ it under the terms of the GNU Lesser General Public License as published
81
+ by the Free Software Foundation, either version 3 of the License, or
82
+ (at your option) any later version.
83
+
84
+ ronin-listener-http is distributed in the hope that it will be useful,
85
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
86
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87
+ GNU Lesser General Public License for more details.
88
+
89
+ You should have received a copy of the GNU Lesser General Public License
90
+ along with ronin-listener-http. If not, see <https://www.gnu.org/licenses/>.
91
+
92
+ [Ruby]: https://www.ruby-lang.org
93
+ [async-http]: https://github.com/socketry/async-http#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,23 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ronin/listener/http'
6
+
7
+ puts "Listening on 127.0.0.1:8080 ..."
8
+ puts "Try sending requests to http://localhost:8080/ to test"
9
+
10
+ begin
11
+ Ronin::Listener::HTTP.listen(host: '127.0.0.1', port: 8080) do |request|
12
+ puts "#{request.method} #{request.path} #{request.version}"
13
+
14
+ request.headers.each do |name,value|
15
+ puts "#{name}: #{value}"
16
+ end
17
+
18
+ puts request.body if request.body
19
+ puts
20
+ end
21
+ rescue Interrupt
22
+ exit(127)
23
+ end
data/gemspec.yml ADDED
@@ -0,0 +1,27 @@
1
+ name: ronin-listener-http
2
+ summary: A HTTP server for receiving exfiled data.
3
+ description: |
4
+ ronin-listener-http is a HTTP server for receiving exfiltrated data sent via
5
+ HTTP requests. ronin-listener-http can be used to test for Server-Side Request
6
+ Forgery (SSRF) or XML external entity (XXE) 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-http
16
+ source_code_uri: https://github.com/ronin-rb/ronin-listener-http
17
+ bug_tracker_uri: https://github.com/ronin-rb/ronin-listener-http/issues
18
+ changelog_uri: https://github.com/ronin-rb/ronin-listener-http/blob/main/ChangeLog.md
19
+ rubygems_mfa_required: 'true'
20
+
21
+ required_ruby_version: ">= 3.0.0"
22
+
23
+ dependencies:
24
+ async-http: ~> 0.60
25
+
26
+ development_dependencies:
27
+ bundler: ~> 2.0
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-http - A HTTP server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-http 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-http 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-http. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'csv'
22
+ require 'json'
23
+
24
+ module Ronin
25
+ module Listener
26
+ module HTTP
27
+ #
28
+ # Represents a received HTTP request.
29
+ #
30
+ class Request
31
+
32
+ # The HTTP request method.
33
+ #
34
+ # @return [String]
35
+ attr_reader :method
36
+
37
+ # The request path.
38
+ #
39
+ # @return [String]
40
+ attr_reader :path
41
+
42
+ # The HTTP version.
43
+ #
44
+ # @return [String]
45
+ attr_reader :version
46
+
47
+ # The HTTP request headers.
48
+ #
49
+ # @return [Hash{String => String}]
50
+ attr_reader :headers
51
+
52
+ # The optional request body.
53
+ #
54
+ # @return [String, nil]
55
+ attr_reader :body
56
+
57
+ #
58
+ # Initializes the request.
59
+ #
60
+ # @param [String] method
61
+ # The HTTP request method.
62
+ #
63
+ # @param [String] path
64
+ # The request path.
65
+ #
66
+ # @param [String] version
67
+ # The HTTP version.
68
+ #
69
+ # @param [Hash{String => String}] headers
70
+ # The HTTP request headers.
71
+ #
72
+ # @param [String, nil] body
73
+ # The optional body sent with the request.
74
+ #
75
+ def initialize(method: , path: , version: , headers:, body: nil)
76
+ @method = method
77
+ @path = path
78
+ @version = version
79
+ @headers = headers
80
+ @body = body
81
+ end
82
+
83
+ #
84
+ # Compares the request to another request.
85
+ #
86
+ # @param [Object] other
87
+ # The other object to compare to.
88
+ #
89
+ # @return [Boolean]
90
+ # Indicates if the request is equal to another request.
91
+ #
92
+ def ==(other)
93
+ self.class == other.class &&
94
+ @method == other.method &&
95
+ @path == other.path &&
96
+ @version == other.version &&
97
+ @headers == other.headers &&
98
+ @body == other.body
99
+ end
100
+
101
+ #
102
+ # Converts the request to a String.
103
+ #
104
+ # @return [String]
105
+ # The raw HTTP request.
106
+ #
107
+ def to_s
108
+ string = "#{@method} #{@path} HTTP/#{@version}\r\n"
109
+
110
+ @headers.each do |name,value|
111
+ string << "#{name}: #{value}\r\n"
112
+ end
113
+
114
+ string << "\r\n#{@body}"
115
+ return string
116
+ end
117
+
118
+ #
119
+ # Converts the request to a Hash.
120
+ #
121
+ # @return [Hash{Symbol => Object}]
122
+ #
123
+ def to_h
124
+ {
125
+ method: @method,
126
+ path: @path,
127
+ version: @version,
128
+ headers: @headers,
129
+ body: @body
130
+ }
131
+ end
132
+
133
+ #
134
+ # Converts the request into a CSV line.
135
+ #
136
+ # @return [String]
137
+ # The generated CSV line.
138
+ #
139
+ def to_csv
140
+ CSV.generate_line(
141
+ [
142
+ @method,
143
+ @path,
144
+ @version,
145
+ CSV.generate { |csv|
146
+ @headers.each_pair do |name_value|
147
+ csv << name_value
148
+ end
149
+ },
150
+ @body
151
+ ]
152
+ )
153
+ end
154
+
155
+ alias as_json to_h
156
+
157
+ #
158
+ # Converts the HTTP request into JSON.
159
+ #
160
+ # @param [Array] args
161
+ # Additional arguments for `Hash#to_json`.
162
+ #
163
+ # @return [String]
164
+ # The raw JSON string.
165
+ #
166
+ def to_json(*args)
167
+ as_json.to_json(*args)
168
+ end
169
+
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-http - A HTTP server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-http 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-http 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-http. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/listener/http/request'
22
+
23
+ require 'async'
24
+ require 'async/http/server'
25
+ require 'async/http/endpoint'
26
+ require 'async/http/protocol/response'
27
+
28
+ module Ronin
29
+ module Listener
30
+ module HTTP
31
+ #
32
+ # A simple HTTP server that receives exfiltrated HTTP requests.
33
+ #
34
+ class Server < Async::HTTP::Server
35
+
36
+ # The host the server will listen on.
37
+ #
38
+ # @return [String]
39
+ attr_reader :host
40
+
41
+ # The port the server will listen on.
42
+ #
43
+ # @return [Integer]
44
+ attr_reader :port
45
+
46
+ # The virtual host (vhost) to filter requests with.
47
+ #
48
+ # @return [String, Regexp, nil]
49
+ attr_reader :vhost
50
+
51
+ # The root directory to filter requests with.
52
+ #
53
+ # @return [String]
54
+ attr_reader :root
55
+
56
+ # The callback which will be passed all received queries.
57
+ #
58
+ # @return [Proc]
59
+ #
60
+ # @api private
61
+ attr_reader :callback
62
+
63
+ #
64
+ # Initializes the HTTP listener server.
65
+ #
66
+ # @param [String] host
67
+ # The interface to listen on.
68
+ #
69
+ # @param [Integer] port
70
+ # The local port to listen on.
71
+ #
72
+ # @param [String, Regexp] vhost
73
+ # The virtual host (vhost) to filter requests with.
74
+ #
75
+ # @param [String] root
76
+ # The root directory to filter requests with. Defaults to `/`.
77
+ #
78
+ # @yield [request]
79
+ # The given block will be passed each received HTTP request.
80
+ #
81
+ # @yieldparam [Request] request
82
+ # The received HTTP request object.
83
+ #
84
+ # @raise [ArgumentError]
85
+ # No callback block was given.
86
+ #
87
+ def initialize(host: '0.0.0.0',
88
+ port: 80,
89
+ vhost: nil,
90
+ root: '/',
91
+ &callback)
92
+ unless callback
93
+ raise(ArgumentError,"#{self.class}#initialize requires a callback block")
94
+ end
95
+
96
+ @host = host
97
+ @port = port
98
+
99
+ # filtering options
100
+ @vhost = vhost
101
+ @root = if root.end_with?('/') then root
102
+ else "#{root}/"
103
+ end
104
+
105
+ @callback = callback
106
+
107
+ endpoint = Async::HTTP::Endpoint.parse("http://#{host}:#{port}")
108
+
109
+ super(method(:process),endpoint)
110
+ end
111
+
112
+ #
113
+ # Runs the HTTP server.
114
+ #
115
+ def run(*args)
116
+ Async::Reactor.run do |task|
117
+ super(*args)
118
+ end
119
+ end
120
+
121
+ #
122
+ # Processes a received request.
123
+ #
124
+ # @param [Async::HTTP::Protocol::HTTP1::Request,
125
+ # Async::HTTP::Protocol::HTTP2::Request] request
126
+ #
127
+ # @return [Protocol::HTTP::Response]
128
+ #
129
+ def process(request)
130
+ if (@vhost.nil? || @vhost === request.authority)
131
+ if request.path == @root || request.path.start_with?(@root)
132
+ @callback.call(
133
+ Request.new(
134
+ method: request.method,
135
+ path: request.path,
136
+ version: request.version,
137
+ headers: request.headers,
138
+ body: request.body
139
+ )
140
+ )
141
+ end
142
+ end
143
+
144
+ return Protocol::HTTP::Response[404, {}, ["Not Found"]]
145
+ end
146
+
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-http - A HTTP server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-http 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-http 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-http. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Ronin
22
+ module Listener
23
+ module HTTP
24
+ # ronin-listener-http version
25
+ VERSION = '0.1.0.rc1'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-listener-http - A HTTP server for receiving exfiltrated data.
4
+ #
5
+ # Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6
+ #
7
+ # ronin-listener-http 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-http 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-http. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/listener/http/server'
22
+
23
+ module Ronin
24
+ module Listener
25
+ #
26
+ # Top-level methods for {Ronin::Listener::HTTP}.
27
+ #
28
+ module HTTP
29
+ #
30
+ # Starts the HTTP listener server.
31
+ #
32
+ # @param [Hash{Symbol => Object}] kwargs
33
+ # Additional keyword arguments for {Server#initialize}.
34
+ #
35
+ # @option kwargs [String] :host ('0.0.0.0')
36
+ # The interface to listen on.
37
+ #
38
+ # @option kwargs [Integer] :port (80)
39
+ # The local port to listen on.
40
+ #
41
+ # @option kwargs [String, Regexp] :vhost
42
+ # The virtual host (vhost) to filter requests with.
43
+ #
44
+ # @option kwargs [String] :root ('/')
45
+ # The root directory to filter requests with. Defaults to `/`.
46
+ #
47
+ # @yield [request]
48
+ # The given block will be passed each received HTTP request.
49
+ #
50
+ # @yieldparam [Async::HTTP::Protocol::HTTP1::Request,
51
+ # Async::HTTP::Protocol::HTTP2::Request] request
52
+ # The received HTTP request object.
53
+ #
54
+ # @raise [ArgumentError]
55
+ # No callback block was given.
56
+ #
57
+ def self.listen(**kwargs,&callback)
58
+ server = Server.new(**kwargs,&callback)
59
+ server.run
60
+ end
61
+ end
62
+ end
63
+ 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/http/version'
14
+ Ronin::Listener::HTTP::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-http
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-http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.60'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.60'
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-http is a HTTP server for receiving exfiltrated data sent via
43
+ HTTP requests. ronin-listener-http can be used to test for Server-Side Request
44
+ Forgery (SSRF) or XML external entity (XXE) 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/http.rb
68
+ - lib/ronin/listener/http/request.rb
69
+ - lib/ronin/listener/http/server.rb
70
+ - lib/ronin/listener/http/version.rb
71
+ - ronin-listener-http.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-http
77
+ source_code_uri: https://github.com/ronin-rb/ronin-listener-http
78
+ bug_tracker_uri: https://github.com/ronin-rb/ronin-listener-http/issues
79
+ changelog_uri: https://github.com/ronin-rb/ronin-listener-http/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 HTTP server for receiving exfiled data.
100
+ test_files: []