ronin-exploits 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +122 -0
  3. data/Manifest.txt +110 -20
  4. data/README.txt +112 -31
  5. data/Rakefile +12 -1
  6. data/bin/ronin-exploit +12 -0
  7. data/bin/ronin-exploits +1 -1
  8. data/bin/ronin-gen-binary-payload +12 -0
  9. data/bin/ronin-gen-exploit +12 -0
  10. data/bin/ronin-gen-ftp-exploit +12 -0
  11. data/bin/ronin-gen-http-exploit +12 -0
  12. data/bin/ronin-gen-local-exploit +12 -0
  13. data/bin/ronin-gen-nops +12 -0
  14. data/bin/ronin-gen-payload +12 -0
  15. data/bin/ronin-gen-remote-exploit +12 -0
  16. data/bin/ronin-gen-remote-tcp-exploit +12 -0
  17. data/bin/ronin-gen-remote-udp-exploit +12 -0
  18. data/bin/ronin-gen-shellcode +12 -0
  19. data/bin/ronin-gen-web-exploit +12 -0
  20. data/bin/ronin-payload +1 -1
  21. data/bin/ronin-payloads +1 -1
  22. data/lib/ronin/controls.rb +23 -0
  23. data/lib/ronin/controls/behaviors.rb +133 -0
  24. data/lib/ronin/{payloads/helpers → controls}/exceptions.rb +2 -4
  25. data/lib/ronin/{payloads/arch.rb → controls/exceptions/not_implemented.rb} +3 -8
  26. data/lib/ronin/controls/exceptions/program_not_found.rb +27 -0
  27. data/lib/ronin/controls/file_system.rb +145 -0
  28. data/lib/ronin/{exploits/os.rb → controls/helpers.rb} +12 -13
  29. data/lib/ronin/controls/helpers/command_exec.rb +143 -0
  30. data/lib/ronin/controls/helpers/dir_create.rb +42 -0
  31. data/lib/ronin/controls/helpers/dir_listing.rb +62 -0
  32. data/lib/ronin/controls/helpers/dir_remove.rb +42 -0
  33. data/lib/ronin/controls/helpers/file_ctime.rb +52 -0
  34. data/lib/ronin/controls/helpers/file_mtime.rb +53 -0
  35. data/lib/ronin/controls/helpers/file_ownership.rb +53 -0
  36. data/lib/ronin/controls/helpers/file_read.rb +62 -0
  37. data/lib/ronin/controls/helpers/file_remove.rb +51 -0
  38. data/lib/ronin/controls/helpers/file_write.rb +62 -0
  39. data/lib/ronin/controls/helpers/memory_read.rb +39 -0
  40. data/lib/ronin/controls/helpers/memory_write.rb +39 -0
  41. data/lib/ronin/exploits.rb +0 -2
  42. data/lib/ronin/exploits/{allow.rb → control.rb} +5 -9
  43. data/lib/ronin/exploits/exceptions.rb +1 -2
  44. data/lib/ronin/exploits/exceptions/exception.rb +27 -0
  45. data/lib/ronin/exploits/exceptions/exploit_not_built.rb +3 -3
  46. data/lib/ronin/exploits/exceptions/payload_size.rb +3 -3
  47. data/lib/ronin/exploits/exceptions/restricted_char.rb +3 -3
  48. data/lib/ronin/exploits/exceptions/target_data_missing.rb +3 -3
  49. data/lib/ronin/exploits/exceptions/target_unspecified.rb +3 -3
  50. data/lib/ronin/exploits/exceptions/unknown_helper.rb +3 -3
  51. data/lib/ronin/exploits/exploit.rb +449 -92
  52. data/lib/ronin/exploits/exploit_author.rb +2 -3
  53. data/lib/ronin/exploits/ftp.rb +7 -2
  54. data/lib/ronin/exploits/helpers.rb +0 -2
  55. data/lib/ronin/exploits/helpers/binary.rb +11 -5
  56. data/lib/ronin/exploits/helpers/buffer_overflow.rb +38 -25
  57. data/lib/ronin/exploits/helpers/file_based.rb +29 -30
  58. data/lib/ronin/exploits/helpers/format_string.rb +34 -24
  59. data/lib/ronin/exploits/helpers/padding.rb +33 -16
  60. data/lib/ronin/exploits/http.rb +9 -4
  61. data/lib/ronin/exploits/local.rb +8 -2
  62. data/lib/ronin/exploits/remote.rb +8 -2
  63. data/lib/ronin/exploits/remote_tcp.rb +26 -8
  64. data/lib/ronin/exploits/remote_udp.rb +26 -8
  65. data/lib/ronin/exploits/target.rb +41 -30
  66. data/lib/ronin/exploits/targets.rb +0 -2
  67. data/lib/ronin/exploits/targets/buffer_overflow.rb +0 -2
  68. data/lib/ronin/exploits/targets/format_string.rb +0 -2
  69. data/lib/ronin/exploits/verifiers.rb +45 -16
  70. data/lib/ronin/exploits/version.rb +1 -3
  71. data/lib/ronin/exploits/web.rb +18 -6
  72. data/lib/ronin/generators/exploits.rb +23 -0
  73. data/lib/ronin/generators/exploits/exploit.rb +70 -0
  74. data/lib/ronin/generators/exploits/ftp.rb +42 -0
  75. data/lib/ronin/generators/exploits/http.rb +42 -0
  76. data/lib/ronin/generators/exploits/local.rb +42 -0
  77. data/lib/ronin/generators/exploits/remote.rb +42 -0
  78. data/lib/ronin/generators/exploits/remote_tcp.rb +44 -0
  79. data/lib/ronin/generators/exploits/remote_udp.rb +44 -0
  80. data/lib/ronin/{exploits/arch.rb → generators/exploits/static.rb} +5 -9
  81. data/lib/ronin/generators/exploits/web.rb +45 -0
  82. data/lib/ronin/generators/payloads.rb +23 -0
  83. data/lib/ronin/generators/payloads/binary_payload.rb +42 -0
  84. data/lib/ronin/generators/payloads/nops.rb +42 -0
  85. data/lib/ronin/generators/payloads/payload.rb +66 -0
  86. data/lib/ronin/generators/payloads/shellcode.rb +42 -0
  87. data/lib/ronin/generators/payloads/static.rb +30 -0
  88. data/lib/ronin/model/has_default_port.rb +6 -6
  89. data/lib/ronin/model/targets_arch.rb +18 -7
  90. data/lib/ronin/model/targets_os.rb +18 -8
  91. data/lib/ronin/model/targets_product.rb +68 -0
  92. data/lib/ronin/payloads.rb +0 -2
  93. data/lib/ronin/payloads/asm_payload.rb +8 -2
  94. data/lib/ronin/payloads/binary_payload.rb +8 -2
  95. data/lib/ronin/payloads/control.rb +1 -5
  96. data/lib/ronin/payloads/encoders.rb +1 -2
  97. data/lib/ronin/payloads/encoders/encoder.rb +92 -0
  98. data/lib/ronin/payloads/encoders/xor.rb +4 -6
  99. data/lib/ronin/payloads/exceptions.rb +1 -2
  100. data/lib/ronin/payloads/{helpers/exceptions/not_implemented.rb → exceptions/exception.rb} +1 -5
  101. data/lib/ronin/payloads/{helpers/exceptions/program_not_found.rb → exceptions/not_implemented.rb} +3 -5
  102. data/lib/ronin/payloads/exceptions/unknown_helper.rb +3 -3
  103. data/lib/ronin/payloads/has_payload.rb +111 -0
  104. data/lib/ronin/payloads/helpers.rb +1 -4
  105. data/lib/ronin/payloads/helpers/chained.rb +61 -0
  106. data/lib/ronin/payloads/helpers/rpc.rb +31 -21
  107. data/lib/ronin/payloads/nops.rb +7 -2
  108. data/lib/ronin/payloads/payload.rb +144 -85
  109. data/lib/ronin/payloads/payload_author.rb +2 -3
  110. data/lib/ronin/payloads/shellcode.rb +8 -5
  111. data/lib/ronin/payloads/web_payload.rb +8 -2
  112. data/lib/ronin/ui/command_line/commands/exploit.rb +193 -0
  113. data/lib/ronin/ui/command_line/commands/exploits.rb +102 -25
  114. data/lib/ronin/ui/command_line/commands/gen_binary_payload.rb +34 -0
  115. data/lib/ronin/ui/command_line/commands/gen_exploit.rb +34 -0
  116. data/lib/ronin/ui/command_line/commands/gen_ftp_exploit.rb +34 -0
  117. data/lib/ronin/ui/command_line/commands/gen_http_exploit.rb +34 -0
  118. data/lib/ronin/ui/command_line/commands/gen_local_exploit.rb +34 -0
  119. data/lib/ronin/{exploits/license.rb → ui/command_line/commands/gen_nops.rb} +8 -8
  120. data/lib/ronin/ui/command_line/commands/gen_payload.rb +34 -0
  121. data/lib/ronin/ui/command_line/commands/gen_remote_exploit.rb +34 -0
  122. data/lib/ronin/ui/command_line/commands/gen_remote_tcp_exploit.rb +34 -0
  123. data/lib/ronin/ui/command_line/commands/gen_remote_udp_exploit.rb +34 -0
  124. data/lib/ronin/ui/command_line/commands/gen_shellcode.rb +34 -0
  125. data/lib/ronin/ui/command_line/commands/gen_web_exploit.rb +34 -0
  126. data/lib/ronin/ui/command_line/commands/payload.rb +73 -50
  127. data/lib/ronin/ui/command_line/commands/payloads.rb +78 -23
  128. data/lib/ronin/vuln/behavior.rb +101 -28
  129. data/spec/controls/behaviors_examples.rb +38 -0
  130. data/spec/exploits/exploit_spec.rb +177 -23
  131. data/spec/exploits/file_based_exploit_spec.rb +16 -7
  132. data/spec/exploits/remote_tcp_spec.rb +1 -1
  133. data/spec/exploits/remote_udp_spec.rb +1 -1
  134. data/spec/generators/exploits/exploit_examples.rb +24 -0
  135. data/spec/generators/exploits/exploit_spec.rb +42 -0
  136. data/spec/generators/exploits/ftp_spec.rb +42 -0
  137. data/spec/generators/exploits/http_spec.rb +42 -0
  138. data/spec/generators/exploits/local_spec.rb +42 -0
  139. data/spec/generators/exploits/remote_spec.rb +42 -0
  140. data/spec/generators/exploits/remote_tcp_spec.rb +47 -0
  141. data/spec/generators/exploits/remote_udp_spec.rb +47 -0
  142. data/spec/generators/exploits/web_spec.rb +52 -0
  143. data/spec/generators/payloads/binary_payload_spec.rb +31 -0
  144. data/spec/generators/payloads/nops_spec.rb +31 -0
  145. data/spec/generators/payloads/payload_examples.rb +16 -0
  146. data/spec/generators/payloads/payload_spec.rb +31 -0
  147. data/spec/generators/payloads/shellcode_spec.rb +31 -0
  148. data/spec/model/models/targets_product_model.rb +11 -0
  149. data/spec/model/targets_arch_spec.rb +11 -1
  150. data/spec/model/targets_os_spec.rb +11 -1
  151. data/spec/model/targets_product_spec.rb +35 -0
  152. data/spec/objects/exploits/{test.rb → simple.rb} +1 -1
  153. data/spec/objects/payloads/{test.rb → simple.rb} +6 -2
  154. data/spec/payloads/encoders/encoder_spec.rb +30 -0
  155. data/spec/payloads/encoders/xor_spec.rb +1 -1
  156. data/spec/payloads/payload_spec.rb +41 -43
  157. data/spec/spec_helper.rb +4 -1
  158. data/static/ronin/generators/exploits/_cache.erb +14 -0
  159. data/static/ronin/generators/exploits/_header.erb +1 -0
  160. data/static/ronin/generators/exploits/_helpers.erb +4 -0
  161. data/static/ronin/generators/exploits/exploit.erb +24 -0
  162. data/static/ronin/generators/exploits/ftp.erb +24 -0
  163. data/static/ronin/generators/exploits/http.erb +26 -0
  164. data/static/ronin/generators/exploits/local.erb +24 -0
  165. data/static/ronin/generators/exploits/remote.erb +24 -0
  166. data/static/ronin/generators/exploits/remote_tcp.erb +26 -0
  167. data/static/ronin/generators/exploits/remote_udp.erb +26 -0
  168. data/static/ronin/generators/exploits/web.erb +28 -0
  169. data/static/ronin/generators/payloads/_cache.erb +10 -0
  170. data/static/ronin/generators/payloads/_header.erb +1 -0
  171. data/static/ronin/generators/payloads/_helpers.erb +2 -0
  172. data/static/ronin/generators/payloads/binary_payload.erb +25 -0
  173. data/static/ronin/generators/payloads/nops.erb +19 -0
  174. data/static/ronin/generators/payloads/payload.erb +25 -0
  175. data/static/ronin/generators/payloads/shellcode.erb +25 -0
  176. data/tasks/spec.rb +1 -0
  177. data/tasks/yard.rb +13 -0
  178. metadata +162 -30
  179. metadata.gz.sig +0 -0
  180. data/TODO.txt +0 -22
  181. data/lib/ronin/exploits/product.rb +0 -34
  182. data/lib/ronin/payloads/encoder.rb +0 -84
  183. data/lib/ronin/payloads/helpers/file_system.rb +0 -187
  184. data/lib/ronin/payloads/helpers/shell.rb +0 -91
  185. data/lib/ronin/payloads/license.rb +0 -34
  186. data/lib/ronin/payloads/os.rb +0 -34
  187. data/spec/payloads/encoder_spec.rb +0 -30
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Exploits - A Ruby library for Ronin that provides exploitation and
4
3
  # payload crafting functionality.
5
4
  #
@@ -18,7 +17,6 @@
18
17
  # You should have received a copy of the GNU General Public License
19
18
  # along with this program; if not, write to the Free Software
20
19
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- #++
22
20
  #
23
21
 
24
22
  require 'ronin/ui/command_line/command'
@@ -32,38 +30,95 @@ module Ronin
32
30
  module Commands
33
31
  class Payloads < Command
34
32
 
35
- def defaults
36
- @query = {}
37
- end
33
+ desc "payloads [options]", "Lists the available Payloads"
34
+ method_option :database, :type => :string, :default => Database.config, :aliases => '-D'
35
+ method_option :name, :type => :string, :aliases => '-n'
36
+ method_option :version, :type => :string, :aliases => '-v'
37
+ method_option :describing, :stype => :string, :aliases => '-d'
38
+ method_option :license, :type => :string, :aliases => '-l'
39
+ method_option :arch, :type => :string, :aliases => '-a'
40
+ method_option :os, :type => :string, :aliases => '-o'
41
+ method_option :verbose, :type => :boolean, :aliases => '-v'
38
42
 
39
- def define_options(opts)
40
- opts.usage = '[options]'
43
+ def default
44
+ Database.setup(options[:database])
41
45
 
42
- opts.options do
43
- opts.on('-D','--database URI','The URI for the database') do |uri|
44
- Database.config = uri.to_s
45
- end
46
+ payloads = Ronin::Payloads::Payload.all
46
47
 
47
- opts.on('-n','--name NAME','Search for payloads with the similar NAME') do |name|
48
- @query[:name.like] = name.to_s
49
- end
48
+ if options[:name]
49
+ payloads = payloads.named(options[:name])
50
+ end
50
51
 
51
- opts.on('-v','--version VERSION','Search for payloads with the similar VERSION') do |version|
52
- @query[:version.like] = version.to_s
53
- end
52
+ if options[:version]
53
+ payloads = payloads.revision(options[:version])
54
+ end
55
+
56
+ if options[:describing]
57
+ payloads = payloads.describing(options[:describing])
54
58
  end
55
- end
56
59
 
57
- def arguments(*args)
58
- Database.setup
60
+ if options[:license]
61
+ payloads = payloads.licensed_under(options[:license])
62
+ end
59
63
 
60
- payloads = Ronin::Payloads::Payload.all(@query)
64
+ if options[:arch]
65
+ payloads = payloads.targeting_arch(options[:arch])
66
+ end
67
+
68
+ if options[:os]
69
+ payloads = payloads.targeting_os(options[:os])
70
+ end
61
71
 
62
72
  if payloads.empty?
63
- fail("could not find similar payloads")
73
+ print_error "Could not find similar payloads"
74
+ exit -1
75
+ end
76
+
77
+ if options.verbose?
78
+ payloads.each { |payload| print_payload(payload) }
79
+ else
80
+ indent do
81
+ payloads.each { |payload| puts payload }
82
+ end
64
83
  end
84
+ end
85
+
86
+ protected
87
+
88
+ def print_payload(payload)
89
+ attributes = payload.humanize_attributes(
90
+ :exclude => [:description]
91
+ )
92
+ attributes['Arch'] = payload.arch if payload.arch
93
+ attributes['OS'] = payload.os if payload.os
94
+
95
+ print_hash(attributes, :title => "Payload: #{payload}")
96
+
97
+ indent do
98
+ if payload.description
99
+ puts "Description:\n\n"
100
+ indent do
101
+ payload.description.each_line { |line| puts line }
102
+ end
103
+ puts "\n"
104
+ end
65
105
 
66
- payloads.each { |payload| puts " #{payload.name}" }
106
+ unless payload.authors.empty?
107
+ payload.authors.each do |author|
108
+ print_hash(author.humanize_attributes, :title => 'Author')
109
+ end
110
+ end
111
+
112
+ unless payload.behaviors.empty?
113
+ print_array(payload.behaviors, :title => 'Controls')
114
+ end
115
+
116
+ attempt { payload.load_original! }
117
+
118
+ unless payload.params.empty?
119
+ print_array(payload.params.values, :title => 'Parameters')
120
+ end
121
+ end
67
122
  end
68
123
 
69
124
  end
@@ -1,5 +1,4 @@
1
1
  #
2
- #--
3
2
  # Ronin Exploits - A Ruby library for Ronin that provides exploitation and
4
3
  # payload crafting functionality.
5
4
  #
@@ -18,7 +17,6 @@
18
17
  # You should have received a copy of the GNU General Public License
19
18
  # along with this program; if not, write to the Free Software
20
19
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- #++
22
20
  #
23
21
 
24
22
  require 'ronin/extensions/meta'
@@ -48,7 +46,10 @@ module Ronin
48
46
  validates_is_unique :name
49
47
 
50
48
  #
51
- # Returns the name of the behavior.
49
+ # Converts the behavior to a String.
50
+ #
51
+ # @return [String]
52
+ # The name of the behavior.
52
53
  #
53
54
  def to_s
54
55
  @name.to_s
@@ -57,35 +58,107 @@ module Ronin
57
58
  protected
58
59
 
59
60
  #
60
- # Defines a new builtin Behavior with the specified _name_ and the
61
- # given _description_.
61
+ # Defines a new builtin Behavior.
62
+ #
63
+ # @param [Symbol, String] name
64
+ # The name of the behavior to predefine.
65
+ #
66
+ # @param [String] description
67
+ # The description of the behavior.
68
+ #
69
+ # @example Defining a builtin Behavior
70
+ # Behavior.predefine :command_exec, "Arbitrary command execution"
62
71
  #
63
- def self.define(name,description=nil)
72
+ # @example Retrieving a predefined behavior
73
+ # Behavior.command_exec
74
+ #
75
+ def self.predefine(name,description=nil)
64
76
  super(name,:name => name.to_s, :description => description)
65
77
  end
66
78
 
67
- define :memory_read, "The ability to read memory"
68
- define :memory_write, "The ability to write to memory"
69
- define :file_create, "Arbitrary file creation"
70
- define :file_read, "The ability to read from a file"
71
- define :file_write, "The ability to write to a file"
72
- define :file_modify, "The ability to modify an existing file"
73
- define :file_ownership, "The ability to change ownership of an existing file"
74
- define :file_mtime, "The ability to change the modification timestamp of a file"
75
- define :file_ctime, "The ability to change the creation timestamp of a file"
76
- define :socket_redirect, "The ability to redirect a socket's connection"
77
- define :socket_connect, "The ability to create a network socket"
78
- define :socket_listen, "The ability to listen on a network socket"
79
- define :socket_read, "The ability to read from a network socket"
80
- define :socket_write, "The ability to write to a network socket"
81
- define :code_exec, "Arbitrary code execution"
82
- define :command_exec, "Arbitrary command execution"
83
- define :auth_bypass, "Authentication by-pass"
84
- define :priv_escalation, "Privilege escalation"
85
- define :exhaust_memory, "Exhaust freely available memory"
86
- define :exhaust_disk, "Exhaust freely available disk-space"
87
- define :exhaust_bandwidth, "Exhaust available bandwidth"
88
- define :exahust_cpu, "Exhaust CPU performance"
79
+ # The ability to read memory
80
+ predefine :memory_read, "The ability to read memory"
81
+
82
+ # The ability to write to memory
83
+ predefine :memory_write, "The ability to write to memory"
84
+
85
+ # The ability to execute from memory
86
+ predefine :memory_exec, "The ability to execute memory"
87
+
88
+ # The ability to create files
89
+ predefine :file_create, "Arbitrary file creation"
90
+
91
+ # The ability to read files
92
+ predefine :file_read, "The ability to read from a file"
93
+
94
+ # The ability to write to a file
95
+ predefine :file_write, "The ability to write to a file"
96
+
97
+ # The ability to modify existing files
98
+ predefine :file_modify, "The ability to modify an existing file"
99
+
100
+ # The ability to change ownership on files
101
+ predefine :file_ownership, "The ability to change ownership of an existing file"
102
+
103
+ # The ability to change the modification time on files
104
+ predefine :file_mtime, "The ability to change the modification timestamp of a file"
105
+
106
+ # The ability to change the creation time on files
107
+ predefine :file_ctime, "The ability to change the creation timestamp of a file"
108
+
109
+ # The ability to create directories
110
+ predefine :dir_create, "The ability to create a directory"
111
+
112
+ # The ability to list the contents of directories
113
+ predefine :dir_listing, "The ability to list the contents of a directory"
114
+
115
+ # The ability to redirect socket connections
116
+ predefine :socket_redirect, "The ability to redirect a socket's connection"
117
+
118
+ # The ability to create socket connections
119
+ predefine :socket_connect, "The ability to create a network socket"
120
+
121
+ # The ability to listen on a socket
122
+ predefine :socket_listen, "The ability to listen on a network socket"
123
+
124
+ # The ability to read from a socket
125
+ predefine :socket_read, "The ability to read from a network socket"
126
+
127
+ # The ability to write to a socket
128
+ predefine :socket_write, "The ability to write to a network socket"
129
+
130
+ # The ability to execute code
131
+ predefine :code_exec, "Arbitrary code execution"
132
+
133
+ # The ability to execute commands
134
+ predefine :command_exec, "Arbitrary command execution"
135
+
136
+ # The ability to bypass authentication
137
+ predefine :auth_bypass, "Authentication by-pass"
138
+
139
+ # The ability to gain privileges
140
+ predefine :gain_privileges, "Gain privileges"
141
+
142
+ # The ability to drop privileges
143
+ predefine :drop_privileges, "Drop privileges"
144
+
145
+ # The ability to safely exit a running program
146
+ predefine :exit_program, "Exit program"
147
+
148
+ # The ability to crash a running program
149
+ predefine :crash_program, "Crash program"
150
+
151
+ # The ability to exhaust available memory
152
+ predefine :exhaust_memory, "Exhaust freely available memory"
153
+
154
+ # The ability to exhaust available disk space
155
+ predefine :exhaust_disk, "Exhaust freely available disk-space"
156
+
157
+ # The ability to exhaust available network bandwidth
158
+ predefine :exhaust_bandwidth, "Exhaust available bandwidth"
159
+
160
+ # The ability to exhaust CPU access
161
+ predefine :exhaust_cpu, "Exhaust CPU performance"
89
162
 
90
163
  end
91
164
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "controls behaviors" do
4
+ it "should have a model to represent the controled behaviors" do
5
+ @controler.control_model.include?(Ronin::Model).should == true
6
+ end
7
+
8
+ it "should not have any controled behaviors by default" do
9
+ @controler.controls.should be_empty
10
+ end
11
+
12
+ it "should specify what behaviors to be controled" do
13
+ @controler.control :memory_read, :memory_write
14
+
15
+ @controler.behaviors.should == [:memory_read, :memory_write]
16
+ end
17
+
18
+ it "should extend a control module if on exists for the behavior" do
19
+ @controler.control :command_exec
20
+
21
+ @controler.behaviors.should == [:command_exec]
22
+ @controler.kind_of?(Ronin::Controls::Helpers::CommandExec).should == true
23
+ end
24
+
25
+ it "should not extend a control module if none exist for the behavior" do
26
+ @controler.control :exhaust_memory
27
+
28
+ @controler.behaviors.should == [:exhaust_memory]
29
+ end
30
+
31
+ it "should load the control modules for the behaviors" do
32
+ @controler.control :command_exec
33
+ @controler.cache!
34
+
35
+ cached = @controler.class.load_first(:name => @controler.name)
36
+ cached.kind_of?(Ronin::Controls::Helpers::CommandExec).should == true
37
+ end
38
+ end
@@ -2,12 +2,17 @@ require 'ronin/exploits/exploit'
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'helpers/objects'
5
+ require 'controls/behaviors_examples'
5
6
 
6
7
  describe Exploits::Exploit do
7
8
  before(:each) do
8
- @exploit = load_exploit('test')
9
+ @exploit = load_exploit('simple')
10
+ @payload = load_payload('simple')
11
+ @controler = @exploit
9
12
  end
10
13
 
14
+ it_should_behave_like "controls behaviors"
15
+
11
16
  it "should require a name attribute" do
12
17
  exp2 = Exploits::Exploit.new
13
18
  exp2.should_not be_valid
@@ -36,19 +41,6 @@ describe Exploits::Exploit do
36
41
  third_exp.should be_valid
37
42
  end
38
43
 
39
- it "should not have any allowances by default" do
40
- @exploit.allows.should be_empty
41
- end
42
-
43
- it "should specify the behaviors allowed by the exploit" do
44
- @exploit.allowing :memory_read, :memory_write
45
-
46
- @exploit.behaviors.should == [
47
- Vuln::Behavior[:memory_read],
48
- Vuln::Behavior[:memory_write]
49
- ]
50
- end
51
-
52
44
  it "should allow for the extending of Helper modules" do
53
45
  @exploit.instance_eval { helper :padding }.should == true
54
46
  end
@@ -76,8 +68,20 @@ describe Exploits::Exploit do
76
68
  }.should == true
77
69
  end
78
70
 
79
- it "should allow the explicit selection of a target" do
80
- @exploit.select_target { |target| target.arch == Arch.i686 }
71
+ it "should allow the selection of a target by index" do
72
+ @exploit.use_target!(1)
73
+
74
+ @exploit.target.arch.should == Arch.i386
75
+ end
76
+
77
+ it "should allow the selection of a target that matches a block" do
78
+ @exploit.use_target! { |target| target.arch == Arch.i386 }
79
+
80
+ @exploit.target.arch.should == Arch.i386
81
+ end
82
+
83
+ it "should select the first target if nothing is passed to use_target!" do
84
+ @exploit.use_target!()
81
85
 
82
86
  @exploit.target.arch.should == Arch.i686
83
87
  end
@@ -104,15 +108,110 @@ describe Exploits::Exploit do
104
108
  @exploit.product.version.should == '1.5'
105
109
  end
106
110
 
111
+ it "should set the payloads exploit when setting the payload" do
112
+ @payload.exploit.should be_nil
113
+
114
+ @exploit.payload = @payload
115
+ @payload.exploit.should == @exploit
116
+ end
117
+
118
+ it "should be able to set the payload to nil" do
119
+ @exploit.payload = @payload
120
+ @exploit.payload = nil
121
+
122
+ @exploit.payload.should be_nil
123
+ end
124
+
125
+ it "should set the payload and the exploit of the payload to nil" do
126
+ @exploit.payload = @payload
127
+ @exploit.payload = nil
128
+
129
+ @payload.exploit.should be_nil
130
+ end
131
+
132
+ it "should specify the additional behaviors controlled by the payload" do
133
+ @payload.control :code_exec
134
+ @payload.control :command_exec
135
+ @exploit.control :code_exec
136
+
137
+ @exploit.payload = @payload
138
+
139
+ @exploit.behaviors.should == [:code_exec, :command_exec]
140
+ end
141
+
142
+ it "should build a raw payload" do
143
+ @exploit.payload = @payload
144
+ @exploit.build_payload!
145
+
146
+ @exploit.raw_payload.should == 'code.func'
147
+ end
148
+
149
+ it "should pass options to the payload when building the raw payload" do
150
+ @exploit.payload = @payload
151
+ @exploit.build_payload!(:custom => 'test')
152
+
153
+ @exploit.raw_payload.should == 'code.test'
154
+ end
155
+
156
+ it "should default raw_payload to an empty String, if payload is nil" do
157
+ @exploit.payload = nil
158
+ @exploit.build_payload!
159
+
160
+ @exploit.raw_payload.should == ''
161
+ end
162
+
163
+ it "should not reset raw_payload, if payload is nil" do
164
+ @exploit.payload = nil
165
+ @exploit.raw_payload = 'data'
166
+
167
+ @exploit.build_payload!
168
+ @exploit.raw_payload.should == 'data'
169
+ end
170
+
171
+ it "should have no payload encoders by default" do
172
+ @exploit.encoders.should be_empty
173
+ end
174
+
175
+ it "should accept blocks as payload encoders" do
176
+ @exploit.raw_payload = 'data'
177
+
178
+ @exploit.encode_payload do |payload|
179
+ payload.capitalize
180
+ end
181
+
182
+ @exploit.encode_payload!
183
+ @exploit.encoded_payload.should == 'Data'
184
+ end
185
+
186
+ it "should accept an object with an #encode method" do
187
+ @exploit.raw_payload = 'data'
188
+ @exploit.encode_payload(Payloads::Encoders::Encoder.new)
189
+
190
+ @exploit.encode_payload!
191
+ @exploit.encoded_payload.should == 'data'
192
+ end
193
+
194
+ it "should not accept objects without an #encode method" do
195
+ lambda {
196
+ @exploit.encode_payload(Object.new)
197
+ }.should raise_error(RuntimeError)
198
+ end
199
+
200
+ it "should accept either a payload encoder object or a block" do
201
+ lambda {
202
+ @exploit.encode_payload()
203
+ }.should raise_error(ArgumentError)
204
+ end
205
+
107
206
  it "should encode a String payload" do
108
- @exploit.payload = 'data'
207
+ @exploit.raw_payload = 'data'
109
208
 
110
209
  @exploit.encode_payload!
111
210
  @exploit.encoded_payload.should == 'data'
112
211
  end
113
212
 
114
213
  it "should encode a String using encoders" do
115
- @exploit.payload = 'data'
214
+ @exploit.raw_payload = 'data'
116
215
  @exploit.encoders << lambda { |payload| payload.upcase }
117
216
 
118
217
  @exploit.encode_payload!
@@ -120,7 +219,7 @@ describe Exploits::Exploit do
120
219
  end
121
220
 
122
221
  it "should ignore payload encoders which return nil" do
123
- @exploit.payload = 'data'
222
+ @exploit.raw_payload = 'data'
124
223
  @exploit.encoders << lambda { |payload| nil }
125
224
 
126
225
  @exploit.encode_payload!
@@ -133,8 +232,20 @@ describe Exploits::Exploit do
133
232
  @exploit.should be_built
134
233
  end
135
234
 
136
- it "should return the result of the builder" do
137
- @exploit.build!.should == 'result'
235
+ it "should pass the built exploit to a given block" do
236
+ @exploit.build! do |exploit|
237
+ exploit.should be_built
238
+ end
239
+ end
240
+
241
+ it "should respect the arity of blocks passed to build!" do
242
+ @exploit.build! do
243
+ @exploit.should be_built
244
+ end
245
+ end
246
+
247
+ it "should return the built exploit" do
248
+ @exploit.build!.should be_built
138
249
  end
139
250
 
140
251
  it "should require the exploit is built before being deployed" do
@@ -149,11 +260,54 @@ describe Exploits::Exploit do
149
260
  end
150
261
  end
151
262
 
263
+ it "should respect the arity of blocks passed to deploy!" do
264
+ @exploit.build!
265
+
266
+ @exploit.deploy! do
267
+ @exploit.should be_deployed
268
+ end
269
+ end
270
+
271
+ it "should deploy the payload after deploying the exploit" do
272
+ @exploit.payload = @payload
273
+ @payload.should_not be_deployed
274
+
275
+ @exploit.build!
276
+ @exploit.deploy! do |exploit|
277
+ exploit.payload.should be_deployed
278
+ end
279
+ end
280
+
281
+ it "should build and deploy the exploit when exploited" do
282
+ @exploit.exploit!
283
+
284
+ @exploit.should be_built
285
+ @exploit.should be_deployed
286
+ end
287
+
288
+ it "should not deploy during a dry-run of the exploit" do
289
+ @exploit.exploit!(:dry_run => true)
290
+
291
+ @exploit.should be_built
292
+ @exploit.should_not be_deployed
293
+ end
294
+
152
295
  it "should return the name and the version when calling to_s" do
153
- @exploit.to_s.should == 'test 0.2'
296
+ @exploit.to_s.should == 'simple 0.2'
154
297
  end
155
298
 
156
299
  it "should have a custom inspect method" do
157
- @exploit.inspect.should == '#<Ronin::Exploits::Exploit: test 0.2>'
300
+ @exploit.inspect.should == '#<Ronin::Exploits::Exploit: simple 0.2>'
301
+ end
302
+
303
+ it "should pass missing methods to the payload" do
304
+ @exploit.payload = @payload
305
+ @exploit.some_control.should == 'control data'
306
+ end
307
+
308
+ it "should not pass missing methods, if payload is nil" do
309
+ lambda {
310
+ @exploit.some_control
311
+ }.should raise_error(NoMethodError)
158
312
  end
159
313
  end