ronin-web 0.2.1 → 0.3.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.gemtest +0 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/COPYING.txt +674 -0
- data/{History.txt → ChangeLog.md} +39 -8
- data/Gemfile +49 -0
- data/{README.txt → README.md} +56 -40
- data/Rakefile +25 -24
- data/bin/ronin-web +18 -5
- data/gemspec.yml +30 -0
- data/lib/ronin/network/{helpers → mixins}/web.rb +74 -39
- data/lib/ronin/web.rb +7 -6
- data/lib/ronin/web/extensions.rb +7 -6
- data/lib/ronin/web/extensions/nokogiri.rb +22 -0
- data/lib/ronin/web/extensions/nokogiri/xml.rb +22 -0
- data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +35 -1
- data/lib/ronin/web/extensions/nokogiri/xml/document.rb +34 -4
- data/lib/ronin/web/extensions/nokogiri/xml/element.rb +36 -2
- data/lib/ronin/web/extensions/nokogiri/xml/node.rb +59 -20
- data/lib/ronin/web/extensions/nokogiri/xml/text.rb +36 -2
- data/lib/ronin/web/middleware.rb +27 -0
- data/lib/ronin/web/middleware/base.rb +144 -0
- data/lib/ronin/web/middleware/directories.rb +177 -0
- data/lib/ronin/web/middleware/files.rb +142 -0
- data/lib/ronin/web/middleware/filters.rb +28 -0
- data/lib/ronin/web/middleware/filters/campaign_filter.rb +77 -0
- data/lib/ronin/web/middleware/filters/ip_filter.rb +73 -0
- data/lib/ronin/web/middleware/filters/path_filter.rb +73 -0
- data/lib/ronin/web/middleware/filters/referer_filter.rb +71 -0
- data/lib/ronin/web/middleware/filters/user_agent_filter.rb +71 -0
- data/lib/ronin/web/middleware/filters/vhost_filter.rb +71 -0
- data/lib/ronin/web/middleware/helpers.rb +145 -0
- data/lib/ronin/web/middleware/proxy.rb +265 -0
- data/lib/ronin/web/middleware/proxy_request.rb +262 -0
- data/lib/ronin/web/middleware/request.rb +58 -0
- data/lib/ronin/web/middleware/response.rb +33 -0
- data/lib/ronin/web/middleware/router.rb +167 -0
- data/lib/ronin/web/middleware/rule.rb +103 -0
- data/lib/ronin/web/proxy.rb +7 -6
- data/lib/ronin/web/proxy/app.rb +7 -6
- data/lib/ronin/web/proxy/base.rb +14 -9
- data/lib/ronin/web/proxy/web.rb +9 -6
- data/lib/ronin/web/server.rb +7 -6
- data/lib/ronin/web/server/app.rb +7 -6
- data/lib/ronin/web/server/base.rb +209 -82
- data/lib/ronin/web/server/web.rb +10 -6
- data/lib/ronin/web/spider.rb +38 -26
- data/lib/ronin/web/version.rb +8 -7
- data/lib/ronin/web/web.rb +122 -80
- data/ronin-web.gemspec +15 -0
- data/spec/helpers/output.rb +3 -0
- data/spec/spec_helper.rb +2 -3
- data/spec/web/extensions/nokogiri_spec.rb +7 -7
- data/spec/web/{server/helpers/server.rb → helpers/rack_app.rb} +3 -14
- data/spec/web/helpers/root.rb +15 -0
- data/spec/web/helpers/root/test1.txt +1 -0
- data/spec/web/helpers/root/test1/index.html +1 -0
- data/spec/web/helpers/root/test1/test1.txt +1 -0
- data/spec/web/helpers/root/test2.txt +1 -0
- data/spec/web/helpers/root/test2/test2.txt +1 -0
- data/spec/web/helpers/root/test3.txt +1 -0
- data/spec/web/helpers/root/test3/test3.txt +1 -0
- data/spec/web/middleware/directories_spec.rb +86 -0
- data/spec/web/middleware/files_spec.rb +57 -0
- data/spec/web/middleware/filters/campaign_filter_spec.rb +30 -0
- data/spec/web/middleware/filters/ip_filter_spec.rb +25 -0
- data/spec/web/middleware/filters/path_filter_spec.rb +29 -0
- data/spec/web/middleware/filters/referer_filter_spec.rb +25 -0
- data/spec/web/middleware/filters/user_agent_filter_spec.rb +25 -0
- data/spec/web/middleware/filters/vhost_filter_spec.rb +23 -0
- data/spec/web/middleware/proxy_spec.rb +67 -0
- data/spec/web/middleware/response_spec.rb +20 -0
- data/spec/web/middleware/router_spec.rb +65 -0
- data/spec/web/middleware/rule_spec.rb +37 -0
- data/spec/web/proxy/base_spec.rb +1 -2
- data/spec/web/server/base_spec.rb +4 -13
- data/spec/web/server/classes/sub_app.rb +2 -2
- data/spec/web/server/classes/test_app.rb +1 -1
- data/spec/web/web_spec.rb +57 -67
- metadata +171 -146
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -64
- data/lib/ronin/scanners/web.rb +0 -52
- data/lib/ronin/web/server/files.rb +0 -92
- data/lib/ronin/web/server/helpers.rb +0 -25
- data/lib/ronin/web/server/helpers/files.rb +0 -126
- data/lib/ronin/web/server/helpers/hosts.rb +0 -72
- data/lib/ronin/web/server/helpers/proxy.rb +0 -153
- data/lib/ronin/web/server/helpers/rendering.rb +0 -36
- data/lib/ronin/web/server/hosts.rb +0 -86
- data/lib/ronin/web/server/proxy.rb +0 -116
- data/spec/scanners/web_spec.rb +0 -24
- data/spec/web/helpers/root/index.html +0 -1
- data/spec/web/helpers/root/test.txt +0 -1
- data/spec/web/helpers/server.rb +0 -10
- data/spec/web/server/classes/files/dir/file.txt +0 -1
- data/spec/web/server/classes/files/dir/index.html +0 -1
- data/spec/web/server/classes/files/dir2/file2.txt +0 -1
- data/spec/web/server/classes/files/dir3/page.xml +0 -4
- data/spec/web/server/classes/files/file.txt +0 -1
- data/spec/web/server/classes/files_app.rb +0 -27
- data/spec/web/server/classes/hosts_app.rb +0 -40
- data/spec/web/server/classes/proxy_app.rb +0 -45
- data/spec/web/server/files_spec.rb +0 -74
- data/spec/web/server/hosts_spec.rb +0 -55
- data/spec/web/server/proxy_spec.rb +0 -49
- data/tasks/spec.rb +0 -10
- data/tasks/yard.rb +0 -13
- metadata.gz.sig +0 -3
@@ -0,0 +1,103 @@
|
|
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/proxy.rb
CHANGED
@@ -2,21 +2,22 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
23
|
require 'ronin/web/proxy/base'
|
data/lib/ronin/web/proxy/app.rb
CHANGED
@@ -2,21 +2,22 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
23
|
require 'ronin/web/proxy/base'
|
data/lib/ronin/web/proxy/base.rb
CHANGED
@@ -2,28 +2,35 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
23
|
require 'ronin/web/server/base'
|
24
|
+
require 'ronin/web/middleware/proxy'
|
23
25
|
|
24
26
|
module Ronin
|
25
27
|
module Web
|
26
28
|
module Proxy
|
29
|
+
#
|
30
|
+
# The base-class for all Ronin Web Proxies. Extends
|
31
|
+
# [Sinatra::Base](http://rubydoc.info/gems/sinatra/Sinatra/Base)
|
32
|
+
# with {Middleware::Proxy}.
|
33
|
+
#
|
27
34
|
class Base < Server::Base
|
28
35
|
|
29
36
|
# The default port to run the Web Proxy on
|
@@ -31,9 +38,7 @@ module Ronin
|
|
31
38
|
|
32
39
|
set :port, DEFAULT_PORT
|
33
40
|
|
34
|
-
|
35
|
-
proxy
|
36
|
-
end
|
41
|
+
use Middleware::Proxy
|
37
42
|
|
38
43
|
end
|
39
44
|
end
|
data/lib/ronin/web/proxy/web.rb
CHANGED
@@ -2,21 +2,22 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
23
|
require 'ronin/web/proxy/app'
|
@@ -29,6 +30,8 @@ module Ronin
|
|
29
30
|
#
|
30
31
|
# @see Server::Base.run!
|
31
32
|
#
|
33
|
+
# @api public
|
34
|
+
#
|
32
35
|
def Web.proxy_server(options={},&block)
|
33
36
|
unless class_variable_defined?('@@ronin_web_proxy')
|
34
37
|
@@ronin_web_proxy = Proxy::App
|
data/lib/ronin/web/server.rb
CHANGED
@@ -2,21 +2,22 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
23
|
require 'ronin/web/server/base'
|
data/lib/ronin/web/server/app.rb
CHANGED
@@ -2,21 +2,22 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
23
|
require 'ronin/web/server/base'
|
@@ -2,33 +2,33 @@
|
|
2
2
|
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
3
|
# scraping and spidering functionality.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
|
-
# This
|
7
|
+
# This file is part of Ronin Web.
|
8
|
+
#
|
9
|
+
# Ronin is free software: you can redistribute it and/or modify
|
8
10
|
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
12
|
# (at your option) any later version.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# Ronin is distributed in the hope that it will be useful,
|
13
15
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
16
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
17
|
# GNU General Public License for more details.
|
16
18
|
#
|
17
19
|
# You should have received a copy of the GNU General Public License
|
18
|
-
# along with
|
19
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
20
21
|
#
|
21
22
|
|
22
|
-
require 'ronin/web/
|
23
|
-
require 'ronin/web/
|
24
|
-
require 'ronin/web/
|
25
|
-
require 'ronin/web/
|
26
|
-
require 'ronin/
|
23
|
+
require 'ronin/web/middleware/helpers'
|
24
|
+
require 'ronin/web/middleware/files'
|
25
|
+
require 'ronin/web/middleware/directories'
|
26
|
+
require 'ronin/web/middleware/router'
|
27
|
+
require 'ronin/web/middleware/proxy'
|
27
28
|
require 'ronin/templates/erb'
|
28
29
|
require 'ronin/ui/output'
|
29
30
|
require 'ronin/extensions/meta'
|
30
31
|
|
31
|
-
require 'set'
|
32
32
|
require 'thread'
|
33
33
|
require 'rack'
|
34
34
|
require 'sinatra'
|
@@ -36,15 +36,16 @@ require 'sinatra'
|
|
36
36
|
module Ronin
|
37
37
|
module Web
|
38
38
|
module Server
|
39
|
+
#
|
40
|
+
# The base-class for all Ronin Web Servers. Extends
|
41
|
+
# [Sinatra::Base](http://rubydoc.info/gems/sinatra/Sinatra/Base)
|
42
|
+
# with additional helper methods and Rack {Middleware}.
|
43
|
+
#
|
39
44
|
class Base < Sinatra::Base
|
40
45
|
|
41
|
-
include Static::Finders
|
42
|
-
include Rack::Utils
|
43
46
|
include Templates::Erb
|
44
|
-
|
45
|
-
|
46
|
-
include Files
|
47
|
-
include Hosts
|
47
|
+
include UI::Output::Helpers
|
48
|
+
extend UI::Output::Helpers
|
48
49
|
|
49
50
|
# Default interface to run the Web Server on
|
50
51
|
DEFAULT_HOST = '0.0.0.0'
|
@@ -52,12 +53,6 @@ module Ronin
|
|
52
53
|
# Default port to run the Web Server on
|
53
54
|
DEFAULT_PORT = 8000
|
54
55
|
|
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
56
|
set :host, DEFAULT_HOST
|
62
57
|
set :port, DEFAULT_PORT
|
63
58
|
|
@@ -69,6 +64,8 @@ module Ronin
|
|
69
64
|
#
|
70
65
|
# @since 0.2.0
|
71
66
|
#
|
67
|
+
# @api public
|
68
|
+
#
|
72
69
|
def Base.handler
|
73
70
|
@@ronin_web_server_handler ||= nil
|
74
71
|
end
|
@@ -84,35 +81,12 @@ module Ronin
|
|
84
81
|
#
|
85
82
|
# @since 0.2.0
|
86
83
|
#
|
84
|
+
# @api public
|
85
|
+
#
|
87
86
|
def Base.handler=(name)
|
88
87
|
@@ronin_web_server_handler = name
|
89
88
|
end
|
90
89
|
|
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
90
|
#
|
117
91
|
# The list of Rack Handlers to attempt to use with the web server.
|
118
92
|
#
|
@@ -121,6 +95,8 @@ module Ronin
|
|
121
95
|
#
|
122
96
|
# @since 0.2.0
|
123
97
|
#
|
98
|
+
# @api public
|
99
|
+
#
|
124
100
|
def self.handlers
|
125
101
|
handlers = self.server
|
126
102
|
|
@@ -143,6 +119,8 @@ module Ronin
|
|
143
119
|
#
|
144
120
|
# @since 0.2.0
|
145
121
|
#
|
122
|
+
# @api semipublic
|
123
|
+
#
|
146
124
|
def self.handler_class
|
147
125
|
self.handlers.find do |name|
|
148
126
|
begin
|
@@ -154,12 +132,12 @@ module Ronin
|
|
154
132
|
end
|
155
133
|
end
|
156
134
|
|
157
|
-
raise(StandardError,"unable to find any Rack handlers"
|
135
|
+
raise(StandardError,"unable to find any Rack handlers")
|
158
136
|
end
|
159
137
|
|
160
138
|
#
|
161
139
|
# Run the web server using the Rack Handler returned by
|
162
|
-
#
|
140
|
+
# {handler_class}.
|
163
141
|
#
|
164
142
|
# @param [Hash] options Additional options.
|
165
143
|
#
|
@@ -175,6 +153,8 @@ module Ronin
|
|
175
153
|
#
|
176
154
|
# @since 0.2.0
|
177
155
|
#
|
156
|
+
# @api public
|
157
|
+
#
|
178
158
|
def self.run!(options={})
|
179
159
|
rack_options = {
|
180
160
|
:Host => (options[:host] || self.host),
|
@@ -223,6 +203,8 @@ module Ronin
|
|
223
203
|
#
|
224
204
|
# @since 0.2.0
|
225
205
|
#
|
206
|
+
# @api public
|
207
|
+
#
|
226
208
|
def self.any(path,options={},&block)
|
227
209
|
get(path,options,&block)
|
228
210
|
put(path,options,&block)
|
@@ -252,60 +234,208 @@ module Ronin
|
|
252
234
|
#
|
253
235
|
# @since 0.2.0
|
254
236
|
#
|
237
|
+
# @api public
|
238
|
+
#
|
255
239
|
def self.default(&block)
|
256
240
|
class_def(:default_response,&block)
|
257
241
|
return self
|
258
242
|
end
|
259
243
|
|
244
|
+
#
|
245
|
+
# Hosts the contents of a file.
|
246
|
+
#
|
247
|
+
# @param [String] remote_path
|
248
|
+
# The path the web server will host the file at.
|
249
|
+
#
|
250
|
+
# @param [String] local_path
|
251
|
+
# The path to the local file.
|
252
|
+
#
|
253
|
+
# @example
|
254
|
+
# file '/robots.txt', '/path/to/my_robots.txt'
|
255
|
+
#
|
256
|
+
# @see Middleware::Files
|
257
|
+
#
|
258
|
+
# @since 0.3.0
|
259
|
+
#
|
260
|
+
# @api public
|
261
|
+
#
|
262
|
+
def self.file(remote_path,local_path)
|
263
|
+
use Middleware::Files, :paths => {remote_path => local_path}
|
264
|
+
end
|
265
|
+
|
266
|
+
#
|
267
|
+
# Hosts the contents of files.
|
268
|
+
#
|
269
|
+
# @yield [files]
|
270
|
+
# The given block will be passed the files middleware to
|
271
|
+
# configure.
|
272
|
+
#
|
273
|
+
# @yieldparam [Middleware::Files]
|
274
|
+
# The files middleware object.
|
275
|
+
#
|
276
|
+
# @example
|
277
|
+
# files do |files|
|
278
|
+
# files.map '/foo.txt', 'foo.txt'
|
279
|
+
# files.map /\.exe$/, 'trojan.exe'
|
280
|
+
# end
|
281
|
+
#
|
282
|
+
# @see Middleware::Files
|
283
|
+
#
|
284
|
+
# @since 0.3.0
|
285
|
+
#
|
286
|
+
# @api public
|
287
|
+
#
|
288
|
+
def self.files(&block)
|
289
|
+
use(Middleware::Files,&block)
|
290
|
+
end
|
291
|
+
|
292
|
+
#
|
293
|
+
# Hosts the contents of the directory.
|
294
|
+
#
|
295
|
+
# @param [String] remote_path
|
296
|
+
# The path the web server will host the directory at.
|
297
|
+
#
|
298
|
+
# @param [String] local_path
|
299
|
+
# The path to the local directory.
|
300
|
+
#
|
301
|
+
# @example
|
302
|
+
# directory '/download/', '/tmp/files/'
|
303
|
+
#
|
304
|
+
# @see Middleware::Directories
|
305
|
+
#
|
306
|
+
# @since 0.2.0
|
307
|
+
#
|
308
|
+
# @api public
|
309
|
+
#
|
310
|
+
def self.directory(remote_path,local_path)
|
311
|
+
use Middleware::Directories, :paths => {remote_path => local_path}
|
312
|
+
end
|
313
|
+
|
314
|
+
#
|
315
|
+
# Hosts the contents of directories.
|
316
|
+
#
|
317
|
+
# @yield [dirs]
|
318
|
+
# The given block will be passed the directories middleware to
|
319
|
+
# configure.
|
320
|
+
#
|
321
|
+
# @yieldparam [Middleware::Directories]
|
322
|
+
# The directories middleware object.
|
323
|
+
#
|
324
|
+
# @example
|
325
|
+
# directories do |dirs|
|
326
|
+
# dirs.map '/downloads', '/tmp/ronin_downloads'
|
327
|
+
# dirs.map '/images', '/tmp/ronin_images'
|
328
|
+
# dirs.map '/pdfs', '/tmp/ronin_pdfs'
|
329
|
+
# end
|
330
|
+
#
|
331
|
+
# @see Middleware::Directories
|
332
|
+
#
|
333
|
+
# @since 0.3.0
|
334
|
+
#
|
335
|
+
# @api public
|
336
|
+
#
|
337
|
+
def self.directories(&block)
|
338
|
+
use(Middleware::Directories,&block)
|
339
|
+
end
|
340
|
+
|
341
|
+
#
|
342
|
+
# Hosts the static contents within a given directory.
|
343
|
+
#
|
344
|
+
# @param [String] path
|
345
|
+
# The path to a directory to serve static content from.
|
346
|
+
#
|
347
|
+
# @example
|
348
|
+
# public_dir 'path/to/another/public'
|
349
|
+
#
|
350
|
+
# @since 0.2.0
|
351
|
+
#
|
352
|
+
# @api public
|
353
|
+
#
|
354
|
+
def self.public_dir(path)
|
355
|
+
self.directory('/',path)
|
356
|
+
end
|
357
|
+
|
260
358
|
#
|
261
359
|
# Routes all requests within a given directory into another
|
262
360
|
# web server.
|
263
361
|
#
|
264
|
-
# @param [String] dir
|
362
|
+
# @param [String, Regexp] dir
|
265
363
|
# The directory that requests for will be routed from.
|
266
364
|
#
|
267
|
-
# @param [
|
365
|
+
# @param [#call] server
|
268
366
|
# The web server to route requests to.
|
269
367
|
#
|
270
368
|
# @example
|
271
|
-
#
|
369
|
+
# map '/subapp/', SubApp
|
370
|
+
#
|
371
|
+
# @see Middleware::Router
|
272
372
|
#
|
273
373
|
# @since 0.2.0
|
274
374
|
#
|
375
|
+
# @api public
|
376
|
+
#
|
275
377
|
def self.map(dir,server)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
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]
|
378
|
+
use Middleware::Router do |router|
|
379
|
+
router.draw :path => dir, :to => server
|
380
|
+
end
|
381
|
+
end
|
283
382
|
|
284
|
-
|
285
|
-
|
383
|
+
#
|
384
|
+
# Routes requests with a specific Host header to another
|
385
|
+
# web server.
|
386
|
+
#
|
387
|
+
# @param [String, Regexp] name
|
388
|
+
# The host-name to route requests for.
|
389
|
+
#
|
390
|
+
# @param [#call] server
|
391
|
+
# The web server to route the requests to.
|
392
|
+
#
|
393
|
+
# @example
|
394
|
+
# vhost 'cdn.evil.com', EvilServer
|
395
|
+
#
|
396
|
+
# @since 0.3.0
|
397
|
+
#
|
398
|
+
# @api public
|
399
|
+
#
|
400
|
+
def self.vhost(name,server)
|
401
|
+
use Middleware::Router do |router|
|
402
|
+
router.draw :vhost => name, :to => server
|
286
403
|
end
|
287
404
|
end
|
288
405
|
|
289
406
|
#
|
290
|
-
#
|
407
|
+
# Proxies requests to a given path.
|
291
408
|
#
|
292
|
-
# @param [String]
|
293
|
-
# The path to
|
409
|
+
# @param [String] path
|
410
|
+
# The path to proxy requests for.
|
411
|
+
#
|
412
|
+
# @param [Hash] options
|
413
|
+
# Additional options.
|
414
|
+
#
|
415
|
+
# @yield [(response), body]
|
416
|
+
# If a block is given, it will be passed the optional
|
417
|
+
# response of the proxied request and the body received
|
418
|
+
# from the proxied request.
|
419
|
+
#
|
420
|
+
# @yieldparam [Net::HTTP::Response] response
|
421
|
+
# The response.
|
422
|
+
#
|
423
|
+
# @yieldparam [String] body
|
424
|
+
# The body from the response.
|
294
425
|
#
|
295
426
|
# @example
|
296
|
-
#
|
427
|
+
# proxy '/login.php' do |response,body|
|
428
|
+
# body.gsub(/https/,'http')
|
429
|
+
# end
|
430
|
+
#
|
431
|
+
# @see Middleware::Proxy
|
297
432
|
#
|
298
433
|
# @since 0.2.0
|
299
434
|
#
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
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
|
435
|
+
# @api public
|
436
|
+
#
|
437
|
+
def self.proxy(path,options={},&block)
|
438
|
+
use(Middleware::Proxy,options,&block)
|
309
439
|
end
|
310
440
|
|
311
441
|
protected
|
@@ -315,18 +445,15 @@ module Ronin
|
|
315
445
|
#
|
316
446
|
# @since 0.2.0
|
317
447
|
#
|
448
|
+
# @api semipublic
|
449
|
+
#
|
318
450
|
def default_response
|
319
451
|
halt 404, ''
|
320
452
|
end
|
321
453
|
|
322
454
|
enable :sessions
|
323
455
|
|
324
|
-
|
325
|
-
helpers Helpers::Proxy
|
326
|
-
|
327
|
-
not_found do
|
328
|
-
default_response
|
329
|
-
end
|
456
|
+
any('*') { default_response }
|
330
457
|
|
331
458
|
end
|
332
459
|
end
|