ronin-web 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +25 -0
- data/Manifest.txt +36 -4
- data/README.txt +67 -64
- data/Rakefile +12 -3
- data/bin/ronin-web +1 -1
- data/lib/ronin/network/helpers/web.rb +221 -0
- data/lib/ronin/web.rb +1 -2
- data/lib/ronin/web/extensions.rb +0 -2
- data/lib/ronin/web/extensions/nokogiri.rb +0 -23
- data/lib/ronin/web/proxy.rb +3 -103
- data/lib/ronin/web/proxy/app.rb +31 -0
- data/lib/ronin/web/proxy/base.rb +41 -0
- data/lib/ronin/web/proxy/web.rb +42 -0
- data/lib/ronin/web/server.rb +3 -530
- data/lib/ronin/web/server/app.rb +31 -0
- data/lib/ronin/web/server/base.rb +334 -0
- data/lib/ronin/web/server/files.rb +92 -0
- data/lib/ronin/web/server/helpers.rb +25 -0
- data/lib/ronin/web/server/helpers/files.rb +126 -0
- data/lib/ronin/web/server/helpers/hosts.rb +72 -0
- data/lib/ronin/web/server/helpers/proxy.rb +153 -0
- data/lib/ronin/web/server/helpers/rendering.rb +36 -0
- data/lib/ronin/web/server/hosts.rb +86 -0
- data/lib/ronin/web/server/proxy.rb +116 -0
- data/lib/ronin/web/server/web.rb +62 -0
- data/lib/ronin/web/spider.rb +53 -26
- data/lib/ronin/web/version.rb +1 -3
- data/lib/ronin/web/web.rb +253 -95
- data/spec/spec_helper.rb +1 -1
- data/spec/web/proxy/base_spec.rb +9 -0
- data/spec/web/server/base_spec.rb +86 -0
- data/spec/web/server/classes/files/dir/file.txt +1 -0
- data/spec/web/server/classes/files/dir/index.html +1 -0
- data/spec/web/server/classes/files/dir2/file2.txt +1 -0
- data/spec/web/server/classes/files/dir3/page.xml +4 -0
- data/spec/web/server/classes/files/file.txt +1 -0
- data/spec/web/server/classes/files_app.rb +27 -0
- data/spec/web/server/classes/hosts_app.rb +40 -0
- data/spec/web/server/classes/proxy_app.rb +45 -0
- data/spec/web/server/classes/public1/static1.txt +1 -0
- data/spec/web/server/classes/public2/static2.txt +1 -0
- data/spec/web/server/classes/sub_app.rb +13 -0
- data/spec/web/server/classes/test_app.rb +20 -0
- data/spec/web/server/files_spec.rb +74 -0
- data/spec/web/server/helpers/server.rb +42 -0
- data/spec/web/server/hosts_spec.rb +55 -0
- data/spec/web/server/proxy_spec.rb +49 -0
- data/tasks/spec.rb +1 -0
- data/tasks/yard.rb +13 -0
- metadata +76 -17
- metadata.gz.sig +0 -0
- data/TODO.txt +0 -7
- data/lib/ronin/sessions/web.rb +0 -80
- data/lib/ronin/web/fingerprint.rb +0 -76
- data/spec/web/server_spec.rb +0 -142
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation; either version 2 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program 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 General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'ronin/web/server/base'
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module Web
|
26
|
+
module Server
|
27
|
+
class App < Base
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,334 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation; either version 2 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program 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 General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'ronin/web/server/helpers/rendering'
|
23
|
+
require 'ronin/web/server/helpers/proxy'
|
24
|
+
require 'ronin/web/server/files'
|
25
|
+
require 'ronin/web/server/hosts'
|
26
|
+
require 'ronin/static/finders'
|
27
|
+
require 'ronin/templates/erb'
|
28
|
+
require 'ronin/ui/output'
|
29
|
+
require 'ronin/extensions/meta'
|
30
|
+
|
31
|
+
require 'set'
|
32
|
+
require 'thread'
|
33
|
+
require 'rack'
|
34
|
+
require 'sinatra'
|
35
|
+
|
36
|
+
module Ronin
|
37
|
+
module Web
|
38
|
+
module Server
|
39
|
+
class Base < Sinatra::Base
|
40
|
+
|
41
|
+
include Static::Finders
|
42
|
+
include Rack::Utils
|
43
|
+
include Templates::Erb
|
44
|
+
extend UI::Output
|
45
|
+
|
46
|
+
include Files
|
47
|
+
include Hosts
|
48
|
+
|
49
|
+
# Default interface to run the Web Server on
|
50
|
+
DEFAULT_HOST = '0.0.0.0'
|
51
|
+
|
52
|
+
# Default port to run the Web Server on
|
53
|
+
DEFAULT_PORT = 8000
|
54
|
+
|
55
|
+
# Default list of index file-names to search for in directories
|
56
|
+
DEFAULT_INDICES = ['index.html', 'index.htm']
|
57
|
+
|
58
|
+
# Directory to search for views within
|
59
|
+
VIEWS_DIR = File.join('ronin','web','server','views')
|
60
|
+
|
61
|
+
set :host, DEFAULT_HOST
|
62
|
+
set :port, DEFAULT_PORT
|
63
|
+
|
64
|
+
#
|
65
|
+
# The default Rack Handler to run all web servers with.
|
66
|
+
#
|
67
|
+
# @return [String]
|
68
|
+
# The class name of the Rack Handler to use.
|
69
|
+
#
|
70
|
+
# @since 0.2.0
|
71
|
+
#
|
72
|
+
def Base.handler
|
73
|
+
@@ronin_web_server_handler ||= nil
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Sets the default Rack Handler to run all web servers with.
|
78
|
+
#
|
79
|
+
# @param [String] name
|
80
|
+
# The name of the handler.
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
# The name of the new handler.
|
84
|
+
#
|
85
|
+
# @since 0.2.0
|
86
|
+
#
|
87
|
+
def Base.handler=(name)
|
88
|
+
@@ronin_web_server_handler = name
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# The list of index files to search for when requesting the
|
93
|
+
# contents of a directory.
|
94
|
+
#
|
95
|
+
# @return [Set]
|
96
|
+
# The names of index files.
|
97
|
+
#
|
98
|
+
# @since 0.2.0
|
99
|
+
#
|
100
|
+
def Base.indices
|
101
|
+
@@ronin_web_server_indices ||= Set[*DEFAULT_INDICES]
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Adds a new index to the +Base.indices+ list.
|
106
|
+
#
|
107
|
+
# @param [String, Symbol] name
|
108
|
+
# The index name to add.
|
109
|
+
#
|
110
|
+
# @since 0.2.0
|
111
|
+
#
|
112
|
+
def Base.index(name)
|
113
|
+
Base.indices << name.to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# The list of Rack Handlers to attempt to use with the web server.
|
118
|
+
#
|
119
|
+
# @return [Array]
|
120
|
+
# The names of handler classes.
|
121
|
+
#
|
122
|
+
# @since 0.2.0
|
123
|
+
#
|
124
|
+
def self.handlers
|
125
|
+
handlers = self.server
|
126
|
+
|
127
|
+
if Base.handler
|
128
|
+
handlers = [Base.handler] + handlers
|
129
|
+
end
|
130
|
+
|
131
|
+
return handlers
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# Attempts to load the desired Rack Handler to run the web server
|
136
|
+
# with.
|
137
|
+
#
|
138
|
+
# @return [Rack::Handler]
|
139
|
+
# The handler class to use to run the web server.
|
140
|
+
#
|
141
|
+
# @raise [StandardError]
|
142
|
+
# None of the handlers could be loaded.
|
143
|
+
#
|
144
|
+
# @since 0.2.0
|
145
|
+
#
|
146
|
+
def self.handler_class
|
147
|
+
self.handlers.find do |name|
|
148
|
+
begin
|
149
|
+
return Rack::Handler.get(name)
|
150
|
+
rescue Gem::LoadError => e
|
151
|
+
raise(e)
|
152
|
+
rescue NameError, ::LoadError
|
153
|
+
next
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
raise(StandardError,"unable to find any Rack handlers",caller)
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# Run the web server using the Rack Handler returned by
|
162
|
+
# +handler_class+.
|
163
|
+
#
|
164
|
+
# @param [Hash] options Additional options.
|
165
|
+
#
|
166
|
+
# @option options [String] :host
|
167
|
+
# The host the server will listen on.
|
168
|
+
#
|
169
|
+
# @option options [Integer] :port
|
170
|
+
# The port the server will bind to.
|
171
|
+
#
|
172
|
+
# @option options [Boolean] :background (false)
|
173
|
+
# Specifies wether the server will run in the background or run
|
174
|
+
# in the foreground.
|
175
|
+
#
|
176
|
+
# @since 0.2.0
|
177
|
+
#
|
178
|
+
def self.run!(options={})
|
179
|
+
rack_options = {
|
180
|
+
:Host => (options[:host] || self.host),
|
181
|
+
:Port => (options[:port] || self.port)
|
182
|
+
}
|
183
|
+
|
184
|
+
runner = lambda { |handler,server,options|
|
185
|
+
print_info "Starting Web Server on #{options[:Host]}:#{options[:Port]}"
|
186
|
+
print_debug "Using Web Server handler #{handler}"
|
187
|
+
|
188
|
+
handler.run(server,options) do |server|
|
189
|
+
trap(:INT) do
|
190
|
+
# Use thins' hard #stop! if available,
|
191
|
+
# otherwise just #stop
|
192
|
+
server.respond_to?(:stop!) ? server.stop! : server.stop
|
193
|
+
end
|
194
|
+
|
195
|
+
set :running, true
|
196
|
+
end
|
197
|
+
}
|
198
|
+
|
199
|
+
handler = self.handler_class
|
200
|
+
|
201
|
+
if options[:background]
|
202
|
+
Thread.new(handler,self,rack_options,&runner)
|
203
|
+
else
|
204
|
+
runner.call(handler,self,rack_options)
|
205
|
+
end
|
206
|
+
|
207
|
+
return self
|
208
|
+
end
|
209
|
+
|
210
|
+
#
|
211
|
+
# Route any type of request for a given URL pattern.
|
212
|
+
#
|
213
|
+
# @param [String] path
|
214
|
+
# The URL pattern to handle requests for.
|
215
|
+
#
|
216
|
+
# @yield []
|
217
|
+
# The block that will handle the request.
|
218
|
+
#
|
219
|
+
# @example
|
220
|
+
# any '/submit' do
|
221
|
+
# puts request.inspect
|
222
|
+
# end
|
223
|
+
#
|
224
|
+
# @since 0.2.0
|
225
|
+
#
|
226
|
+
def self.any(path,options={},&block)
|
227
|
+
get(path,options,&block)
|
228
|
+
put(path,options,&block)
|
229
|
+
post(path,options,&block)
|
230
|
+
delete(path,options,&block)
|
231
|
+
end
|
232
|
+
|
233
|
+
#
|
234
|
+
# Sets the default route.
|
235
|
+
#
|
236
|
+
# @yield []
|
237
|
+
# The block that will handle all other requests.
|
238
|
+
#
|
239
|
+
# @example
|
240
|
+
# default do
|
241
|
+
# status 200
|
242
|
+
# content_type :html
|
243
|
+
#
|
244
|
+
# %{
|
245
|
+
# <html>
|
246
|
+
# <body>
|
247
|
+
# <center><h1>YOU LOSE THE GAME</h1></center>
|
248
|
+
# </body>
|
249
|
+
# </html>
|
250
|
+
# }
|
251
|
+
# end
|
252
|
+
#
|
253
|
+
# @since 0.2.0
|
254
|
+
#
|
255
|
+
def self.default(&block)
|
256
|
+
class_def(:default_response,&block)
|
257
|
+
return self
|
258
|
+
end
|
259
|
+
|
260
|
+
#
|
261
|
+
# Routes all requests within a given directory into another
|
262
|
+
# web server.
|
263
|
+
#
|
264
|
+
# @param [String] dir
|
265
|
+
# The directory that requests for will be routed from.
|
266
|
+
#
|
267
|
+
# @param [Base, #call] server
|
268
|
+
# The web server to route requests to.
|
269
|
+
#
|
270
|
+
# @example
|
271
|
+
# MyApp.map '/subapp/', SubApp
|
272
|
+
#
|
273
|
+
# @since 0.2.0
|
274
|
+
#
|
275
|
+
def self.map(dir,server)
|
276
|
+
dir = File.join(dir,'')
|
277
|
+
|
278
|
+
before do
|
279
|
+
if dir == request.path_info[0,dir.length]
|
280
|
+
# remove the dir from the beginning of the path
|
281
|
+
# before passing it to the server
|
282
|
+
request.env['PATH_INFO'] = request.path_info[dir.length-1..-1]
|
283
|
+
|
284
|
+
halt(*server.call(request.env))
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
#
|
290
|
+
# Hosts the static contents within a given directory.
|
291
|
+
#
|
292
|
+
# @param [String] directory
|
293
|
+
# The path to a directory to serve static content from.
|
294
|
+
#
|
295
|
+
# @example
|
296
|
+
# MyApp.public_dir 'path/to/another/public'
|
297
|
+
#
|
298
|
+
# @since 0.2.0
|
299
|
+
#
|
300
|
+
def self.public_dir(directory)
|
301
|
+
directory = File.expand_path(directory)
|
302
|
+
|
303
|
+
before do
|
304
|
+
sub_path = File.expand_path(File.join('',request.path_info))
|
305
|
+
full_path = File.join(directory,sub_path)
|
306
|
+
|
307
|
+
return_file(full_path) if File.file?(full_path)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
protected
|
312
|
+
|
313
|
+
#
|
314
|
+
# Returns an HTTP 404 response with an empty body.
|
315
|
+
#
|
316
|
+
# @since 0.2.0
|
317
|
+
#
|
318
|
+
def default_response
|
319
|
+
halt 404, ''
|
320
|
+
end
|
321
|
+
|
322
|
+
enable :sessions
|
323
|
+
|
324
|
+
helpers Helpers::Rendering
|
325
|
+
helpers Helpers::Proxy
|
326
|
+
|
327
|
+
not_found do
|
328
|
+
default_response
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#
|
2
|
+
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
+
# scraping and spidering functionality.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation; either version 2 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program 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 General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program; if not, write to the Free Software
|
19
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'ronin/web/server/helpers/files'
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module Web
|
26
|
+
module Server
|
27
|
+
module Files
|
28
|
+
def self.included(base)
|
29
|
+
base.module_eval do
|
30
|
+
#
|
31
|
+
# Hosts the contents of a file.
|
32
|
+
#
|
33
|
+
# @param [String] http_path
|
34
|
+
# The path the web server will host the file at.
|
35
|
+
#
|
36
|
+
# @param [String] path
|
37
|
+
# The path to the local file.
|
38
|
+
#
|
39
|
+
# @param [Symbol] custom_content_type
|
40
|
+
# Optional content-type to host the file as.
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# MyApp.file '/robots.txt', '/path/to/my_robots.txt'
|
44
|
+
#
|
45
|
+
# @since 0.2.0
|
46
|
+
#
|
47
|
+
def self.file(http_path,path,custom_content_type=nil)
|
48
|
+
path = File.expand_path(path)
|
49
|
+
|
50
|
+
any(http_path) do
|
51
|
+
return_file(path,custom_content_type)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Hosts the contents of the directory.
|
57
|
+
#
|
58
|
+
# @param [String] http_path
|
59
|
+
# The path the web server will host the directory at.
|
60
|
+
#
|
61
|
+
# @param [String] directory
|
62
|
+
# The path to the local directory.
|
63
|
+
#
|
64
|
+
# @param [Symbol] custom_content_type
|
65
|
+
# Optional content-type to host the contents of the directory
|
66
|
+
# with.
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# MyApp.directory '/download/', '/tmp/files/'
|
70
|
+
#
|
71
|
+
# @since 0.2.0
|
72
|
+
#
|
73
|
+
def self.directory(http_path,directory,custom_content_type=nil)
|
74
|
+
directory = File.expand_path(directory)
|
75
|
+
|
76
|
+
any(File.join(http_path,'*')) do
|
77
|
+
sub_path = File.expand_path(File.join('',params[:splat].first))
|
78
|
+
full_path = File.join(directory,sub_path)
|
79
|
+
|
80
|
+
return_file(full_path,custom_content_type)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
helpers Ronin::Web::Server::Helpers::Files
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|