ronin 0.2.4 → 0.3.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 +95 -0
- data/Manifest.txt +55 -25
- data/README.txt +64 -52
- data/Rakefile +21 -14
- data/bin/ronin +1 -1
- data/bin/ronin-add +1 -1
- data/bin/ronin-console +1 -1
- data/bin/ronin-help +1 -1
- data/bin/ronin-install +1 -1
- data/bin/ronin-list +1 -1
- data/bin/ronin-remove +1 -1
- data/bin/ronin-uninstall +1 -1
- data/bin/ronin-update +1 -1
- data/lib/ronin.rb +2 -4
- data/lib/ronin/arch.rb +66 -21
- data/lib/ronin/author.rb +27 -18
- data/lib/ronin/cacheable.rb +63 -23
- data/lib/ronin/code/emittable.rb +1 -4
- data/lib/ronin/code/reference.rb +2 -5
- data/lib/ronin/code/symbol_table.rb +1 -4
- data/lib/ronin/code/token.rb +1 -4
- data/lib/ronin/config.rb +31 -10
- data/lib/ronin/database.rb +1 -4
- data/lib/ronin/database/database.rb +42 -23
- data/lib/ronin/database/exceptions.rb +1 -4
- data/lib/ronin/database/exceptions/invalid_config.rb +1 -4
- data/lib/ronin/environment.rb +1 -5
- data/lib/ronin/extensions.rb +1 -5
- data/lib/ronin/extensions/array.rb +8 -6
- data/lib/ronin/extensions/file.rb +9 -4
- data/lib/ronin/extensions/ip_addr.rb +33 -13
- data/lib/ronin/extensions/kernel.rb +44 -9
- data/lib/ronin/extensions/meta.rb +1 -4
- data/lib/ronin/extensions/string.rb +8 -7
- data/lib/ronin/extensions/uri.rb +1 -4
- data/lib/ronin/extensions/uri/http.rb +1 -48
- data/lib/ronin/extensions/uri/query_params.rb +27 -8
- data/lib/ronin/formatting.rb +1 -4
- data/lib/ronin/formatting/binary.rb +1 -4
- data/lib/ronin/formatting/digest.rb +1 -4
- data/lib/ronin/formatting/extensions.rb +1 -4
- data/lib/ronin/formatting/extensions/binary.rb +1 -4
- data/lib/ronin/formatting/extensions/binary/file.rb +3 -28
- data/lib/ronin/formatting/extensions/binary/integer.rb +31 -12
- data/lib/ronin/formatting/extensions/binary/string.rb +59 -36
- data/lib/ronin/formatting/extensions/digest.rb +1 -4
- data/lib/ronin/formatting/extensions/digest/string.rb +31 -9
- data/lib/ronin/formatting/extensions/http.rb +1 -4
- data/lib/ronin/formatting/extensions/http/string.rb +16 -9
- data/lib/ronin/formatting/extensions/text.rb +1 -4
- data/lib/ronin/formatting/extensions/text/array.rb +17 -7
- data/lib/ronin/formatting/extensions/text/string.rb +70 -27
- data/lib/ronin/formatting/http.rb +1 -4
- data/lib/ronin/formatting/text.rb +1 -4
- data/lib/ronin/license.rb +72 -65
- data/lib/ronin/model.rb +1 -4
- data/lib/ronin/model/has_description.rb +37 -8
- data/lib/ronin/model/has_license.rb +12 -8
- data/lib/ronin/model/has_name.rb +10 -7
- data/lib/ronin/model/has_version.rb +14 -4
- data/lib/ronin/model/model.rb +71 -14
- data/lib/ronin/network.rb +1 -4
- data/lib/ronin/network/esmtp.rb +1 -4
- data/lib/ronin/network/extensions.rb +1 -4
- data/lib/ronin/network/extensions/esmtp.rb +1 -4
- data/lib/ronin/network/extensions/esmtp/net.rb +49 -21
- data/lib/ronin/network/extensions/http.rb +1 -4
- data/lib/ronin/network/extensions/http/net.rb +319 -531
- data/lib/ronin/network/extensions/imap.rb +1 -4
- data/lib/ronin/network/extensions/imap/net.rb +50 -23
- data/lib/ronin/network/extensions/pop3.rb +1 -4
- data/lib/ronin/network/extensions/pop3/net.rb +40 -17
- data/lib/ronin/network/extensions/smtp.rb +1 -4
- data/lib/ronin/network/extensions/smtp/net.rb +49 -21
- data/lib/ronin/network/extensions/tcp.rb +1 -4
- data/lib/ronin/network/extensions/tcp/net.rb +234 -31
- data/lib/ronin/network/extensions/telnet.rb +1 -4
- data/lib/ronin/network/extensions/telnet/net.rb +83 -51
- data/lib/ronin/network/extensions/udp.rb +1 -4
- data/lib/ronin/network/extensions/udp/net.rb +164 -27
- data/lib/ronin/{sessions.rb → network/helpers.rb} +10 -13
- data/lib/ronin/network/helpers/esmtp.rb +129 -0
- data/lib/ronin/{sessions/session.rb → network/helpers/helper.rb} +25 -17
- data/lib/ronin/network/helpers/http.rb +444 -0
- data/lib/ronin/network/helpers/imap.rb +115 -0
- data/lib/ronin/network/helpers/pop3.rb +110 -0
- data/lib/ronin/network/helpers/smtp.rb +123 -0
- data/lib/ronin/network/helpers/tcp.rb +309 -0
- data/lib/ronin/network/helpers/telnet.rb +158 -0
- data/lib/ronin/network/helpers/udp.rb +197 -0
- data/lib/ronin/network/http.rb +3 -156
- data/lib/ronin/network/http/exceptions.rb +1 -4
- data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -4
- data/lib/ronin/network/http/http.rb +214 -0
- data/lib/ronin/network/http/proxy.rb +308 -0
- data/lib/ronin/network/imap.rb +7 -6
- data/lib/ronin/network/pop3.rb +7 -6
- data/lib/ronin/network/smtp.rb +1 -4
- data/lib/ronin/network/smtp/email.rb +34 -18
- data/lib/ronin/network/smtp/smtp.rb +19 -7
- data/lib/ronin/network/tcp.rb +1 -4
- data/lib/ronin/network/telnet.rb +25 -12
- data/lib/ronin/network/udp.rb +1 -4
- data/lib/ronin/os.rb +43 -21
- data/lib/ronin/path.rb +29 -9
- data/lib/ronin/platform.rb +1 -4
- data/lib/ronin/platform/exceptions.rb +1 -4
- data/lib/ronin/platform/exceptions/extension_not_found.rb +1 -4
- data/lib/ronin/platform/exceptions/overlay_cached.rb +1 -4
- data/lib/ronin/platform/exceptions/overlay_not_found.rb +1 -4
- data/lib/ronin/platform/extension.rb +195 -52
- data/lib/ronin/platform/extension_cache.rb +60 -24
- data/lib/ronin/platform/maintainer.rb +15 -8
- data/lib/ronin/platform/object_cache.rb +29 -8
- data/lib/ronin/platform/overlay.rb +82 -26
- data/lib/ronin/platform/overlay_cache.rb +179 -56
- data/lib/ronin/platform/platform.rb +154 -58
- data/lib/ronin/platform/ronin.rb +38 -11
- data/lib/ronin/product.rb +17 -17
- data/lib/ronin/rpc.rb +1 -4
- data/lib/ronin/rpc/call.rb +1 -4
- data/lib/ronin/rpc/client.rb +1 -4
- data/lib/ronin/rpc/console.rb +1 -4
- data/lib/ronin/rpc/exceptions.rb +1 -4
- data/lib/ronin/rpc/exceptions/not_implemented.rb +1 -4
- data/lib/ronin/rpc/exceptions/response_missing.rb +1 -4
- data/lib/ronin/rpc/response.rb +1 -4
- data/lib/ronin/rpc/service.rb +1 -4
- data/lib/ronin/rpc/shell.rb +1 -4
- data/lib/ronin/scanners.rb +1 -4
- data/lib/ronin/scanners/exceptions.rb +1 -4
- data/lib/ronin/scanners/exceptions/unknown_category.rb +1 -4
- data/lib/ronin/scanners/scanner.rb +82 -26
- data/lib/ronin/static.rb +1 -4
- data/lib/ronin/static/finders.rb +1 -4
- data/lib/ronin/static/static.rb +16 -7
- data/lib/ronin/templates.rb +2 -4
- data/lib/ronin/templates/erb.rb +24 -10
- data/lib/ronin/templates/template.rb +130 -0
- data/lib/ronin/ui.rb +2 -6
- data/lib/ronin/ui/command_line.rb +1 -4
- data/lib/ronin/ui/command_line/command.rb +137 -68
- data/lib/ronin/ui/command_line/command_line.rb +52 -29
- data/lib/ronin/ui/command_line/commands/add.rb +39 -67
- data/lib/ronin/ui/command_line/commands/console.rb +23 -27
- data/lib/ronin/ui/command_line/commands/help.rb +10 -29
- data/lib/ronin/ui/command_line/commands/install.rb +31 -56
- data/lib/ronin/ui/command_line/commands/list.rb +34 -52
- data/lib/ronin/ui/command_line/commands/remove.rb +12 -32
- data/lib/ronin/ui/command_line/commands/uninstall.rb +11 -31
- data/lib/ronin/ui/command_line/commands/update.rb +15 -35
- data/lib/ronin/ui/command_line/exceptions.rb +1 -4
- data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -4
- data/lib/ronin/ui/console.rb +54 -23
- data/lib/ronin/ui/hexdump.rb +1 -4
- data/lib/ronin/ui/hexdump/extensions.rb +1 -4
- data/lib/ronin/ui/hexdump/extensions/file.rb +8 -6
- data/lib/ronin/ui/hexdump/extensions/kernel.rb +4 -5
- data/lib/ronin/ui/hexdump/hexdump.rb +8 -5
- data/lib/ronin/{sessions/exceptions.rb → ui/output.rb} +3 -5
- data/lib/ronin/ui/output/handler.rb +121 -0
- data/lib/ronin/ui/output/helpers.rb +110 -0
- data/lib/ronin/ui/output/output.rb +144 -0
- data/lib/ronin/ui/shell.rb +38 -12
- data/lib/ronin/version.rb +2 -5
- data/lib/ronin/{sessions/exceptions/variable_missing.rb → yard.rb} +2 -10
- data/lib/ronin/{ronin.rb → yard/handlers.rb} +5 -15
- data/lib/ronin/yard/handlers/ruby.rb +27 -0
- data/lib/ronin/yard/handlers/ruby/base.rb +27 -0
- data/lib/ronin/yard/handlers/ruby/belongs_to_handler.rb +45 -0
- data/lib/ronin/yard/handlers/ruby/eval_block_handler.rb +18 -0
- data/lib/ronin/yard/handlers/ruby/has_handler.rb +49 -0
- data/lib/ronin/yard/handlers/ruby/legacy.rb +26 -0
- data/lib/ronin/yard/handlers/ruby/legacy/belongs_to_handler.rb +41 -0
- data/lib/ronin/yard/handlers/ruby/legacy/eval_block_handler.rb +19 -0
- data/lib/ronin/yard/handlers/ruby/legacy/has_handler.rb +34 -0
- data/lib/ronin/yard/handlers/ruby/legacy/metaclass_eval_handler.rb +21 -0
- data/lib/ronin/yard/handlers/ruby/legacy/property_handler.rb +41 -0
- data/lib/ronin/yard/handlers/ruby/legacy/scanner_handler.rb +61 -0
- data/lib/ronin/yard/handlers/ruby/metaclass_eval_handler.rb +18 -0
- data/lib/ronin/yard/handlers/ruby/property_handler.rb +45 -0
- data/lib/ronin/yard/handlers/ruby/scanner_handler.rb +66 -0
- data/spec/author_spec.rb +3 -3
- data/spec/extensions/classes/some_class.rb +2 -0
- data/spec/extensions/kernel_spec.rb +17 -0
- data/spec/extensions/uri/http_spec.rb +0 -31
- data/spec/formatting/binary/integer_spec.rb +4 -0
- data/spec/formatting/text/string_spec.rb +96 -0
- data/spec/license_spec.rb +6 -6
- data/spec/model/classes/basic_model.rb +13 -0
- data/spec/model/classes/custom_model.rb +17 -0
- data/spec/model/classes/described_model.rb +10 -0
- data/spec/model/has_description_spec.rb +42 -0
- data/spec/model/has_license_spec.rb +18 -4
- data/spec/model/model_spec.rb +68 -0
- data/spec/network/helpers/classes/test_helper.rb +11 -0
- data/spec/network/helpers/classes/uses_test_helper.rb +10 -0
- data/spec/network/helpers/helper_spec.rb +25 -0
- data/spec/network/{http_spec.rb → http/http_spec.rb} +0 -0
- data/spec/network/http/proxy_spec.rb +116 -0
- data/spec/os_spec.rb +4 -4
- data/spec/platform/extension_cache_spec.rb +14 -0
- data/spec/platform/extension_spec.rb +11 -0
- data/spec/platform/platform_spec.rb +8 -0
- data/spec/product_spec.rb +9 -9
- data/spec/spec_helper.rb +1 -1
- data/spec/templates/classes/{uses_erb.rb → example_erb.rb} +1 -1
- data/spec/templates/classes/example_template.rb +21 -0
- data/spec/templates/erb_spec.rb +2 -2
- data/spec/templates/helpers/static.rb +5 -0
- data/spec/templates/helpers/static/templates/_relative.erb +1 -0
- data/spec/templates/helpers/static/templates/example.erb +1 -0
- data/spec/templates/template_spec.rb +41 -0
- data/spec/ui/command_line/classes/test_command.rb +23 -0
- data/spec/ui/command_line/command_spec.rb +31 -0
- data/spec/ui/output_spec.rb +29 -0
- data/static/ronin/platform/overlay.xsl +135 -114
- data/tasks/spec.rb +1 -0
- data/tasks/yard.rb +18 -0
- metadata +98 -59
- metadata.gz.sig +0 -0
- data/TODO.txt +0 -15
- data/lib/ronin/extensions/hash.rb +0 -62
- data/lib/ronin/sessions/esmtp.rb +0 -57
- data/lib/ronin/sessions/http.rb +0 -678
- data/lib/ronin/sessions/imap.rb +0 -54
- data/lib/ronin/sessions/pop3.rb +0 -52
- data/lib/ronin/sessions/smtp.rb +0 -57
- data/lib/ronin/sessions/tcp.rb +0 -100
- data/lib/ronin/sessions/telnet.rb +0 -55
- data/lib/ronin/sessions/udp.rb +0 -73
- data/lib/ronin/ui/command_line/options.rb +0 -136
- data/lib/ronin/ui/diagnostics.rb +0 -66
- data/lib/ronin/ui/verbose.rb +0 -58
- data/spec/extensions/hash_spec.rb +0 -38
- data/spec/sessions/classes/test_session.rb +0 -11
- data/spec/sessions/classes/uses_test_session.rb +0 -10
- data/spec/sessions/session_spec.rb +0 -25
- data/spec/ui/verbose_spec.rb +0 -17
@@ -1,7 +1,5 @@
|
|
1
1
|
#
|
2
|
-
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
2
|
+
# Ronin - A Ruby platform for exploit development and security research.
|
5
3
|
#
|
6
4
|
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
5
|
#
|
@@ -18,7 +16,6 @@
|
|
18
16
|
# You should have received a copy of the GNU General Public License
|
19
17
|
# along with this program; if not, write to the Free Software
|
20
18
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
19
|
#
|
23
20
|
|
24
21
|
require 'ronin/network/http/exceptions/unknown_request'
|
@@ -1,7 +1,5 @@
|
|
1
1
|
#
|
2
|
-
|
3
|
-
# Ronin - A Ruby platform designed for information security and data
|
4
|
-
# exploration tasks.
|
2
|
+
# Ronin - A Ruby platform for exploit development and security research.
|
5
3
|
#
|
6
4
|
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
5
|
#
|
@@ -18,7 +16,6 @@
|
|
18
16
|
# You should have received a copy of the GNU General Public License
|
19
17
|
# along with this program; if not, write to the Free Software
|
20
18
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
-
#++
|
22
19
|
#
|
23
20
|
|
24
21
|
module Ronin
|
@@ -0,0 +1,214 @@
|
|
1
|
+
#
|
2
|
+
# Ronin - A Ruby platform for exploit development and security research.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
5
|
+
#
|
6
|
+
# This program is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'ronin/network/http/exceptions/unknown_request'
|
22
|
+
require 'ronin/network/http/proxy'
|
23
|
+
require 'ronin/network/extensions/http'
|
24
|
+
|
25
|
+
module Ronin
|
26
|
+
module Network
|
27
|
+
module HTTP
|
28
|
+
#
|
29
|
+
# @return [Proxy]
|
30
|
+
# The Ronin HTTP proxy hash.
|
31
|
+
#
|
32
|
+
def HTTP.proxy
|
33
|
+
@@http_proxy ||= Proxy.new
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# @return [String, nil]
|
38
|
+
# The default Ronin HTTP User-Agent.
|
39
|
+
#
|
40
|
+
def HTTP.user_agent
|
41
|
+
@@http_user_agent ||= nil
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Sets the default Ronin HTTP User-Agent.
|
46
|
+
#
|
47
|
+
# @param [String] agent
|
48
|
+
# The new User-Agent string to use.
|
49
|
+
#
|
50
|
+
def HTTP.user_agent=(agent)
|
51
|
+
@@http_user_agent = agent
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Expands the given HTTP _options_.
|
56
|
+
#
|
57
|
+
# @param [Hash] options
|
58
|
+
# HTTP options.
|
59
|
+
#
|
60
|
+
# @option options [String, URI::HTTP, URI::HTTPS] :url
|
61
|
+
# The URL to request.
|
62
|
+
#
|
63
|
+
# @option options [String] :host
|
64
|
+
# The host to connect to.
|
65
|
+
#
|
66
|
+
# @option options [String] :port (::Net::HTTP.default_port)
|
67
|
+
# The port to connect to.
|
68
|
+
#
|
69
|
+
# @option options [String] :user
|
70
|
+
# The user to authenticate as.
|
71
|
+
#
|
72
|
+
# @option options [String] :password
|
73
|
+
# The password to authenticate with.
|
74
|
+
#
|
75
|
+
# @option options [String] :path ('/')
|
76
|
+
# The path to request.
|
77
|
+
#
|
78
|
+
# @option options [String, Hash] :proxy (Ronin::Network::HTTP.proxy)
|
79
|
+
# The Proxy information.
|
80
|
+
#
|
81
|
+
# @return [Hash]
|
82
|
+
# The expanded version of _options_.
|
83
|
+
#
|
84
|
+
def HTTP.expand_options(options={})
|
85
|
+
new_options = options.dup
|
86
|
+
|
87
|
+
if new_options[:url]
|
88
|
+
url = URI(new_options.delete(:url).to_s)
|
89
|
+
|
90
|
+
new_options[:host] = url.host
|
91
|
+
new_options[:port] = url.port
|
92
|
+
|
93
|
+
new_options[:user] = url.user if url.user
|
94
|
+
new_options[:password] = url.password if url.password
|
95
|
+
|
96
|
+
unless url.path.empty?
|
97
|
+
new_options[:path] = url.path
|
98
|
+
else
|
99
|
+
new_options[:path] = '/'
|
100
|
+
end
|
101
|
+
|
102
|
+
new_options[:path] << "?#{url.query}" if url.query
|
103
|
+
else
|
104
|
+
new_options[:port] ||= ::Net::HTTP.default_port
|
105
|
+
new_options[:path] ||= '/'
|
106
|
+
end
|
107
|
+
|
108
|
+
if (proxy = new_options[:proxy])
|
109
|
+
unless proxy.kind_of?(Hash)
|
110
|
+
new_options[:proxy] = Ronin::Network::HTTP::Proxy.parse(proxy)
|
111
|
+
end
|
112
|
+
else
|
113
|
+
new_options[:proxy] = Ronin::Network::HTTP.proxy
|
114
|
+
end
|
115
|
+
|
116
|
+
return new_options
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Converts underscored, dashed, lowercase and uppercase HTTP headers
|
121
|
+
# to standard camel-cased HTTP headers.
|
122
|
+
#
|
123
|
+
# @param [Hash{Symbol,String => String}] options
|
124
|
+
# Ronin HTTP headers.
|
125
|
+
#
|
126
|
+
# @return [Hash]
|
127
|
+
# The camel-cased HTTP headers created from the given _options_.
|
128
|
+
#
|
129
|
+
def HTTP.headers(options={})
|
130
|
+
headers = {}
|
131
|
+
|
132
|
+
if HTTP.user_agent
|
133
|
+
headers['User-Agent'] = HTTP.user_agent
|
134
|
+
end
|
135
|
+
|
136
|
+
if options
|
137
|
+
options.each do |name,value|
|
138
|
+
header_name = name.to_s.split(/[\s+_-]/).map { |word|
|
139
|
+
word.capitalize
|
140
|
+
}.join('-')
|
141
|
+
|
142
|
+
headers[header_name] = value.to_s
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
return headers
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Creates an HTTP request object with the specified _type_ and
|
151
|
+
# given _options_. If type does not represent the name of an Net:HTTP
|
152
|
+
# Request Class an UnknownRequest exception will be raised.
|
153
|
+
#
|
154
|
+
# @param [Hash] options
|
155
|
+
# The HTTP options for the request.
|
156
|
+
#
|
157
|
+
# @option options [Symbol, String] :method
|
158
|
+
# The HTTP method to use for the request.
|
159
|
+
#
|
160
|
+
# @option options [String] :path ('/')
|
161
|
+
# The path to request.
|
162
|
+
#
|
163
|
+
# @option options [String] :user
|
164
|
+
# The user to authenticate as.
|
165
|
+
#
|
166
|
+
# @option options [String] :password
|
167
|
+
# The password to authenticate with.
|
168
|
+
#
|
169
|
+
# @option options [Hash{Symbol,String => String}] :headers
|
170
|
+
# Additional HTTP headers to use for the request.
|
171
|
+
#
|
172
|
+
# @return [HTTP::Request]
|
173
|
+
# The new HTTP Request object.
|
174
|
+
#
|
175
|
+
# @raise [ArgumentError]
|
176
|
+
# The +:method+ option must be specified.
|
177
|
+
#
|
178
|
+
# @raise [UnknownRequest]
|
179
|
+
# The +:method+ option did not match a known Net::HTTP request
|
180
|
+
# class.
|
181
|
+
#
|
182
|
+
# @see HTTP.expand_options
|
183
|
+
#
|
184
|
+
def HTTP.request(options={})
|
185
|
+
unless options[:method]
|
186
|
+
raise(ArgumentError,"the :method option must be specified",caller)
|
187
|
+
end
|
188
|
+
|
189
|
+
name = options[:method].to_s.capitalize
|
190
|
+
|
191
|
+
unless Net::HTTP.const_defined?(name)
|
192
|
+
raise(UnknownRequest,"unknown HTTP request type #{name.dump}",caller)
|
193
|
+
end
|
194
|
+
|
195
|
+
headers = HTTP.headers(options[:headers])
|
196
|
+
path = (options[:path] || '/').to_s
|
197
|
+
|
198
|
+
request = Net::HTTP.const_get(name).new(path,headers)
|
199
|
+
|
200
|
+
if (user = options.delete(:user))
|
201
|
+
user = user.to_s
|
202
|
+
|
203
|
+
if (password = options.delete(:password))
|
204
|
+
password = password.to_s
|
205
|
+
end
|
206
|
+
|
207
|
+
request.basic_auth(user,password)
|
208
|
+
end
|
209
|
+
|
210
|
+
return request
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
#
|
2
|
+
# Ronin - A Ruby platform for exploit development and security research.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
|
5
|
+
#
|
6
|
+
# This program is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module Network
|
23
|
+
module HTTP
|
24
|
+
class Proxy < Hash
|
25
|
+
|
26
|
+
# The default port of proxies
|
27
|
+
DEFAULT_PORT = 8080
|
28
|
+
|
29
|
+
#
|
30
|
+
# Creates a new Proxy object that represents a proxy to connect to.
|
31
|
+
#
|
32
|
+
# @param [Hash] options
|
33
|
+
# Additional options for the proxy.
|
34
|
+
#
|
35
|
+
# @option options [String] :host
|
36
|
+
# The host-name of the proxy.
|
37
|
+
#
|
38
|
+
# @option options [Integer] :port (DEFAULT_PORT)
|
39
|
+
# The port that the proxy is running on.
|
40
|
+
# @option options [String] :user
|
41
|
+
# The user-name to authenticate as.
|
42
|
+
# @option options [String] :password
|
43
|
+
# The password to authenticate with.
|
44
|
+
#
|
45
|
+
def initialize(options={})
|
46
|
+
super()
|
47
|
+
|
48
|
+
self[:host] = options[:host]
|
49
|
+
self[:port] = (options[:port] || DEFAULT_PORT)
|
50
|
+
self[:user] = options[:user]
|
51
|
+
self[:password] = options[:password]
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Parses a proxy URL.
|
56
|
+
#
|
57
|
+
# @param [String, URI::HTTP] proxy
|
58
|
+
# The proxy URL in String form.
|
59
|
+
#
|
60
|
+
# @return [Proxy]
|
61
|
+
# The parsed proxy information.
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# Proxy.parse('217.31.51.77:443')
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# Proxy.parse('joe:lol@127.0.0.1:8080')
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# Proxy.parse('http://201.26.192.61:8080')
|
71
|
+
#
|
72
|
+
def Proxy.parse(proxy)
|
73
|
+
proxy = proxy.to_s.gsub(/^http(s)?:\/*/,'')
|
74
|
+
|
75
|
+
if proxy.include?('@')
|
76
|
+
auth, proxy = proxy.split('@',2)
|
77
|
+
user, password = auth.split(':')
|
78
|
+
else
|
79
|
+
user = nil
|
80
|
+
password = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
host, port = proxy.split(':',2)
|
84
|
+
port = port.to_i if port
|
85
|
+
|
86
|
+
return Proxy.new(
|
87
|
+
:host => host,
|
88
|
+
:port => port,
|
89
|
+
:user => user,
|
90
|
+
:password => password
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Tests the proxy.
|
96
|
+
#
|
97
|
+
# @return [Boolean]
|
98
|
+
# Specifies if the proxy can proxy requests.
|
99
|
+
#
|
100
|
+
def valid?
|
101
|
+
begin
|
102
|
+
Net.http_get_body(
|
103
|
+
:url => 'http://www.example.com/',
|
104
|
+
:proxy => self
|
105
|
+
).include?('Example Web Page')
|
106
|
+
rescue Timeout::Error, StandardError
|
107
|
+
return false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Measures the lag of the proxy.
|
113
|
+
#
|
114
|
+
# @return [Float]
|
115
|
+
# The extra number of seconds it takes the proxy to process the
|
116
|
+
# request.
|
117
|
+
#
|
118
|
+
def lag
|
119
|
+
time = lambda { |proxy|
|
120
|
+
t1 = Time.now
|
121
|
+
Net.http_head(
|
122
|
+
:url => 'http://www.example.com/',
|
123
|
+
:proxy => proxy
|
124
|
+
)
|
125
|
+
t2 = Time.now
|
126
|
+
|
127
|
+
(t2 - t1)
|
128
|
+
}
|
129
|
+
|
130
|
+
begin
|
131
|
+
return (time.call(self) - time.call(nil))
|
132
|
+
rescue Timeout::Error, StandardError
|
133
|
+
return (1.0/0)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Disables the Proxy object.
|
139
|
+
#
|
140
|
+
def disable!
|
141
|
+
self[:host] = nil
|
142
|
+
self[:port] = DEFAULT_PORT
|
143
|
+
self[:user] = nil
|
144
|
+
self[:password] = nil
|
145
|
+
|
146
|
+
return self
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Specifies whether the proxy object is usable.
|
151
|
+
#
|
152
|
+
# @return [Boolean]
|
153
|
+
# Specifies whether the proxy object is usable by
|
154
|
+
# Net::HTTP::Proxy.
|
155
|
+
#
|
156
|
+
def enabled?
|
157
|
+
!(self[:host].nil? || self[:port].nil?)
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# @return [String, nil]
|
162
|
+
# The host-name to connect when using the proxy.
|
163
|
+
#
|
164
|
+
def host
|
165
|
+
self[:host]
|
166
|
+
end
|
167
|
+
|
168
|
+
#
|
169
|
+
# Set the host-name of the proxy.
|
170
|
+
#
|
171
|
+
# @param [String] new_host
|
172
|
+
# The new host-name to use.
|
173
|
+
#
|
174
|
+
# @return [String]
|
175
|
+
# The new host-name to use.
|
176
|
+
#
|
177
|
+
def host=(new_host)
|
178
|
+
self[:host] = new_host.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# @return [Integer]
|
183
|
+
# The port to connect when using the proxy.
|
184
|
+
#
|
185
|
+
def port
|
186
|
+
self[:port]
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# Set the port of the proxy.
|
191
|
+
#
|
192
|
+
# @param [Integer] new_port
|
193
|
+
# The new port to use.
|
194
|
+
#
|
195
|
+
# @return [Integer]
|
196
|
+
# The new port to use.
|
197
|
+
#
|
198
|
+
def port=(new_port)
|
199
|
+
self[:port] = new_port.to_i
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# @return [String, nil]
|
204
|
+
# The user-name to authenticate as, when using the proxy.
|
205
|
+
#
|
206
|
+
def user
|
207
|
+
self[:user]
|
208
|
+
end
|
209
|
+
|
210
|
+
#
|
211
|
+
# Set the user-name to authenticate as with the proxy.
|
212
|
+
#
|
213
|
+
# @param [String] new_user
|
214
|
+
# The new user-name to use.
|
215
|
+
#
|
216
|
+
# @return [Integer]
|
217
|
+
# The new user-name to use.
|
218
|
+
#
|
219
|
+
def user=(new_user)
|
220
|
+
self[:user] = new_user.to_s
|
221
|
+
end
|
222
|
+
|
223
|
+
#
|
224
|
+
# @return [String, nil]
|
225
|
+
# The password to authenticate with, when using the proxy.
|
226
|
+
#
|
227
|
+
def password
|
228
|
+
self[:password]
|
229
|
+
end
|
230
|
+
|
231
|
+
#
|
232
|
+
# Set the password to authenticate with for the proxy.
|
233
|
+
#
|
234
|
+
# @param [String] new_user
|
235
|
+
# The new user-name to use.
|
236
|
+
#
|
237
|
+
# @return [Integer]
|
238
|
+
# The new user-name to use.
|
239
|
+
#
|
240
|
+
def password=(new_password)
|
241
|
+
self[:password] = new_password.to_s
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Builds a HTTP URI from the proxy information.
|
246
|
+
#
|
247
|
+
# @return [URI::HTTP, nil]
|
248
|
+
# The HTTP URI representing the proxy. If the proxy is disabled,
|
249
|
+
# then +nil+ will be returned.
|
250
|
+
#
|
251
|
+
def url
|
252
|
+
return nil unless enabled?
|
253
|
+
|
254
|
+
userinfo = if self[:user]
|
255
|
+
if self[:password]
|
256
|
+
"#{self[:user]}:#{self[:password]}"
|
257
|
+
else
|
258
|
+
self[:user]
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
return URI::HTTP.build({
|
263
|
+
:userinfo => userinfo,
|
264
|
+
:host => self[:host],
|
265
|
+
:port => self[:port]
|
266
|
+
})
|
267
|
+
end
|
268
|
+
|
269
|
+
#
|
270
|
+
# Converts the proxy object to a String.
|
271
|
+
#
|
272
|
+
# @return [String]
|
273
|
+
# The host-name of the proxy.
|
274
|
+
#
|
275
|
+
def to_s
|
276
|
+
self[:host].to_s
|
277
|
+
end
|
278
|
+
|
279
|
+
#
|
280
|
+
# Inspects the proxy object.
|
281
|
+
#
|
282
|
+
# @return [String]
|
283
|
+
# The inspection of the proxy object.
|
284
|
+
#
|
285
|
+
def inspect
|
286
|
+
unless (self[:host] || self[:port])
|
287
|
+
str = 'disabled'
|
288
|
+
else
|
289
|
+
str = "#{self[:host]}:#{self[:port]}"
|
290
|
+
|
291
|
+
if self[:user]
|
292
|
+
auth_str = self[:user]
|
293
|
+
|
294
|
+
if self[:password]
|
295
|
+
auth_str = "#{auth_str}:#{self[:password]}"
|
296
|
+
end
|
297
|
+
|
298
|
+
str = "#{auth_str}@#{str}"
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
return "#<#{self.class}: #{str}>"
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|