ronin-web 0.3.0.pre2 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +13 -0
- data/.mailmap +1 -0
- data/.ruby-version +1 -0
- data/COPYING.txt +3 -3
- data/ChangeLog.md +115 -67
- data/Gemfile +42 -37
- data/README.md +159 -144
- data/Rakefile +16 -7
- data/bin/ronin-web +10 -18
- data/data/new/nokogiri.rb.erb +12 -0
- data/data/new/server.rb.erb +22 -0
- data/data/new/spider.rb.erb +26 -0
- data/data/new/webapp/.gitignore +15 -0
- data/data/new/webapp/.ruby-version.erb +1 -0
- data/data/new/webapp/Dockerfile.erb +11 -0
- data/data/new/webapp/Gemfile +6 -0
- data/data/new/webapp/app.rb.erb +15 -0
- data/data/new/webapp/config.ru +4 -0
- data/data/new/webapp/docker-compose.yml.erb +9 -0
- data/gemspec.yml +32 -17
- data/lib/ronin/web/cli/command.rb +36 -0
- data/lib/ronin/web/cli/commands/diff.rb +106 -0
- data/lib/ronin/web/cli/commands/html.rb +174 -0
- data/lib/ronin/web/cli/commands/irb.rb +56 -0
- data/lib/ronin/web/cli/commands/new/nokogiri.rb +85 -0
- data/lib/ronin/web/cli/commands/new/server.rb +96 -0
- data/lib/ronin/web/cli/commands/new/spider.rb +315 -0
- data/lib/ronin/web/cli/commands/new/webapp.rb +123 -0
- data/lib/ronin/web/cli/commands/new.rb +64 -0
- data/lib/ronin/web/cli/commands/reverse_proxy.rb +215 -0
- data/lib/ronin/web/cli/commands/server.rb +155 -0
- data/lib/ronin/web/cli/commands/spider.rb +822 -0
- data/lib/ronin/web/cli/ruby_shell.rb +50 -0
- data/lib/ronin/web/cli.rb +44 -0
- data/lib/ronin/web/html.rb +85 -0
- data/lib/ronin/web/mechanize.rb +79 -0
- data/lib/ronin/web/root.rb +27 -0
- data/lib/ronin/web/version.rb +7 -10
- data/lib/ronin/web/xml.rb +85 -0
- data/lib/ronin/web.rb +372 -13
- data/man/ronin-web-diff.1 +41 -0
- data/man/ronin-web-diff.1.md +30 -0
- data/man/ronin-web-html.1 +89 -0
- data/man/ronin-web-html.1.md +66 -0
- data/man/ronin-web-irb.1 +31 -0
- data/man/ronin-web-irb.1.md +22 -0
- data/man/ronin-web-new-nokogiri.1 +41 -0
- data/man/ronin-web-new-nokogiri.1.md +30 -0
- data/man/ronin-web-new-server.1 +45 -0
- data/man/ronin-web-new-server.1.md +33 -0
- data/man/ronin-web-new-spider.1 +173 -0
- data/man/ronin-web-new-spider.1.md +129 -0
- data/man/ronin-web-new-webapp.1 +53 -0
- data/man/ronin-web-new-webapp.1.md +39 -0
- data/man/ronin-web-new.1 +59 -0
- data/man/ronin-web-new.1.md +44 -0
- data/man/ronin-web-reverse-proxy.1 +63 -0
- data/man/ronin-web-reverse-proxy.1.md +47 -0
- data/man/ronin-web-server.1 +59 -0
- data/man/ronin-web-server.1.md +43 -0
- data/man/ronin-web-spider.1 +225 -0
- data/man/ronin-web-spider.1.md +168 -0
- data/man/ronin-web.1 +41 -0
- data/man/ronin-web.1.md +30 -0
- data/ronin-web.gemspec +57 -11
- data/spec/cli/ruby_shell_spec.rb +14 -0
- data/spec/html_spec.rb +43 -0
- data/spec/mechanize_spec.rb +72 -0
- data/spec/spec_helper.rb +5 -3
- data/spec/web_spec.rb +97 -0
- data/spec/xml_spec.rb +42 -0
- metadata +237 -217
- data/.gemtest +0 -0
- data/lib/ronin/network/mixins/web.rb +0 -256
- data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
- data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
- data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
- data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
- data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
- data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
- data/lib/ronin/web/extensions/nokogiri.rb +0 -23
- data/lib/ronin/web/extensions.rb +0 -23
- data/lib/ronin/web/middleware/base.rb +0 -144
- data/lib/ronin/web/middleware/directories.rb +0 -179
- data/lib/ronin/web/middleware/files.rb +0 -144
- data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
- data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
- data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
- data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters.rb +0 -28
- data/lib/ronin/web/middleware/helpers.rb +0 -145
- data/lib/ronin/web/middleware/proxy.rb +0 -265
- data/lib/ronin/web/middleware/proxy_request.rb +0 -262
- data/lib/ronin/web/middleware/request.rb +0 -79
- data/lib/ronin/web/middleware/response.rb +0 -33
- data/lib/ronin/web/middleware/router.rb +0 -167
- data/lib/ronin/web/middleware/rule.rb +0 -103
- data/lib/ronin/web/middleware.rb +0 -27
- data/lib/ronin/web/proxy/app.rb +0 -32
- data/lib/ronin/web/proxy/base.rb +0 -46
- data/lib/ronin/web/proxy/web.rb +0 -46
- data/lib/ronin/web/proxy.rb +0 -25
- data/lib/ronin/web/server/app.rb +0 -32
- data/lib/ronin/web/server/base.rb +0 -461
- data/lib/ronin/web/server/web.rb +0 -66
- data/lib/ronin/web/server.rb +0 -25
- data/lib/ronin/web/spider.rb +0 -115
- data/lib/ronin/web/web.rb +0 -573
- data/spec/helpers/output.rb +0 -3
- data/spec/web/extensions/nokogiri_spec.rb +0 -38
- data/spec/web/helpers/rack_app.rb +0 -31
- data/spec/web/helpers/root/test1/index.html +0 -1
- data/spec/web/helpers/root/test1/test1.txt +0 -1
- data/spec/web/helpers/root/test1.txt +0 -1
- data/spec/web/helpers/root/test2/test2.txt +0 -1
- data/spec/web/helpers/root/test2.txt +0 -1
- data/spec/web/helpers/root/test3/test3.txt +0 -1
- data/spec/web/helpers/root/test3.txt +0 -1
- data/spec/web/helpers/root.rb +0 -15
- data/spec/web/middleware/directories_spec.rb +0 -86
- data/spec/web/middleware/files_spec.rb +0 -57
- data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
- data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
- data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
- data/spec/web/middleware/proxy_spec.rb +0 -67
- data/spec/web/middleware/response_spec.rb +0 -20
- data/spec/web/middleware/router_spec.rb +0 -65
- data/spec/web/middleware/rule_spec.rb +0 -37
- data/spec/web/proxy/base_spec.rb +0 -8
- data/spec/web/server/base_spec.rb +0 -77
- data/spec/web/server/classes/public1/static1.txt +0 -1
- data/spec/web/server/classes/public2/static2.txt +0 -1
- data/spec/web/server/classes/sub_app.rb +0 -13
- data/spec/web/server/classes/test_app.rb +0 -20
- data/spec/web/web_spec.rb +0 -157
@@ -1,262 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/web/middleware/request'
|
24
|
-
|
25
|
-
module Ronin
|
26
|
-
module Web
|
27
|
-
module Middleware
|
28
|
-
class ProxyRequest < Request
|
29
|
-
|
30
|
-
#
|
31
|
-
# Changes the HTTP Host header of the request.
|
32
|
-
#
|
33
|
-
# @param [String] new_host
|
34
|
-
# The new value of the HTTP Host header.
|
35
|
-
#
|
36
|
-
# @return [String]
|
37
|
-
# The new HTTP Host header.
|
38
|
-
#
|
39
|
-
# @since 0.3.0
|
40
|
-
#
|
41
|
-
# @api public
|
42
|
-
#
|
43
|
-
def host=(new_host)
|
44
|
-
@env['HTTP_HOST'] = new_host
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Changes the port the request is being sent to.
|
49
|
-
#
|
50
|
-
# @param [Integer] new_port
|
51
|
-
# The new port the request will be sent to.
|
52
|
-
#
|
53
|
-
# @return [Integer]
|
54
|
-
# The new port the request will be sent to.
|
55
|
-
#
|
56
|
-
# @since 0.3.0
|
57
|
-
#
|
58
|
-
# @api public
|
59
|
-
#
|
60
|
-
def port=(new_port)
|
61
|
-
@env['SERVER_PORT'] = new_port
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Changes the URI scheme of the request.
|
66
|
-
#
|
67
|
-
# @param [String] new_port
|
68
|
-
# The new URI scheme for the request.
|
69
|
-
#
|
70
|
-
# @return [String]
|
71
|
-
# The new URI scheme of the request.
|
72
|
-
#
|
73
|
-
# @since 0.3.0
|
74
|
-
#
|
75
|
-
# @api public
|
76
|
-
#
|
77
|
-
def scheme=(new_scheme)
|
78
|
-
@env['rack.url_scheme'] = new_scheme
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# Causes the request to be proxied over SSL.
|
83
|
-
#
|
84
|
-
# @return [ProxyRequest]
|
85
|
-
# The proxy request.
|
86
|
-
#
|
87
|
-
# @since 0.3.0
|
88
|
-
#
|
89
|
-
# @api public
|
90
|
-
#
|
91
|
-
def ssl!
|
92
|
-
self.port = 443
|
93
|
-
self.scheme = 'https'
|
94
|
-
|
95
|
-
return self
|
96
|
-
end
|
97
|
-
|
98
|
-
#
|
99
|
-
# Changes the HTTP Request Method of the request.
|
100
|
-
#
|
101
|
-
# @param [String] new_method
|
102
|
-
# The new HTTP Request Method.
|
103
|
-
#
|
104
|
-
# @return [String]
|
105
|
-
# The new HTTP Request Method.
|
106
|
-
#
|
107
|
-
# @since 0.3.0
|
108
|
-
#
|
109
|
-
# @api public
|
110
|
-
#
|
111
|
-
def request_method=(new_method)
|
112
|
-
@env['REQUEST_METHOD'] = new_method
|
113
|
-
end
|
114
|
-
|
115
|
-
alias path= path_info=
|
116
|
-
|
117
|
-
#
|
118
|
-
# Changes the HTTP Query String of the request.
|
119
|
-
#
|
120
|
-
# @param [String] new_query
|
121
|
-
# The new HTTP Query String for the request.
|
122
|
-
#
|
123
|
-
# @return [String]
|
124
|
-
# The new HTTP Query String of the request.
|
125
|
-
#
|
126
|
-
# @since 0.3.0
|
127
|
-
#
|
128
|
-
# @api public
|
129
|
-
#
|
130
|
-
def query_string=(new_query)
|
131
|
-
@env['QUERY_STRING'] = new_query
|
132
|
-
end
|
133
|
-
|
134
|
-
#
|
135
|
-
# Determines if the request is an XML-HTTP Request.
|
136
|
-
#
|
137
|
-
# @return [Boolean]
|
138
|
-
# Specifies whether the request is XML-HTTP.
|
139
|
-
#
|
140
|
-
# @since 0.3.0
|
141
|
-
#
|
142
|
-
# @api public
|
143
|
-
#
|
144
|
-
def xhr?
|
145
|
-
@env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
|
146
|
-
end
|
147
|
-
|
148
|
-
#
|
149
|
-
# Specifies that the request is a XML HTTP Request.
|
150
|
-
#
|
151
|
-
# @yield [request]
|
152
|
-
# If a block is given, it will be passed the request
|
153
|
-
# for further modification.
|
154
|
-
#
|
155
|
-
# @yieldparam [ProxyRequest] request
|
156
|
-
# The proxy request.
|
157
|
-
#
|
158
|
-
# @return [ProxyRequest]
|
159
|
-
# The request.
|
160
|
-
#
|
161
|
-
# @since 0.3.0
|
162
|
-
#
|
163
|
-
# @api public
|
164
|
-
#
|
165
|
-
def xhr!
|
166
|
-
@env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
167
|
-
|
168
|
-
yield self if block_given?
|
169
|
-
return self
|
170
|
-
end
|
171
|
-
|
172
|
-
#
|
173
|
-
# Changes the HTTP Content-Type header of the request.
|
174
|
-
#
|
175
|
-
# @param [String] new_content_type
|
176
|
-
# The new HTTP Content-Type for the request.
|
177
|
-
#
|
178
|
-
# @return [String]
|
179
|
-
# The new HTTP Content-Type of the request.
|
180
|
-
#
|
181
|
-
# @since 0.3.0
|
182
|
-
#
|
183
|
-
# @api public
|
184
|
-
#
|
185
|
-
def content_type=(new_content_type)
|
186
|
-
@env['CONTENT_TYPE'] = new_content_type
|
187
|
-
end
|
188
|
-
|
189
|
-
#
|
190
|
-
# Changes the HTTP Accept-Encoding header of the request.
|
191
|
-
#
|
192
|
-
# @param [String] new_encoding
|
193
|
-
# The new HTTP Accept-Encoding for the request.
|
194
|
-
#
|
195
|
-
# @return [String]
|
196
|
-
# The new HTTP Accept-Encoding of the request.
|
197
|
-
#
|
198
|
-
# @since 0.3.0
|
199
|
-
#
|
200
|
-
# @api public
|
201
|
-
#
|
202
|
-
def accept_encoding=(new_encoding)
|
203
|
-
@env['HTTP_ACCEPT_ENCODING'] = new_encoding
|
204
|
-
end
|
205
|
-
|
206
|
-
#
|
207
|
-
# Sets the HTTP User-Agent header of the request.
|
208
|
-
#
|
209
|
-
# @param [String] new_user_agent
|
210
|
-
# The new User-Agent header to use.
|
211
|
-
#
|
212
|
-
# @return [String]
|
213
|
-
# The new User-Agent header.
|
214
|
-
#
|
215
|
-
# @since 0.3.0
|
216
|
-
#
|
217
|
-
# @api public
|
218
|
-
#
|
219
|
-
def user_agent=(new_user_agent)
|
220
|
-
@env['HTTP_USER_AGENT'] = new_user_agent
|
221
|
-
end
|
222
|
-
|
223
|
-
#
|
224
|
-
# Changes the HTTP Referer header of the request.
|
225
|
-
#
|
226
|
-
# @param [String] new_referer
|
227
|
-
# The new HTTP Referer for the request.
|
228
|
-
#
|
229
|
-
# @return [String]
|
230
|
-
# The new HTTP Referer of the request.
|
231
|
-
#
|
232
|
-
# @since 0.3.0
|
233
|
-
#
|
234
|
-
# @api public
|
235
|
-
#
|
236
|
-
def referer=(new_referer)
|
237
|
-
@env['HTTP_REFERER'] = new_referer
|
238
|
-
end
|
239
|
-
|
240
|
-
alias referrer= referer=
|
241
|
-
|
242
|
-
#
|
243
|
-
# Changes the body of the request.
|
244
|
-
#
|
245
|
-
# @param [String] new_body
|
246
|
-
# The new body for the request.
|
247
|
-
#
|
248
|
-
# @return [String]
|
249
|
-
# The new body of the request.
|
250
|
-
#
|
251
|
-
# @since 0.3.0
|
252
|
-
#
|
253
|
-
# @api public
|
254
|
-
#
|
255
|
-
def body=(new_body)
|
256
|
-
@env['rack.input'] = new_body
|
257
|
-
end
|
258
|
-
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/network/http/http'
|
24
|
-
|
25
|
-
require 'rack'
|
26
|
-
|
27
|
-
module Ronin
|
28
|
-
module Web
|
29
|
-
module Middleware
|
30
|
-
class Request < Rack::Request
|
31
|
-
|
32
|
-
#
|
33
|
-
# Returns the remote IP address and port for the request.
|
34
|
-
#
|
35
|
-
# @param [Hash] env
|
36
|
-
# The request env Hash.
|
37
|
-
#
|
38
|
-
# @return [String]
|
39
|
-
# The IP address and port number.
|
40
|
-
#
|
41
|
-
# @since 0.3.0
|
42
|
-
#
|
43
|
-
# @api semipublic
|
44
|
-
#
|
45
|
-
def address
|
46
|
-
if env.has_key?('REMOTE_PORT')
|
47
|
-
"#{ip}:#{env['REMOTE_PORT']}"
|
48
|
-
else
|
49
|
-
ip
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# The HTTP Headers for the request.
|
55
|
-
#
|
56
|
-
# @return [Hash{String => String}]
|
57
|
-
# The HTTP Headers of the request.
|
58
|
-
#
|
59
|
-
# @since 0.3.0
|
60
|
-
#
|
61
|
-
# @api public
|
62
|
-
#
|
63
|
-
def headers
|
64
|
-
headers = {}
|
65
|
-
|
66
|
-
env.each do |name,value|
|
67
|
-
if name =~ /^HTTP_/
|
68
|
-
header_name = Network::HTTP.header_name(name.sub('HTTP_',''))
|
69
|
-
headers[header_name] = value
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
return headers
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'rack'
|
24
|
-
|
25
|
-
module Ronin
|
26
|
-
module Web
|
27
|
-
module Middleware
|
28
|
-
class Response < Rack::Response
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,167 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/web/middleware/rule'
|
24
|
-
require 'ronin/web/middleware/base'
|
25
|
-
|
26
|
-
module Ronin
|
27
|
-
module Web
|
28
|
-
module Middleware
|
29
|
-
#
|
30
|
-
# A Rack middleware for routing requests based on predefined rules.
|
31
|
-
#
|
32
|
-
# use Ronin::Web::Middleware::Router do |router|
|
33
|
-
# # route requests by source IP address
|
34
|
-
# router.draw :ip => '212.18.45.0/24', :to => BannedApp
|
35
|
-
# router.draw :ip => '192.168.0.0/16' do |request|
|
36
|
-
# response ['Nothing here'], 404
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# # route requests by Referer URL
|
40
|
-
# router.draw :referer => 'http://www.sexy.com/', :to => TrapApp
|
41
|
-
# router.draw :referer => /\.google\./ do |request|
|
42
|
-
# response ['Nothing to see here.'], 404
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# # route requests by User-Agent
|
46
|
-
# router.draw :user_agent => /Microsoft/, :to => IEApp
|
47
|
-
#
|
48
|
-
# # mix route options together
|
49
|
-
# router.draw :ip => '212.18.45.0/24',
|
50
|
-
# :user_agent => /Microsoft/, :to => PwnApp
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
class Router < Base
|
54
|
-
|
55
|
-
# The routes of the router
|
56
|
-
attr_reader :routes
|
57
|
-
|
58
|
-
#
|
59
|
-
# Creates a new Router middleware.
|
60
|
-
#
|
61
|
-
# @param [#call] app
|
62
|
-
# The application that the router sits in front of.
|
63
|
-
#
|
64
|
-
# @param [Hash] options
|
65
|
-
# Additional options.
|
66
|
-
#
|
67
|
-
# @yield [router]
|
68
|
-
# If a block is given, it will be passed the newly created
|
69
|
-
# router middleware.
|
70
|
-
#
|
71
|
-
# @yieldparam [Router] router
|
72
|
-
# The new router middleware object.
|
73
|
-
#
|
74
|
-
# @since 0.3.0
|
75
|
-
#
|
76
|
-
# @api public
|
77
|
-
#
|
78
|
-
def initialize(app,options={},&block)
|
79
|
-
@routes = {}
|
80
|
-
|
81
|
-
super(app,options,&block)
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# Defines a rule to route requests by.
|
86
|
-
#
|
87
|
-
# @param [Hash] options
|
88
|
-
# Filter options.
|
89
|
-
#
|
90
|
-
# @option options [String] :campaign
|
91
|
-
# The name of the campaign who's targetted hosts will be routed.
|
92
|
-
#
|
93
|
-
# @option options [String, Regexp] :vhost
|
94
|
-
# The Virtual-Host to route.
|
95
|
-
#
|
96
|
-
# @option options [String, IPAddr] :ip
|
97
|
-
# The IP address or IP range to route.
|
98
|
-
#
|
99
|
-
# @option options [String, Regexp] :referer
|
100
|
-
# The Referer URL or pattern to route.
|
101
|
-
#
|
102
|
-
# @option options [String, Regexp] :user_agent
|
103
|
-
# The User-Agent string to route.
|
104
|
-
#
|
105
|
-
# @option options [Proc] :when
|
106
|
-
# Custom logic to route requests by.
|
107
|
-
#
|
108
|
-
# @option options [#call] :to
|
109
|
-
# The application that will receive routed requests.
|
110
|
-
#
|
111
|
-
# @yield [request]
|
112
|
-
# If a block is given, it will receive routed requests.
|
113
|
-
#
|
114
|
-
# @yieldparam [Rack::Request] request
|
115
|
-
# A routed request.
|
116
|
-
#
|
117
|
-
# @return [#call]
|
118
|
-
# The application that is being routed.
|
119
|
-
#
|
120
|
-
# @example Route requests going to an application.
|
121
|
-
# router.draw :ip => '210.18.0.0/16', :to => BannedApp
|
122
|
-
#
|
123
|
-
# @example Accept routed requests using a block.
|
124
|
-
# router.draw :ip => '210.18.0.0/16' do |request|
|
125
|
-
# response ['Banned!']
|
126
|
-
# end
|
127
|
-
#
|
128
|
-
# @since 0.3.0
|
129
|
-
#
|
130
|
-
# @api public
|
131
|
-
#
|
132
|
-
def draw(options={},&block)
|
133
|
-
app = (options.delete(:to) || block)
|
134
|
-
|
135
|
-
return @routes[Rule.new(options)] = app
|
136
|
-
end
|
137
|
-
|
138
|
-
#
|
139
|
-
# Filters requests based on the defined routes.
|
140
|
-
#
|
141
|
-
# @param [Hash, Rack::Request] env
|
142
|
-
# An incoming request.
|
143
|
-
#
|
144
|
-
# @return [Array, Response]
|
145
|
-
# A response.
|
146
|
-
#
|
147
|
-
# @since 0.3.0
|
148
|
-
#
|
149
|
-
# @api public
|
150
|
-
#
|
151
|
-
def call(env)
|
152
|
-
request = Request.new(env)
|
153
|
-
|
154
|
-
@routes.each do |rule,app|
|
155
|
-
if rule.match?(request)
|
156
|
-
print_info "Routing #{request.url} for #{request.address}"
|
157
|
-
return app.call(env)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
super(env)
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/web/middleware/filters'
|
24
|
-
|
25
|
-
module Ronin
|
26
|
-
module Web
|
27
|
-
module Middleware
|
28
|
-
#
|
29
|
-
# Matches requests against one or more filters.
|
30
|
-
#
|
31
|
-
class Rule
|
32
|
-
|
33
|
-
# Registered filters
|
34
|
-
FILTERS = {
|
35
|
-
:ip => Filters::IPFilter,
|
36
|
-
:campaign => Filters::CampaignFilter,
|
37
|
-
:path => Filters::PathFilter,
|
38
|
-
:vhost => Filters::VHostFilter,
|
39
|
-
:referer => Filters::RefererFilter,
|
40
|
-
:user_agent => Filters::UserAgentFilter
|
41
|
-
}
|
42
|
-
|
43
|
-
#
|
44
|
-
# Creates a new rule.
|
45
|
-
#
|
46
|
-
# @param [Hash] options
|
47
|
-
# Additional filtering options for the rule.
|
48
|
-
#
|
49
|
-
# @option options [String] :campaign
|
50
|
-
# The name of the campaign who's targetted hosts will be
|
51
|
-
# filtered by.
|
52
|
-
#
|
53
|
-
# @option options [String, Regexp] :vhost
|
54
|
-
# The Virtual-Host to filter.
|
55
|
-
#
|
56
|
-
# @option options [String, IPAddr] :ip
|
57
|
-
# The IP address or IP range to filter.
|
58
|
-
#
|
59
|
-
# @option options [String, Regexp] :referer
|
60
|
-
# The Referer URL or pattern to filter.
|
61
|
-
#
|
62
|
-
# @option options [String, Regexp] :user_agent
|
63
|
-
# The User-Agent string to filter.
|
64
|
-
#
|
65
|
-
# @option options [Proc] :when
|
66
|
-
# Custom logic to filter requests by.
|
67
|
-
#
|
68
|
-
# @since 0.3.0
|
69
|
-
#
|
70
|
-
# @api public
|
71
|
-
#
|
72
|
-
def initialize(options={},&block)
|
73
|
-
@filters = []
|
74
|
-
@when_block = options.delete(:when)
|
75
|
-
|
76
|
-
options.each do |name,value|
|
77
|
-
if FILTERS.has_key?(name)
|
78
|
-
@filters << FILTERS[name].new(value)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Matches a request against the rule.
|
85
|
-
#
|
86
|
-
# @param [Rack::Request] request
|
87
|
-
# The request to match.
|
88
|
-
#
|
89
|
-
# @return [Boolean]
|
90
|
-
# Specifies if the request matches all of the filters.
|
91
|
-
#
|
92
|
-
# @api public
|
93
|
-
#
|
94
|
-
def match?(request)
|
95
|
-
@filters.all? { |filter|
|
96
|
-
filter.match?(request)
|
97
|
-
} && (@when_block.nil? || (@when_block.call(request) ? true : false))
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
data/lib/ronin/web/middleware.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/web/middleware/base'
|
24
|
-
require 'ronin/web/middleware/files'
|
25
|
-
require 'ronin/web/middleware/directories'
|
26
|
-
require 'ronin/web/middleware/router'
|
27
|
-
require 'ronin/web/middleware/proxy'
|
data/lib/ronin/web/proxy/app.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/web/proxy/base'
|
24
|
-
|
25
|
-
module Ronin
|
26
|
-
module Web
|
27
|
-
module Proxy
|
28
|
-
class App < Base
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|