ronin 1.0.0 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +0 -1
- data/ChangeLog.md +67 -3
- data/Gemfile +20 -12
- data/README.md +3 -5
- data/gemspec.yml +5 -5
- data/lib/ronin/address.rb +8 -3
- data/lib/ronin/arch.rb +39 -14
- data/lib/ronin/author.rb +2 -0
- data/lib/ronin/auto_load.rb +67 -0
- data/lib/ronin/campaign.rb +15 -2
- data/lib/ronin/class_methods.rb +7 -1
- data/lib/ronin/config.rb +5 -0
- data/lib/ronin/credential.rb +14 -3
- data/lib/ronin/database/database.rb +38 -12
- data/lib/ronin/database/migrations.rb +3 -1
- data/lib/ronin/database/migrations/add_created_at_column_to_targets_table.rb +48 -0
- data/lib/ronin/database/migrations/add_updated_at_column_to_campaigns_table.rb +47 -0
- data/lib/ronin/database/migrations/create_licenses_table.rb +1 -1
- data/lib/ronin/database/migrations/create_passwords_table.rb +1 -1
- data/lib/ronin/database/migrations/{create_cached_files_table.rb → create_script_paths_table.rb} +4 -4
- data/lib/ronin/database/migrations/migration.rb +3 -6
- data/lib/ronin/database/migrations/migrations.rb +3 -3
- data/lib/ronin/email_address.rb +20 -3
- data/lib/ronin/environment.rb +0 -3
- data/lib/ronin/host_name.rb +20 -6
- data/lib/ronin/host_name_ip_address.rb +2 -3
- data/lib/ronin/installation.rb +92 -23
- data/lib/ronin/ip_address.rb +31 -8
- data/lib/ronin/ip_address_mac_address.rb +2 -3
- data/lib/ronin/license.rb +1 -1
- data/lib/ronin/mac_address.rb +6 -4
- data/lib/ronin/model/class_methods.rb +4 -0
- data/lib/ronin/model/has_authors/class_methods.rb +4 -0
- data/lib/ronin/model/has_authors/has_authors.rb +4 -0
- data/lib/ronin/model/has_description/class_methods.rb +2 -0
- data/lib/ronin/model/has_description/has_description.rb +2 -0
- data/lib/ronin/model/has_license/class_methods.rb +2 -0
- data/lib/ronin/model/has_license/has_license.rb +4 -0
- data/lib/ronin/model/has_name/class_methods.rb +2 -0
- data/lib/ronin/model/has_name/has_name.rb +4 -0
- data/lib/ronin/model/has_title/class_methods.rb +2 -0
- data/lib/ronin/model/has_title/has_title.rb +2 -0
- data/lib/ronin/model/has_unique_name/class_methods.rb +2 -0
- data/lib/ronin/model/has_unique_name/has_unique_name.rb +7 -1
- data/lib/ronin/model/has_version/class_methods.rb +4 -0
- data/lib/ronin/model/has_version/has_version.rb +2 -0
- data/lib/ronin/model/model.rb +2 -0
- data/lib/ronin/model/types.rb +1 -7
- data/lib/ronin/model/types/description.rb +2 -0
- data/lib/ronin/network/mixins/esmtp.rb +40 -25
- data/lib/ronin/network/mixins/http.rb +336 -73
- data/lib/ronin/network/mixins/imap.rb +38 -25
- data/lib/ronin/network/mixins/pop3.rb +34 -21
- data/lib/ronin/network/mixins/smtp.rb +40 -25
- data/lib/ronin/network/mixins/tcp.rb +66 -41
- data/lib/ronin/network/mixins/telnet.rb +43 -30
- data/lib/ronin/network/mixins/udp.rb +59 -40
- data/lib/ronin/open_port.rb +12 -5
- data/lib/ronin/organization.rb +1 -2
- data/lib/ronin/os.rb +10 -3
- data/lib/ronin/os_guess.rb +2 -3
- data/lib/ronin/password.rb +11 -3
- data/lib/ronin/port.rb +7 -2
- data/lib/ronin/{engine/exceptions/deploy_failed.rb → repositories.rb} +4 -6
- data/lib/ronin/repository.rb +110 -37
- data/lib/ronin/ronin.rb +4 -3
- data/lib/ronin/{engine.rb → script.rb} +2 -1
- data/lib/ronin/{engine → script}/buildable.rb +43 -29
- data/lib/ronin/script/class_methods.rb +84 -0
- data/lib/ronin/{engine → script}/deployable.rb +61 -40
- data/lib/ronin/{engine → script}/exceptions.rb +4 -3
- data/lib/ronin/script/exceptions/deploy_failed.rb +27 -0
- data/lib/ronin/{engine/exceptions/not_built.rb → script/exceptions/exception.rb} +2 -2
- data/lib/ronin/{engine/exceptions/verification_failed.rb → script/exceptions/not_built.rb} +4 -2
- data/lib/ronin/script/exceptions/test_failed.rb +27 -0
- data/lib/ronin/script/instance_methods.rb +217 -0
- data/lib/ronin/script/path.rb +277 -0
- data/lib/ronin/{engine/engine.rb → script/script.rb} +52 -15
- data/lib/ronin/{engine/verifiable.rb → script/testable.rb} +97 -68
- data/lib/ronin/service.rb +1 -2
- data/lib/ronin/service_credential.rb +1 -2
- data/lib/ronin/software.rb +3 -2
- data/lib/ronin/spec/database.rb +0 -4
- data/lib/ronin/target.rb +11 -3
- data/lib/ronin/tcp_port.rb +3 -2
- data/lib/ronin/udp_port.rb +2 -0
- data/lib/ronin/ui/cli/cli.rb +6 -0
- data/lib/ronin/ui/cli/command.rb +48 -12
- data/lib/ronin/ui/cli/commands/campaigns.rb +3 -3
- data/lib/ronin/ui/cli/commands/console.rb +2 -1
- data/lib/ronin/ui/cli/commands/creds.rb +3 -3
- data/lib/ronin/ui/cli/commands/database.rb +1 -17
- data/lib/ronin/ui/cli/commands/emails.rb +3 -3
- data/lib/ronin/ui/cli/commands/hosts.rb +3 -7
- data/lib/ronin/ui/cli/commands/ips.rb +3 -7
- data/lib/ronin/ui/cli/commands/repos.rb +5 -17
- data/lib/ronin/ui/cli/commands/urls.rb +3 -3
- data/lib/ronin/ui/cli/model_command.rb +82 -97
- data/lib/ronin/ui/cli/resources_command.rb +89 -0
- data/lib/ronin/ui/cli/script_command.rb +115 -0
- data/lib/ronin/ui/console.rb +17 -3
- data/lib/ronin/ui/output/helpers.rb +18 -0
- data/lib/ronin/ui/output/output.rb +20 -1
- data/lib/ronin/ui/output/terminal/color.rb +10 -0
- data/lib/ronin/ui/output/terminal/raw.rb +10 -0
- data/lib/ronin/ui/shell.rb +2 -0
- data/lib/ronin/url.rb +47 -12
- data/lib/ronin/url_query_param.rb +4 -0
- data/lib/ronin/url_scheme.rb +3 -3
- data/lib/ronin/user_name.rb +2 -0
- data/lib/ronin/version.rb +1 -1
- data/lib/ronin/web_credential.rb +6 -3
- data/spec/arch_spec.rb +3 -3
- data/spec/classes/my_script.rb +21 -0
- data/spec/helpers/repos/{test1 → installed}/ronin.yml +1 -1
- data/spec/helpers/repos/{hello/cache → installed/scripts}/.keep +0 -0
- data/spec/helpers/repos/local/lib/init.rb +1 -0
- data/spec/helpers/repos/{hello → local}/lib/stuff/another_test.rb +0 -0
- data/spec/helpers/repos/{hello → local}/lib/stuff/test.rb +0 -0
- data/spec/helpers/repos/{random → local}/ronin.yml +1 -1
- data/spec/helpers/repos/{random/cache → local/scripts}/.keep +0 -0
- data/spec/helpers/repos/{hello → remote}/ronin.yml +1 -1
- data/spec/helpers/repos/remote/scripts/.keep +0 -0
- data/spec/helpers/repos/{test2 → scripts}/ronin.yml +0 -0
- data/spec/helpers/repos/scripts/scripts/cached/cached.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/cached/missing.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/cached/modified.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/cached/unmodified.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/failures/exceptions.rb +11 -0
- data/spec/helpers/repos/{test2/cache/cacheable_model → scripts/scripts/failures}/load_errors.rb +3 -1
- data/spec/helpers/repos/{test2/cache/cacheable_model → scripts/scripts/failures}/name_errors.rb +1 -0
- data/spec/helpers/repos/scripts/scripts/failures/no_method_errors.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/failures/syntax_errors.rb +11 -0
- data/spec/helpers/repos/scripts/scripts/failures/validation_errors.rb +11 -0
- data/spec/helpers/repos/scripts/scripts/my_scripts/test.rb +16 -0
- data/spec/model/spec_helper.rb +0 -2
- data/spec/repository_spec.rb +61 -81
- data/spec/ronin_spec.rb +2 -2
- data/spec/{engine → script}/buildable_spec.rb +9 -9
- data/spec/script/classes/buildable_class.rb +15 -0
- data/spec/script/classes/deployable_class.rb +13 -0
- data/spec/{engine/classes/engine_class.rb → script/classes/script_class.rb} +3 -3
- data/spec/{engine/classes/verifiable_class.rb → script/classes/testable_class.rb} +5 -5
- data/spec/{engine → script}/deployable_spec.rb +10 -10
- data/spec/{cached_file_spec.rb → script/path_spec.rb} +33 -72
- data/spec/script/script_spec.rb +130 -0
- data/spec/script/testable_spec.rb +117 -0
- data/spec/spec_helper.rb +15 -13
- metadata +114 -139
- data/lib/ronin/cached_file.rb +0 -247
- data/lib/ronin/engine/class_methods.rb +0 -135
- data/lib/ronin/engine/instance_methods.rb +0 -97
- data/lib/ronin/model/cacheable.rb +0 -21
- data/lib/ronin/model/cacheable/cacheable.rb +0 -273
- data/lib/ronin/model/cacheable/class_methods.rb +0 -60
- data/lib/ronin/ui/cli/engine_command.rb +0 -106
- data/spec/engine/classes/buildable_class.rb +0 -15
- data/spec/engine/classes/deployable_class.rb +0 -13
- data/spec/engine/engine_spec.rb +0 -55
- data/spec/engine/verifiable_spec.rb +0 -117
- data/spec/helpers/repos/hello/lib/init.rb +0 -1
- data/spec/helpers/repos/test1/cache/cacheable_model/one.rb +0 -15
- data/spec/helpers/repos/test2/cache/cacheable_model/exceptions.rb +0 -7
- data/spec/helpers/repos/test2/cache/cacheable_model/no_method_errors.rb +0 -9
- data/spec/helpers/repos/test2/cache/cacheable_model/syntax_errors.rb +0 -7
- data/spec/helpers/repos/test2/cache/cacheable_model/two.rb +0 -15
- data/spec/helpers/repos/test2/cache/cacheable_model/validation_errors.rb +0 -9
- data/spec/model/cacheable_spec.rb +0 -96
- data/spec/model/models/cacheable_model.rb +0 -13
@@ -18,13 +18,12 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'ronin/model'
|
21
|
+
require 'ronin/ip_address'
|
22
|
+
require 'ronin/mac_address'
|
21
23
|
|
22
24
|
require 'dm-timestamps'
|
23
25
|
|
24
26
|
module Ronin
|
25
|
-
autoload :IPAddress, 'ronin/ip_address'
|
26
|
-
autoload :MACAddress, 'ronin/mac_address'
|
27
|
-
|
28
27
|
#
|
29
28
|
# Associates an {IPAddress} with a {MACAddress}.
|
30
29
|
#
|
data/lib/ronin/license.rb
CHANGED
data/lib/ronin/mac_address.rb
CHANGED
@@ -18,12 +18,10 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'ronin/address'
|
21
|
-
require 'ronin/
|
21
|
+
require 'ronin/ip_address'
|
22
|
+
require 'ronin/ip_address_mac_address'
|
22
23
|
|
23
24
|
module Ronin
|
24
|
-
autoload :IPAddressMACAddress, 'ronin/ip_address_mac_address'
|
25
|
-
autoload :IPAddress, 'ronin/ip_address'
|
26
|
-
|
27
25
|
#
|
28
26
|
# Represents MAC addresses that can be stored in the {Database}.
|
29
27
|
#
|
@@ -49,6 +47,8 @@ module Ronin
|
|
49
47
|
#
|
50
48
|
# @since 1.0.0
|
51
49
|
#
|
50
|
+
# @api public
|
51
|
+
#
|
52
52
|
def recent_ip_address
|
53
53
|
self.ip_address_mac_addresses.all(
|
54
54
|
:order => [:created_at.desc]
|
@@ -63,6 +63,8 @@ module Ronin
|
|
63
63
|
#
|
64
64
|
# @since 1.0.0
|
65
65
|
#
|
66
|
+
# @api public
|
67
|
+
#
|
66
68
|
def to_i
|
67
69
|
self.address.split(':').inject(0) do |bits,char|
|
68
70
|
bits = ((bits << 8) | char.hex)
|
@@ -34,6 +34,8 @@ module Ronin
|
|
34
34
|
#
|
35
35
|
# @since 1.0.0
|
36
36
|
#
|
37
|
+
# @api semipublic
|
38
|
+
#
|
37
39
|
def relationship_name
|
38
40
|
name = Support::Inflector.underscore(self.name.split('::').last)
|
39
41
|
|
@@ -43,6 +45,8 @@ module Ronin
|
|
43
45
|
#
|
44
46
|
# Loads and initialize the resources.
|
45
47
|
#
|
48
|
+
# @api private
|
49
|
+
#
|
46
50
|
def load(records,query)
|
47
51
|
resources = super(records,query)
|
48
52
|
resources.each { |resource| resource.send :initialize }
|
@@ -34,6 +34,8 @@ module Ronin
|
|
34
34
|
# @return [Array<Model>]
|
35
35
|
# The resources written by the author.
|
36
36
|
#
|
37
|
+
# @api public
|
38
|
+
#
|
37
39
|
def written_by(name)
|
38
40
|
all('authors.name.like' => "%#{name}%")
|
39
41
|
end
|
@@ -47,6 +49,8 @@ module Ronin
|
|
47
49
|
# @return [Array<Model>]
|
48
50
|
# The resources associated with the organization.
|
49
51
|
#
|
52
|
+
# @api public
|
53
|
+
#
|
50
54
|
def written_for(name)
|
51
55
|
all('authors.organization.like' => "%#{name}%")
|
52
56
|
end
|
@@ -33,6 +33,8 @@ module Ronin
|
|
33
33
|
# @param [Class] base
|
34
34
|
# The model.
|
35
35
|
#
|
36
|
+
# @api semipublic
|
37
|
+
#
|
36
38
|
def self.included(base)
|
37
39
|
base.send :include, Model
|
38
40
|
base.send :extend, ClassMethods
|
@@ -58,6 +60,8 @@ module Ronin
|
|
58
60
|
# :email => 'anon@example.com',
|
59
61
|
# :organization => 'Anonymous LLC'
|
60
62
|
#
|
63
|
+
# @api public
|
64
|
+
#
|
61
65
|
def author(attributes)
|
62
66
|
self.authors.new(attributes)
|
63
67
|
end
|
@@ -33,6 +33,8 @@ module Ronin
|
|
33
33
|
# @param [Class] base
|
34
34
|
# The model.
|
35
35
|
#
|
36
|
+
# @api semipublic
|
37
|
+
#
|
36
38
|
def self.included(base)
|
37
39
|
base.send :include, Model
|
38
40
|
base.send :extend, ClassMethods
|
@@ -59,6 +61,8 @@ module Ronin
|
|
59
61
|
#
|
60
62
|
# @since 1.0.0
|
61
63
|
#
|
64
|
+
# @api public
|
65
|
+
#
|
62
66
|
def license!(name)
|
63
67
|
self.license = Ronin::License.predefined_resource(name)
|
64
68
|
end
|
@@ -32,6 +32,8 @@ module Ronin
|
|
32
32
|
# @param [Class] base
|
33
33
|
# The model.
|
34
34
|
#
|
35
|
+
# @api semipublic
|
36
|
+
#
|
35
37
|
def self.included(base)
|
36
38
|
base.send :include, Model
|
37
39
|
base.send :extend, ClassMethods
|
@@ -50,6 +52,8 @@ module Ronin
|
|
50
52
|
#
|
51
53
|
# @since 1.0.0
|
52
54
|
#
|
55
|
+
# @api public
|
56
|
+
#
|
53
57
|
def to_s
|
54
58
|
self.name.to_s
|
55
59
|
end
|
@@ -33,6 +33,8 @@ module Ronin
|
|
33
33
|
# @param [Class] base
|
34
34
|
# The model.
|
35
35
|
#
|
36
|
+
# @api semipublic
|
37
|
+
#
|
36
38
|
def self.included(base)
|
37
39
|
base.send :include, Model
|
38
40
|
base.send :extend, HasName::ClassMethods,
|
@@ -52,6 +54,8 @@ module Ronin
|
|
52
54
|
#
|
53
55
|
# @since 1.0.0
|
54
56
|
#
|
57
|
+
# @api public
|
58
|
+
#
|
55
59
|
def to_s
|
56
60
|
self.name.to_s
|
57
61
|
end
|
@@ -64,8 +68,10 @@ module Ronin
|
|
64
68
|
#
|
65
69
|
# @since 1.0.0
|
66
70
|
#
|
71
|
+
# @api public
|
72
|
+
#
|
67
73
|
def inspect
|
68
|
-
"#<#{self.class}
|
74
|
+
"#<#{self.class}: #{self.name}>"
|
69
75
|
end
|
70
76
|
end
|
71
77
|
end
|
@@ -34,6 +34,8 @@ module Ronin
|
|
34
34
|
# @return [Array]
|
35
35
|
# The models with the specific version.
|
36
36
|
#
|
37
|
+
# @api public
|
38
|
+
#
|
37
39
|
def revision(version)
|
38
40
|
all(:version => version.to_s)
|
39
41
|
end
|
@@ -41,6 +43,8 @@ module Ronin
|
|
41
43
|
#
|
42
44
|
# Finds latest version of the model.
|
43
45
|
#
|
46
|
+
# @api public
|
47
|
+
#
|
44
48
|
def latest
|
45
49
|
first(:order => [:version.desc])
|
46
50
|
end
|
data/lib/ronin/model/model.rb
CHANGED
data/lib/ronin/model/types.rb
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'ronin/network/esmtp'
|
21
|
+
require 'ronin/ui/output/helpers'
|
22
|
+
require 'ronin/mixin'
|
21
23
|
|
22
24
|
require 'parameters'
|
23
25
|
|
@@ -27,46 +29,55 @@ module Ronin
|
|
27
29
|
#
|
28
30
|
# Adds ESMTP convenience methods and connection parameters to a class.
|
29
31
|
#
|
32
|
+
# Defines the following parameters:
|
33
|
+
#
|
34
|
+
# * `host` (`String`) - ESMTP host.
|
35
|
+
# * `port` (`Integer`) - ESMTP port.
|
36
|
+
# * `esmtp_login` (`String`) - ESMTP authentication method to use.
|
37
|
+
# * `esmtp_user` (`String`) - ESMTP user to login as.
|
38
|
+
# * `esmtp_password` (`String`) - ESMTP password to login with.
|
39
|
+
#
|
30
40
|
module ESMTP
|
31
|
-
include
|
41
|
+
include Mixin
|
32
42
|
|
33
|
-
|
34
|
-
parameter :host,
|
35
|
-
:type => String,
|
36
|
-
:description => 'ESMTP host'
|
43
|
+
mixin UI::Output::Helpers, Parameters
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
mixin do
|
46
|
+
# ESMTP host
|
47
|
+
parameter :host, :type => String,
|
48
|
+
:description => 'ESMTP host'
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
:description => 'ESMTP authentication method to use'
|
50
|
+
# ESMTP port
|
51
|
+
parameter :port, :type => Integer,
|
52
|
+
:description => 'ESMTP port'
|
47
53
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
:description => 'ESMTP user to login as'
|
54
|
+
# ESMTP authentication method to use
|
55
|
+
parameter :esmtp_login, :type => String,
|
56
|
+
:description => 'ESMTP authentication method to use'
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
# ESMTP user to login as
|
59
|
+
parameter :esmtp_user, :type => String,
|
60
|
+
:description => 'ESMTP user to login as'
|
61
|
+
|
62
|
+
# ESMTP password to login with
|
63
|
+
parameter :esmtp_password, :type => String,
|
64
|
+
:description => 'ESMTP password to login with'
|
65
|
+
end
|
57
66
|
|
58
67
|
protected
|
59
68
|
|
60
69
|
#
|
61
70
|
# @see Ronin::Network::SMTP.message.
|
62
71
|
#
|
72
|
+
# @api public
|
73
|
+
#
|
63
74
|
def esmtp_message(options={},&block)
|
64
75
|
Network::SMTP.message(options,&block)
|
65
76
|
end
|
66
77
|
|
67
78
|
#
|
68
|
-
# Creates a connection to the ESMTP server. The
|
69
|
-
#
|
79
|
+
# Creates a connection to the ESMTP server. The `host`, `port`,
|
80
|
+
# `esmtp_login`, `esmtp_user` and `esmtp_password` parameters
|
70
81
|
# will also be used to connect to the ESMTP server.
|
71
82
|
#
|
72
83
|
# @param [Hash] options
|
@@ -98,6 +109,8 @@ module Ronin
|
|
98
109
|
# @return [Net::SMTP]
|
99
110
|
# The ESMTP enabled session.
|
100
111
|
#
|
112
|
+
# @api public
|
113
|
+
#
|
101
114
|
def esmtp_connect(options={},&block)
|
102
115
|
options[:port] ||= self.port
|
103
116
|
options[:login] ||= self.esmtp_login
|
@@ -114,8 +127,8 @@ module Ronin
|
|
114
127
|
end
|
115
128
|
|
116
129
|
#
|
117
|
-
# Starts a session with the ESMTP server. The
|
118
|
-
#
|
130
|
+
# Starts a session with the ESMTP server. The `host`, `port`,
|
131
|
+
# `esmtp_login`, `esmtp_user` and `esmtp_password` parameters
|
119
132
|
# will also be used to connect to the ESMTP server.
|
120
133
|
#
|
121
134
|
# @param [Hash] options
|
@@ -131,6 +144,8 @@ module Ronin
|
|
131
144
|
#
|
132
145
|
# @see esmtp_connect
|
133
146
|
#
|
147
|
+
# @api public
|
148
|
+
#
|
134
149
|
def esmtp_session(options={})
|
135
150
|
esmtp_connect(options) do |sess|
|
136
151
|
yield sess if block_given?
|
@@ -18,6 +18,8 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'ronin/network/http'
|
21
|
+
require 'ronin/ui/output/helpers'
|
22
|
+
require 'ronin/mixin'
|
21
23
|
|
22
24
|
require 'parameters'
|
23
25
|
|
@@ -27,48 +29,57 @@ module Ronin
|
|
27
29
|
#
|
28
30
|
# Adds HTTP convenience methods and connection parameters to a class.
|
29
31
|
#
|
32
|
+
# Defines the following parameters:
|
33
|
+
#
|
34
|
+
# * `host` (`String`) - HTTP host.
|
35
|
+
# * `port` (`Integer`) - HTTP port. Defaults to `Net::HTTP.default_port`.
|
36
|
+
# * `http_vhost` (`String`) - HTTP Host header to send.
|
37
|
+
# * `http_user` (`String`) - HTTP user to authenticate as.
|
38
|
+
# * `http_password` (`String`) - HTTP password to authenticate with.
|
39
|
+
# * `http_proxy` - HTTP proxy information.
|
40
|
+
# * `http_user_agent` (`String`) - HTTP User-Agent header to send.
|
41
|
+
#
|
30
42
|
module HTTP
|
31
|
-
include
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
parameter :http_user_agent,
|
64
|
-
:type => String,
|
65
|
-
:description => 'HTTP User-Agent header to send'
|
43
|
+
include Mixin
|
44
|
+
|
45
|
+
mixin UI::Output::Helpers, Parameters
|
46
|
+
|
47
|
+
mixin do
|
48
|
+
# HTTP host
|
49
|
+
parameter :host, :type => String,
|
50
|
+
:description => 'HTTP host'
|
51
|
+
|
52
|
+
# HTTP port
|
53
|
+
parameter :port, :default => Net::HTTP.default_port,
|
54
|
+
:description => 'HTTP port'
|
55
|
+
|
56
|
+
# HTTP `Host` header to send
|
57
|
+
parameter :http_vhost, :type => String,
|
58
|
+
:description => 'HTTP Host header to send'
|
59
|
+
|
60
|
+
# HTTP user to authenticate as
|
61
|
+
parameter :http_user, :type => String,
|
62
|
+
:description => 'HTTP user to authenticate as'
|
63
|
+
|
64
|
+
# HTTP password to authenticate with
|
65
|
+
parameter :http_password, :type => String,
|
66
|
+
:description => 'HTTP password to authenticate with'
|
67
|
+
|
68
|
+
# HTTP proxy information
|
69
|
+
parameter :http_proxy, :description => 'HTTP proxy information'
|
70
|
+
|
71
|
+
# HTTP `User-Agent` header to send
|
72
|
+
parameter :http_user_agent, :type => String,
|
73
|
+
:description => 'HTTP User-Agent header to send'
|
74
|
+
end
|
66
75
|
|
67
76
|
protected
|
68
77
|
|
69
78
|
#
|
70
79
|
# Resets the HTTP proxy settings.
|
71
80
|
#
|
81
|
+
# @api public
|
82
|
+
#
|
72
83
|
def disable_http_proxy
|
73
84
|
@http_proxy = nil
|
74
85
|
end
|
@@ -109,8 +120,19 @@ module Ronin
|
|
109
120
|
# @return [Net::HTTP]
|
110
121
|
# The HTTP session object.
|
111
122
|
#
|
112
|
-
|
113
|
-
|
123
|
+
# @api public
|
124
|
+
#
|
125
|
+
def http_session(options={})
|
126
|
+
options = http_merge_options(options)
|
127
|
+
host_port = "#{options[:host]}:#{options[:port]}"
|
128
|
+
|
129
|
+
Net.http_session(options) do |http|
|
130
|
+
print_info "Starting HTTP Session with #{host_port}"
|
131
|
+
|
132
|
+
yield http
|
133
|
+
|
134
|
+
print_info "Closing HTTP Session with #{host_port}"
|
135
|
+
end
|
114
136
|
end
|
115
137
|
|
116
138
|
#
|
@@ -138,10 +160,127 @@ module Ronin
|
|
138
160
|
# @return [Net::HTTP::Response]
|
139
161
|
# The response of the HTTP request.
|
140
162
|
#
|
141
|
-
# @see http_session
|
163
|
+
# @see #http_session
|
164
|
+
#
|
165
|
+
# @api public
|
142
166
|
#
|
143
167
|
def http_request(options={},&block)
|
144
|
-
|
168
|
+
options = http_merge_options(options)
|
169
|
+
print_info "HTTP #{options[:method]} #{http_options_to_s(options)}"
|
170
|
+
|
171
|
+
return Net.http_request(options,&block)
|
172
|
+
end
|
173
|
+
|
174
|
+
#
|
175
|
+
# Returns the Status Code of the Response.
|
176
|
+
#
|
177
|
+
# @param [Hash] options
|
178
|
+
# Additional options.
|
179
|
+
#
|
180
|
+
# @option options [Symbol, String] :method (:head)
|
181
|
+
# The method to use for the request.
|
182
|
+
#
|
183
|
+
# @return [Integer]
|
184
|
+
# The HTTP Response Status.
|
185
|
+
#
|
186
|
+
# @see #http_request
|
187
|
+
#
|
188
|
+
# @since 1.1.0
|
189
|
+
#
|
190
|
+
# @api public
|
191
|
+
#
|
192
|
+
def http_status(options={})
|
193
|
+
options = http_merge_options(options)
|
194
|
+
|
195
|
+
if (result = Net.http_status(options))
|
196
|
+
print_debug "HTTP #{result} #{http_options_to_s(options)}"
|
197
|
+
end
|
198
|
+
|
199
|
+
return result
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Checks if the response has an HTTP OK status code.
|
204
|
+
#
|
205
|
+
# @param [Hash] options
|
206
|
+
# Additional options.
|
207
|
+
#
|
208
|
+
# @option options [Symbol, String] :method (:head)
|
209
|
+
# The method to use for the request.
|
210
|
+
#
|
211
|
+
# @return [Boolean]
|
212
|
+
# Specifies wether the response had an HTTP OK status code or not.
|
213
|
+
#
|
214
|
+
# @see #http_status
|
215
|
+
#
|
216
|
+
# @since 1.1.0
|
217
|
+
#
|
218
|
+
# @api public
|
219
|
+
#
|
220
|
+
def http_ok?(options={})
|
221
|
+
options = http_merge_options(options)
|
222
|
+
|
223
|
+
if (result = Net.http_ok?(options))
|
224
|
+
print_debug "HTTP 200 OK #{http_options_to_s(options)}"
|
225
|
+
end
|
226
|
+
|
227
|
+
return result
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# Sends a HTTP Head request and returns the HTTP Server header.
|
232
|
+
#
|
233
|
+
# @param [Hash] options
|
234
|
+
# Additional options.
|
235
|
+
#
|
236
|
+
# @option options [Symbol, String] :method (:head)
|
237
|
+
# The method to use for the request.
|
238
|
+
#
|
239
|
+
# @return [String]
|
240
|
+
# The HTTP `Server` header.
|
241
|
+
#
|
242
|
+
# @see #http_request
|
243
|
+
#
|
244
|
+
# @since 1.1.0
|
245
|
+
#
|
246
|
+
# @api public
|
247
|
+
#
|
248
|
+
def http_server(options={})
|
249
|
+
options = http_merge_options(options)
|
250
|
+
|
251
|
+
if (result = Net.http_server(options))
|
252
|
+
print_debug "HTTP Server: #{result}"
|
253
|
+
end
|
254
|
+
|
255
|
+
return result
|
256
|
+
end
|
257
|
+
|
258
|
+
#
|
259
|
+
# Sends an HTTP Head request and returns the HTTP X-Powered-By header.
|
260
|
+
#
|
261
|
+
# @param [Hash] options
|
262
|
+
# Additional options.
|
263
|
+
#
|
264
|
+
# @option options [Symbol, String] :method (:get)
|
265
|
+
# The method to use for the request.
|
266
|
+
#
|
267
|
+
# @return [String]
|
268
|
+
# The HTTP `X-Powered-By` header.
|
269
|
+
#
|
270
|
+
# @see #http_request
|
271
|
+
#
|
272
|
+
# @since 1.1.0
|
273
|
+
#
|
274
|
+
# @api public
|
275
|
+
#
|
276
|
+
def http_powered_by(options={})
|
277
|
+
options = http_merge_options(options)
|
278
|
+
|
279
|
+
if (result = Net.http_powered_by(options))
|
280
|
+
print_debug "HTTP X-Powered-By: #{result}"
|
281
|
+
end
|
282
|
+
|
283
|
+
return result
|
145
284
|
end
|
146
285
|
|
147
286
|
#
|
@@ -157,10 +296,15 @@ module Ronin
|
|
157
296
|
# @return [Net::HTTP::Response]
|
158
297
|
# The response of the HTTP request.
|
159
298
|
#
|
160
|
-
# @see http_request
|
299
|
+
# @see #http_request
|
300
|
+
#
|
301
|
+
# @api public
|
161
302
|
#
|
162
303
|
def http_copy(options={},&block)
|
163
|
-
|
304
|
+
options = http_merge_options(options)
|
305
|
+
print_info "HTTP COPY #{http_options_to_s(options)}"
|
306
|
+
|
307
|
+
return Net.http_copy(options,&block)
|
164
308
|
end
|
165
309
|
|
166
310
|
#
|
@@ -176,10 +320,15 @@ module Ronin
|
|
176
320
|
# @return [Net::HTTP::Response]
|
177
321
|
# The response of the HTTP request.
|
178
322
|
#
|
179
|
-
# @see http_request
|
323
|
+
# @see #http_request
|
324
|
+
#
|
325
|
+
# @api public
|
180
326
|
#
|
181
327
|
def http_delete(options={},&block)
|
182
|
-
|
328
|
+
options = http_merge_options(options)
|
329
|
+
print_info "HTTP DELETE #{http_options_to_s(options)}"
|
330
|
+
|
331
|
+
return Net.http_delete(options,&block)
|
183
332
|
end
|
184
333
|
|
185
334
|
#
|
@@ -195,10 +344,15 @@ module Ronin
|
|
195
344
|
# @return [Net::HTTP::Response]
|
196
345
|
# The response of the HTTP request.
|
197
346
|
#
|
198
|
-
# @see http_request
|
347
|
+
# @see #http_request
|
348
|
+
#
|
349
|
+
# @api public
|
199
350
|
#
|
200
351
|
def http_get(options={},&block)
|
201
|
-
|
352
|
+
options = http_merge_options(options)
|
353
|
+
print_info "HTTP GET #{http_options_to_s(options)}"
|
354
|
+
|
355
|
+
return Net.http_get(options,&block)
|
202
356
|
end
|
203
357
|
|
204
358
|
#
|
@@ -214,10 +368,15 @@ module Ronin
|
|
214
368
|
# @return [String]
|
215
369
|
# The body of the HTTP Get request.
|
216
370
|
#
|
217
|
-
# @see http_get
|
371
|
+
# @see #http_get
|
372
|
+
#
|
373
|
+
# @api public
|
218
374
|
#
|
219
375
|
def http_get_body(options={},&block)
|
220
|
-
|
376
|
+
options = http_merge_options(options)
|
377
|
+
print_info "HTTP GET #{http_options_to_s(options)}"
|
378
|
+
|
379
|
+
return Net.http_get_body(options,&block)
|
221
380
|
end
|
222
381
|
|
223
382
|
#
|
@@ -233,10 +392,15 @@ module Ronin
|
|
233
392
|
# @return [Net::HTTP::Response]
|
234
393
|
# The response of the HTTP request.
|
235
394
|
#
|
236
|
-
# @see http_request
|
395
|
+
# @see #http_request
|
396
|
+
#
|
397
|
+
# @api public
|
237
398
|
#
|
238
399
|
def http_head(options={},&block)
|
239
|
-
|
400
|
+
options = http_merge_options(options)
|
401
|
+
print_info "HTTP HEAD #{http_options_to_s(options)}"
|
402
|
+
|
403
|
+
return Net.http_head(options,&block)
|
240
404
|
end
|
241
405
|
|
242
406
|
#
|
@@ -252,10 +416,15 @@ module Ronin
|
|
252
416
|
# @return [Net::HTTP::Response]
|
253
417
|
# The response of the HTTP request.
|
254
418
|
#
|
255
|
-
# @see http_request
|
419
|
+
# @see #http_request
|
420
|
+
#
|
421
|
+
# @api public
|
256
422
|
#
|
257
423
|
def http_lock(options={},&block)
|
258
|
-
|
424
|
+
options = http_merge_options(options)
|
425
|
+
print_info "HTTP LOCK #{http_options_to_s(options)}"
|
426
|
+
|
427
|
+
return Net.http_lock(options,&block)
|
259
428
|
end
|
260
429
|
|
261
430
|
#
|
@@ -271,10 +440,15 @@ module Ronin
|
|
271
440
|
# @return [Net::HTTP::Response]
|
272
441
|
# The response of the HTTP request.
|
273
442
|
#
|
274
|
-
# @see http_request
|
443
|
+
# @see #http_request
|
444
|
+
#
|
445
|
+
# @api public
|
275
446
|
#
|
276
447
|
def http_mkcol(options={},&block)
|
277
|
-
|
448
|
+
options = http_merge_options(options)
|
449
|
+
print_info "HTTP MKCOL #{http_options_to_s(options)}"
|
450
|
+
|
451
|
+
return Net.http_mkcol(options,&block)
|
278
452
|
end
|
279
453
|
|
280
454
|
#
|
@@ -290,10 +464,15 @@ module Ronin
|
|
290
464
|
# @return [Net::HTTP::Response]
|
291
465
|
# The response of the HTTP request.
|
292
466
|
#
|
293
|
-
# @see http_request
|
467
|
+
# @see #http_request
|
468
|
+
#
|
469
|
+
# @api public
|
294
470
|
#
|
295
471
|
def http_move(options={},&block)
|
296
|
-
|
472
|
+
options = http_merge_options(options)
|
473
|
+
print_info "HTTP MOVE #{http_options_to_s(options)}"
|
474
|
+
|
475
|
+
return Net.http_move(options,&block)
|
297
476
|
end
|
298
477
|
|
299
478
|
#
|
@@ -309,10 +488,15 @@ module Ronin
|
|
309
488
|
# @return [Net::HTTP::Response]
|
310
489
|
# The response of the HTTP request.
|
311
490
|
#
|
312
|
-
# @see http_request
|
491
|
+
# @see #http_request
|
492
|
+
#
|
493
|
+
# @api public
|
313
494
|
#
|
314
495
|
def http_options(options={},&block)
|
315
|
-
|
496
|
+
options = http_merge_options(options)
|
497
|
+
print_info "HTTP OPTIONS #{http_options_to_s(options)}"
|
498
|
+
|
499
|
+
return Net.http_options(options,&block)
|
316
500
|
end
|
317
501
|
|
318
502
|
#
|
@@ -334,10 +518,15 @@ module Ronin
|
|
334
518
|
# @return [Net::HTTP::Response]
|
335
519
|
# The response of the HTTP request.
|
336
520
|
#
|
337
|
-
# @see http_request
|
521
|
+
# @see #http_request
|
522
|
+
#
|
523
|
+
# @api public
|
338
524
|
#
|
339
525
|
def http_post(options={},&block)
|
340
|
-
|
526
|
+
options = http_merge_options(options)
|
527
|
+
print_info "HTTP POST #{http_options_to_s(options)}"
|
528
|
+
|
529
|
+
return Net.http_post(options,&block)
|
341
530
|
end
|
342
531
|
|
343
532
|
#
|
@@ -353,10 +542,15 @@ module Ronin
|
|
353
542
|
# @return [String]
|
354
543
|
# The body of the Post request.
|
355
544
|
#
|
356
|
-
# @see http_post
|
545
|
+
# @see #http_post
|
546
|
+
#
|
547
|
+
# @api public
|
357
548
|
#
|
358
549
|
def http_post_body(options={},&block)
|
359
|
-
|
550
|
+
options = http_merge_options(options)
|
551
|
+
print_info "HTTP POST #{http_options_to_s(options)}"
|
552
|
+
|
553
|
+
return Net.http_post_body(options,&block)
|
360
554
|
end
|
361
555
|
|
362
556
|
#
|
@@ -372,10 +566,15 @@ module Ronin
|
|
372
566
|
# @return [Net::HTTP::Response]
|
373
567
|
# The response of the HTTP request.
|
374
568
|
#
|
375
|
-
# @see http_request
|
569
|
+
# @see #http_request
|
570
|
+
#
|
571
|
+
# @api public
|
376
572
|
#
|
377
573
|
def http_prop_find(options={},&block)
|
378
|
-
|
574
|
+
options = http_merge_options(options)
|
575
|
+
print_info "HTTP PROPFIND #{http_options_to_s(options)}"
|
576
|
+
|
577
|
+
return Net.http_prop_find(options,&block)
|
379
578
|
end
|
380
579
|
|
381
580
|
#
|
@@ -391,10 +590,15 @@ module Ronin
|
|
391
590
|
# @return [Net::HTTP::Response]
|
392
591
|
# The response of the HTTP request.
|
393
592
|
#
|
394
|
-
# @see http_request
|
593
|
+
# @see #http_request
|
594
|
+
#
|
595
|
+
# @api public
|
395
596
|
#
|
396
597
|
def http_prop_patch(options={},&block)
|
397
|
-
|
598
|
+
options = http_merge_options(options)
|
599
|
+
print_info "HTTP PROPPATCH #{http_options_to_s(options)}"
|
600
|
+
|
601
|
+
return Net.http_prop_patch(options,&block)
|
398
602
|
end
|
399
603
|
|
400
604
|
#
|
@@ -410,10 +614,15 @@ module Ronin
|
|
410
614
|
# @return [Net::HTTP::Response]
|
411
615
|
# The response of the HTTP request.
|
412
616
|
#
|
413
|
-
# @see http_request
|
617
|
+
# @see #http_request
|
618
|
+
#
|
619
|
+
# @api public
|
414
620
|
#
|
415
621
|
def http_trace(options={},&block)
|
416
|
-
|
622
|
+
options = http_merge_options(options)
|
623
|
+
print_info "HTTP TRACE #{http_options_to_s(options)}"
|
624
|
+
|
625
|
+
return Net.http_trace(options,&block)
|
417
626
|
end
|
418
627
|
|
419
628
|
#
|
@@ -429,31 +638,85 @@ module Ronin
|
|
429
638
|
# @return [Net::HTTP::Response]
|
430
639
|
# The response of the HTTP request.
|
431
640
|
#
|
432
|
-
# @see http_request
|
641
|
+
# @see #http_request
|
642
|
+
#
|
643
|
+
# @api public
|
433
644
|
#
|
434
645
|
def http_unlock(options={},&block)
|
435
|
-
|
646
|
+
options = http_merge_options(options)
|
647
|
+
print_info "HTTP UNLOCK #{http_options_to_s(options)}"
|
648
|
+
|
649
|
+
return Net.http_unlock(options,&block)
|
436
650
|
end
|
437
651
|
|
438
652
|
private
|
439
653
|
|
654
|
+
#
|
655
|
+
# Merges the HTTP parameters into the HTTP options.
|
656
|
+
#
|
657
|
+
# @param [Hash] options
|
658
|
+
# The HTTP options to merge into.
|
659
|
+
#
|
660
|
+
# @return [Hash]
|
661
|
+
# The merged HTTP options.
|
662
|
+
#
|
663
|
+
# @since 1.0.0
|
664
|
+
#
|
665
|
+
# @api private
|
666
|
+
#
|
440
667
|
def http_merge_options(options={})
|
441
668
|
options[:host] ||= self.host if self.host
|
442
669
|
options[:port] ||= self.port if self.port
|
443
670
|
|
444
|
-
|
445
|
-
|
671
|
+
if (self.http_vhost || self.http_user_agent)
|
672
|
+
headers = options.fetch(:headers,{})
|
673
|
+
|
674
|
+
headers[:host] ||= self.http_vhost if self.http_vhost
|
675
|
+
headers[:user_agent] ||= self.http_user_agent if self.http_user_agent
|
446
676
|
|
447
|
-
|
677
|
+
options[:headers] = headers
|
678
|
+
end
|
448
679
|
|
449
680
|
options[:user] ||= self.http_user if self.http_user
|
450
681
|
options[:password] ||= self.http_password if self.http_password
|
451
682
|
|
452
683
|
options[:proxy] ||= self.http_proxy if self.http_proxy
|
453
|
-
options[:user_agent] ||= self.http_user_agent if self.http_user_agent
|
454
684
|
|
455
685
|
return options
|
456
686
|
end
|
687
|
+
|
688
|
+
#
|
689
|
+
# Converts the HTTP options to a printable String.
|
690
|
+
#
|
691
|
+
# @param [Hash] options
|
692
|
+
# HTTP options.
|
693
|
+
#
|
694
|
+
# @return [String]
|
695
|
+
# The printable String.
|
696
|
+
#
|
697
|
+
# @since 1.1.0
|
698
|
+
#
|
699
|
+
# @api private
|
700
|
+
#
|
701
|
+
def http_options_to_s(options)
|
702
|
+
fields = ["#{options[:host]}:#{options[:port]}"]
|
703
|
+
|
704
|
+
if (options[:user] || options[:password])
|
705
|
+
fields << "#{options[:user]}:#{options[:password]}"
|
706
|
+
end
|
707
|
+
|
708
|
+
path = options[:path]
|
709
|
+
path += "?#{options[:query]}" if options[:query]
|
710
|
+
|
711
|
+
fields << path
|
712
|
+
|
713
|
+
if options[:headers]
|
714
|
+
fields << ("%p" % options[:headers])
|
715
|
+
end
|
716
|
+
|
717
|
+
return fields.join(' ')
|
718
|
+
end
|
719
|
+
|
457
720
|
end
|
458
721
|
end
|
459
722
|
end
|