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,9 +17,9 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
24
23
  require 'ronin/exploits/exceptions/unknown_helper'
25
24
  require 'ronin/exploits/exceptions/target_unspecified'
26
25
  require 'ronin/exploits/exceptions/target_data_missing'
@@ -0,0 +1,27 @@
1
+ #
2
+ # Ronin Exploits - A Ruby library for Ronin that provides exploitation and
3
+ # payload crafting functionality.
4
+ #
5
+ # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 2 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #
21
+
22
+ module Ronin
23
+ module Exploits
24
+ class Exception < RuntimeError
25
+ end
26
+ end
27
+ 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,12 +17,13 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
23
+
24
24
  module Ronin
25
25
  module Exploits
26
- class ExploitNotBuilt < RuntimeError
26
+ class ExploitNotBuilt < Exception
27
27
  end
28
28
  end
29
29
  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,12 +17,13 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
23
+
24
24
  module Ronin
25
25
  module Exploits
26
- class PayloadSize < RuntimeError
26
+ class PayloadSize < Exception
27
27
  end
28
28
  end
29
29
  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,12 +17,13 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
23
+
24
24
  module Ronin
25
25
  module Exploits
26
- class RestrictedChar < RuntimeError
26
+ class RestrictedChar < Exception
27
27
  end
28
28
  end
29
29
  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,12 +17,13 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
23
+
24
24
  module Ronin
25
25
  module Exploits
26
- class TargetDataMissing < RuntimeError
26
+ class TargetDataMissing < Exception
27
27
  end
28
28
  end
29
29
  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,12 +17,13 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
23
+
24
24
  module Ronin
25
25
  module Exploits
26
- class TargetUnspecified < RuntimeError
26
+ class TargetUnspecified < Exception
27
27
  end
28
28
  end
29
29
  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,12 +17,13 @@
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
 
22
+ require 'ronin/exploits/exceptions/exception'
23
+
24
24
  module Ronin
25
25
  module Exploits
26
- class UnknownHelper < RuntimeError
26
+ class UnknownHelper < Exception
27
27
  end
28
28
  end
29
29
  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/exploits/exceptions/unknown_helper'
@@ -26,18 +24,20 @@ require 'ronin/exploits/exceptions/target_unspecified'
26
24
  require 'ronin/exploits/exceptions/target_data_missing'
27
25
  require 'ronin/exploits/exceptions/restricted_char'
28
26
  require 'ronin/exploits/exceptions/exploit_not_built'
29
- require 'ronin/exploits/license'
30
27
  require 'ronin/exploits/verifiers'
31
28
  require 'ronin/exploits/exploit_author'
32
29
  require 'ronin/exploits/target'
33
- require 'ronin/exploits/allow'
34
- require 'ronin/vuln/behavior'
30
+ require 'ronin/exploits/control'
31
+ require 'ronin/payloads/has_payload'
32
+ require 'ronin/payloads/payload'
33
+ require 'ronin/controls/behaviors'
35
34
  require 'ronin/cacheable'
36
35
  require 'ronin/model/has_name'
37
36
  require 'ronin/model/has_description'
38
37
  require 'ronin/model/has_version'
39
38
  require 'ronin/model/has_license'
40
- require 'ronin/ui/diagnostics'
39
+ require 'ronin/ui/output/helpers'
40
+ require 'ronin/extensions/kernel'
41
41
 
42
42
  require 'parameters'
43
43
  require 'chars/char_set'
@@ -52,9 +52,19 @@ module Ronin
52
52
  include Model::HasDescription
53
53
  include Model::HasVersion
54
54
  include Model::HasLicense
55
- include UI::Diagnostics
55
+ include Payloads::HasPayload
56
+ include Controls::Behaviors
57
+ include UI::Output::Helpers
56
58
  include Verifiers
57
59
 
60
+ #
61
+ # Creates a new Ronin::Exploits::Exploit object using the given
62
+ # _block_.
63
+ #
64
+ # ronin_exploit do
65
+ # ...
66
+ # end
67
+ #
58
68
  contextify :ronin_exploit
59
69
 
60
70
  # Primary key of the exploit
@@ -78,10 +88,10 @@ module Ronin
78
88
  ]
79
89
 
80
90
  # Author(s) of the exploit
81
- has n, :authors, :class_name => 'Ronin::Exploits::ExploitAuthor'
91
+ has n, :authors, :model => 'Ronin::Exploits::ExploitAuthor'
82
92
 
83
93
  # Behaviors that the exploit allows
84
- has n, :allows
94
+ has n, :controls, :model => 'Ronin::Exploits::Control'
85
95
 
86
96
  # Targets for the exploit
87
97
  has n, :targets
@@ -91,10 +101,7 @@ module Ronin
91
101
  validates_is_unique :version, :scope => [:name]
92
102
 
93
103
  # Exploit target
94
- attr_accessor :target
95
-
96
- # Exploit payload
97
- attr_accessor :payload
104
+ attr_writer :target
98
105
 
99
106
  # Characters to restrict
100
107
  attr_reader :restricted_chars
@@ -102,11 +109,22 @@ module Ronin
102
109
  # Encoders to run on the payload
103
110
  attr_reader :encoders
104
111
 
112
+ # The raw unencoded payload
113
+ attr_reader :raw_payload
114
+
105
115
  # The encoded payload
106
116
  attr_reader :encoded_payload
107
117
 
108
118
  #
109
- # Creates a new Exploit object with the given _attributes_.
119
+ # Creates a new Exploit object.
120
+ #
121
+ # @param [Hash] attributes
122
+ # Additional attributes used to initialize the exploit's model
123
+ # attributes and parameters.
124
+ #
125
+ # @yield []
126
+ # If a block is given, it will be evaluated in the newly created
127
+ # Exploit object.
110
128
  #
111
129
  def initialize(attributes={},&block)
112
130
  super(attributes)
@@ -124,10 +142,84 @@ module Ronin
124
142
  end
125
143
 
126
144
  #
127
- # Adds an ExploitAuthor with the given _attributes_ to the exploit.
128
- # If a _block_ is given, it will be passed to the newly created
129
- # ExploitAuthor object.
145
+ # Finds all exploits written by a specific author.
146
+ #
147
+ # @param [String] name
148
+ # The name of the author.
149
+ #
150
+ # @return [Array<Exploit>]
151
+ # The exploits written by the author.
152
+ #
153
+ def self.written_by(name)
154
+ all(self.authors.name.like => "%#{name}%")
155
+ end
156
+
157
+ #
158
+ # Finds all exploits written for a specific organization.
159
+ #
160
+ # @param [String] name
161
+ # The name of the organization.
162
+ #
163
+ # @return [Array<Exploit>]
164
+ # The exploits written for the organization.
165
+ #
166
+ def self.written_for(name)
167
+ all(self.authors.organization.like => "%#{name}%")
168
+ end
169
+
170
+ #
171
+ # Finds all exploits which target a given architecture.
172
+ #
173
+ # @param [String, Symbol] name
174
+ # The name of the architecture.
175
+ #
176
+ # @return [Array<Exploit>]
177
+ # The exploits targeting the architecture.
178
+ #
179
+ def self.targeting_arch(name)
180
+ all(self.targets.arch.name => name.to_s)
181
+ end
182
+
183
+ #
184
+ # Finds all exploits which target a given OS.
185
+ #
186
+ # @param [String, Symbol] name
187
+ # The name of the OS.
188
+ #
189
+ # @return [Array<Exploit>]
190
+ # The exploits targeting the OS.
191
+ #
192
+ def self.targeting_os(name)
193
+ all(self.targets.os.name => name.to_s)
194
+ end
195
+
196
+ #
197
+ # Finds all exploits which target a given product.
198
+ #
199
+ # @param [String, Symbol] name
200
+ # The name of the product.
201
+ #
202
+ # @return [Array<Exploit>]
203
+ # The exploits targeting the product.
204
+ #
205
+ def self.targeting_product(name)
206
+ all(self.targets.product.name => "%#{name}%")
207
+ end
208
+
209
+ #
210
+ # Adds a new author to the exploit.
211
+ #
212
+ # @param [Hash] attributes
213
+ # Additional attributes to create the ExploitAuthor object with.
130
214
  #
215
+ # @yield [author]
216
+ # If a block is given, it will be passed the newly created author
217
+ # object.
218
+ #
219
+ # @yieldparam [ExploitAuthor] author
220
+ # The author object tied to the exploit.
221
+ #
222
+ # @example
131
223
  # author :name => 'Anonymous',
132
224
  # :email => 'anon@example.com',
133
225
  # :organization => 'Anonymous LLC'
@@ -137,19 +229,18 @@ module Ronin
137
229
  end
138
230
 
139
231
  #
140
- # Adds a new Allow object granting the specified _behaviors_.
232
+ # Adds a new target to the exploit.
141
233
  #
142
- # allowing :code_exec, :auth_bypass
234
+ # @param [Hash] attributes
235
+ # Additional attributes to create the target with.
143
236
  #
144
- def allowing(*behaviors)
145
- behaviors.each do |behavior|
146
- self.allows << Allow.new(:behavior => Vuln::Behavior[behavior])
147
- end
148
- end
149
-
237
+ # @yield [target]
238
+ # If a block is given, it will be passed the newly created target.
150
239
  #
151
- # Adds a new Target with the given _attributes_ and _block_.
240
+ # @yieldparam [Target] target
241
+ # The newly created target.
152
242
  #
243
+ # @example
153
244
  # targeting do |target|
154
245
  # target.arch :i686
155
246
  # target.os :name => 'Linux'
@@ -160,8 +251,15 @@ module Ronin
160
251
  end
161
252
 
162
253
  #
163
- # Adds the given _chars_ to the restricted list of characters.
254
+ # Adds new characters to the list of restricted characters.
164
255
  #
256
+ # @param [Array<String>] chars
257
+ # The character to restrict.
258
+ #
259
+ # @return [Array<String>]
260
+ # The new list of restricted characters.
261
+ #
262
+ # @example
165
263
  # restrict 0x00, "\n"
166
264
  # # => #<Chars::CharSet: {"\0", "\n"}>
167
265
  #
@@ -170,189 +268,421 @@ module Ronin
170
268
  end
171
269
 
172
270
  #
173
- # Adds the specified _encoder_ to the list of encoders to use on the
271
+ # Adds a new encoder to the list of encoders to use for encoding the
174
272
  # payload.
175
273
  #
176
- def encode_with(encoder)
177
- @encoders << encoder
274
+ # @param [#encode] encoder
275
+ # The payload encoder object to use.
276
+ # Must provide an encode method.
277
+ #
278
+ # @yield [payload]
279
+ # If a block is given, and an encoder object is not, the block will
280
+ # be used to encode the payload.
281
+ #
282
+ # @yieldparam [String] payload
283
+ # The payload to be encoded.
284
+ #
285
+ # @return [Array]
286
+ # The new list of encoders to use to encode the payload.
287
+ #
288
+ # @raise [RuntimeError]
289
+ # The payload encoder object does not provide an encode method.
290
+ #
291
+ # @raise [ArgumentError]
292
+ # Either a payload encoder object or a block can be given.
293
+ #
294
+ # @example
295
+ # exploit.encode_payload(some_encoder)
296
+ #
297
+ # @example
298
+ # exploit.encode_payload do |payload|
299
+ # # ...
300
+ # end
301
+ #
302
+ def encode_payload(encoder=nil,&block)
303
+ if encoder
304
+ unless encoder.respond_to?(:encode)
305
+ raise(RuntimeError,"The payload encoder must provide an encode method",caller)
306
+ end
307
+
308
+ @encoders << encoder
309
+ elsif (encoder.nil? && block)
310
+ @encoders << block
311
+ else
312
+ raise(ArgumentError,"either a payload encoder or a block can be given",caller)
313
+ end
314
+ end
315
+
316
+ #
317
+ # Lists the behaviors controlled by the exploit and the payload, if
318
+ # one is being used.
319
+ #
320
+ # @return [Array<Symbol>]
321
+ # The combined behaviors controlled by the exploit.
322
+ #
323
+ def behaviors
324
+ total_behaviors = super
325
+
326
+ if @payload
327
+ total_behaviors = (total_behaviors + @payload.behaviors).uniq
328
+ end
329
+
330
+ return total_behaviors
178
331
  end
179
332
 
180
333
  #
181
- # Returns the Array of targeted architectures.
334
+ # @return [Array<Arch>]
335
+ # The targeted architectures.
182
336
  #
183
337
  def targeted_archs
184
338
  self.targets.map { |target| target.arch }.compact
185
339
  end
186
340
 
187
341
  #
188
- # Returns the Array of targeted OSes.
342
+ # @return [Array<OS>]
343
+ # The targeted OSes.
189
344
  #
190
345
  def targeted_oses
191
346
  self.targets.map { |target| target.os }.compact
192
347
  end
193
348
 
194
349
  #
195
- # Returns the Array of targeted Products.
350
+ # @return [Array<Product>]
351
+ # The targeted Products.
196
352
  #
197
353
  def targeted_products
198
354
  self.targets.map { |target| target.product }.compact
199
355
  end
200
356
 
201
357
  #
202
- # Explicitly selects the first target that matches the specified
203
- # _block_.
358
+ # Selects a target to use in exploitation.
204
359
  #
205
- # select_target { |target| target.arch == Arch.i686 }
360
+ # @param [Integer, Hash] index_or_query
361
+ # The index within #targets or a query to select the target.
206
362
  #
207
- def select_target(&block)
208
- @target = self.targets.first(&block)
363
+ # @yield [target]
364
+ # If a block is given, it will be used to select the desired
365
+ # target from #targets.
366
+ #
367
+ # @yieldparam [Target] target
368
+ # The potential target to review.
369
+ #
370
+ # @example
371
+ # use_target!(2)
372
+ #
373
+ # @example
374
+ # use_target!(Target.arch.name => 'i686')
375
+ #
376
+ # @example
377
+ # use_target! { |target| target.arch == Arch.i686 }
378
+ #
379
+ # @since 0.3.0
380
+ #
381
+ def use_target!(index_or_query=0,&block)
382
+ @target = if block
383
+ self.targets.find(&block)
384
+ elsif index_or_query.kind_of?(Hash)
385
+ self.targets.first(index_or_query)
386
+ elsif index_or_query.kind_of?(Integer)
387
+ self.targets[index_or_query]
388
+ end
209
389
  end
210
390
 
211
391
  #
212
- # Returns the current target.
392
+ # @return [Target]
393
+ # The current target to use in exploitation.
213
394
  #
214
395
  def target
215
396
  @target ||= self.targets.first
216
397
  end
217
398
 
218
399
  #
219
- # Returns the currently targeted architecture.
400
+ # @return [Arch]
401
+ # The current targeted architecture.
220
402
  #
221
403
  def arch
222
404
  target.arch if target
223
405
  end
224
406
 
225
407
  #
226
- # Returns the currently targeted OS.
408
+ # @return [OS]
409
+ # The current targeted OS.
227
410
  #
228
411
  def os
229
412
  target.os if target
230
413
  end
231
414
 
232
415
  #
233
- # Returns the currently targeted Product.
416
+ # @return [Product]
417
+ # The current targeted product.
234
418
  #
235
419
  def product
236
420
  target.product if target
237
421
  end
238
422
 
239
423
  #
240
- # Returns the behaviors allowed by the exploit.
424
+ # Associates a payload with the exploit, and the exploit with the
425
+ # payload.
241
426
  #
242
- def behaviors
243
- self.allows.map { |allow| allow.behavior }
427
+ # @param [Payload] new_payload
428
+ # The new payload to associate with the exploit.
429
+ #
430
+ # @return [Payload]
431
+ # The new payload.
432
+ #
433
+ # @since 0.3.0
434
+ #
435
+ def payload=(new_payload)
436
+ if (@payload && new_payload.nil?)
437
+ @payload.exploit = nil
438
+ end
439
+
440
+ super(new_payload)
441
+
442
+ if @payload
443
+ print_info "Using payload: #{new_payload}"
444
+
445
+ @payload.exploit = self
446
+ end
447
+
448
+ return @payload
244
449
  end
245
450
 
246
451
  #
247
- # Encodes the current payload, returning the encoded payload in
248
- # String form.
452
+ # Sets the raw payload to use with the exploit.
249
453
  #
250
- def encode_payload!
251
- @encoded_payload = ''
454
+ # @param [String, #to_s] new_raw_payload
455
+ # The new raw payload to use with the exploit.
456
+ #
457
+ # @return [String]
458
+ # The new raw payload of the exploit.
459
+ #
460
+ def raw_payload=(new_raw_payload)
461
+ new_raw_payload = new_raw_payload.to_s
462
+
463
+ print_debug "Using raw payload: #{new_raw_payload.dump}"
252
464
 
465
+ @raw_payload = new_raw_payload
466
+ end
467
+
468
+ #
469
+ # Builds the current payload, saving the result to the +@raw_payload+
470
+ # instance variable.
471
+ #
472
+ # @param [Hash] options
473
+ # Additional options to build the paylod with.
474
+ #
475
+ # @return [String]
476
+ # The built payload.
477
+ #
478
+ # @see Payload#build!
479
+ # @since 0.3.0
480
+ #
481
+ def build_payload!(options={})
253
482
  if @payload
254
- @encoded_payload = @payload.to_s
483
+ @raw_payload = ''
255
484
 
256
- @encoders.each do |encoder|
257
- if (new_payload = encoder.call(@encoded_payload))
258
- @encoded_payload = new_payload
259
- end
260
- end
485
+ @payload.build!(options)
486
+ @raw_payload = @payload.raw_payload
487
+ else
488
+ @raw_payload ||= ''
489
+ end
490
+
491
+ return @raw_payload
492
+ end
493
+
494
+ #
495
+ # Encodes the current payload and saves the result in the
496
+ # +@encoded_payload+ instance variable.
497
+ #
498
+ # @return [String]
499
+ # The encoded payload.
500
+ #
501
+ def encode_payload!
502
+ @encoded_payload = @raw_payload.to_s
503
+
504
+ @encoders.each do |encoder|
505
+ print_debug "Encoding payload: #{@encoded_payload.dump}"
506
+
507
+ new_payload = if encoder.respond_to?(:encode)
508
+ encoder.encode(@encoded_payload)
509
+ elsif encoder.respond_to?(:call)
510
+ encoder.call(@encoded_payload)
511
+ end
512
+
513
+ @encoded_payload = (new_payload || @encoded_payload).to_s
261
514
  end
262
515
 
263
516
  return @encoded_payload
264
517
  end
265
518
 
266
519
  #
267
- # Returns +true+ if the exploit is built, returns +false+ otherwise.
520
+ # @return [Boolean]
521
+ # Specifies whether the exploit is built.
268
522
  #
269
523
  def built?
270
524
  @built == true
271
525
  end
272
526
 
273
527
  #
274
- # Builds the exploit with the given _options_ and checks for
275
- # restricted characters or patterns. If any restricted characters or
276
- # patterns are found in the built exploit, a RestrictedText exception
277
- # will be raised.
528
+ # Builds the exploit and checks for restricted characters or patterns.
278
529
  #
279
- def build!(options={})
280
- if options[:payload]
281
- @payload = options.delete(:payload)
282
- end
283
-
530
+ # @param [Hash] options
531
+ # Additional options to also use as parameters.
532
+ #
533
+ def build!(options={},&block)
284
534
  self.params = options
285
535
 
536
+ print_debug "Exploit parameters: #{self.params.inspect}"
537
+
286
538
  @built = false
287
539
 
540
+ build_payload!(options)
288
541
  encode_payload!
289
- result = build
542
+
543
+ print_info "Building exploit ..."
544
+
545
+ build
546
+
547
+ print_info "Exploit built!"
290
548
 
291
549
  @built = true
292
- return result
550
+
551
+ if block
552
+ if block.arity == 1
553
+ block.call(self)
554
+ else
555
+ block.call()
556
+ end
557
+ end
558
+
559
+ return self
293
560
  end
294
561
 
295
562
  #
296
- # Verifies the exploit is properly configured, built and ready to be
297
- # deployed. An exception should be raised if the exploit is not ready
298
- # to be deployed, returns +true+ otherwise.
563
+ # Verifies the exploit is built, properly configured, built and
564
+ # ready deployment.
565
+ #
566
+ # @return [true]
567
+ # The exploit is built and ready for deployment.
568
+ #
569
+ # @raise [ExploitNotBuilt]
570
+ # The exploit has not been built, and cannot be deployed.
299
571
  #
300
572
  def verify!
301
573
  unless built?
302
574
  raise(ExploitNotBuilt,"cannot deploy an unbuilt exploit",caller)
303
575
  end
304
576
 
577
+ print_info "Verifying exploit ..."
578
+
305
579
  verify
580
+
581
+ print_info "Exploit verified!"
306
582
  return true
307
583
  end
308
584
 
309
585
  #
310
- # Returns +true+ if the exploit has previously been deployed, returns
311
- # +false+ otherwise.
586
+ # @return [Boolean]
587
+ # Specifies whether the exploit has previously been deployed.
312
588
  #
313
589
  def deployed?
314
590
  @deployed == true
315
591
  end
316
592
 
317
593
  #
318
- # Verifies then deploys the exploit with the given _block_. If a
319
- # _block_ is given, it will be passed the deployed exploit. If the
320
- # exploit has not been previously built, an ExploitNotBuilt exception
321
- # will be raised.
594
+ # Verifies then deploys the exploit. If a payload has been set,
595
+ # the payload will also be deployed.
596
+ #
597
+ # @yield [exploit]
598
+ # If a block is given, it will be passed the deployed exploit.
599
+ #
600
+ # @yieldparam [Exploit] exploit
601
+ # The deployed exploit.
602
+ #
603
+ # @return [Exploit]
604
+ # The deployed exploit.
605
+ #
606
+ # @raise [ExploitNotBuilt]
607
+ # The exploit has not been built, and cannot be deployed.
322
608
  #
323
609
  def deploy!(&block)
324
610
  verify!
325
611
 
612
+ print_info "Deploying exploit ..."
326
613
  @deployed = false
327
614
 
328
615
  deploy()
329
616
 
617
+ print_info "Exploit deployed!"
330
618
  @deployed = true
331
619
 
332
- block.call(self) if block
620
+ @payload.deploy!() if @payload
621
+
622
+ if block
623
+ if block.arity == 1
624
+ block.call(self)
625
+ else
626
+ block.call()
627
+ end
628
+ end
629
+
333
630
  return self
334
631
  end
335
632
 
336
633
  #
337
- # Builds the exploit with the given _options_, then deploys the
338
- # exploit with the given _block_.
634
+ # Builds, verified and then deploys the exploit.
635
+ #
636
+ # @param [Hash] options
637
+ # Additional options to build the exploit with.
638
+ #
639
+ # @option options [Boolean] :dry_run (false)
640
+ # Specifies whether to do a dry-run of the exploit, where the
641
+ # exploit will be built, verified but *not* deployed.
642
+ #
643
+ # @yieldparam [Exploit] exploit
644
+ # The deployed exploit.
645
+ #
646
+ # @return [Exploit]
647
+ # The deployed exploit.
648
+ #
649
+ # @return [Exploit]
650
+ # The deployed exploit.
339
651
  #
340
- def call(options={},&block)
652
+ # @since 0.3.0
653
+ #
654
+ def exploit!(options={},&block)
341
655
  build!(options)
342
656
 
343
- return deploy!(&block)
657
+ unless options[:dry_run]
658
+ deploy!(&block)
659
+ end
660
+
661
+ return self
344
662
  end
345
663
 
346
664
  #
347
- # Returns the name and version of the exploit.
665
+ # Converts the exploit to a String.
666
+ #
667
+ # @return [String]
668
+ # The name and version of the exploit.
348
669
  #
349
670
  def to_s
350
- "#{self.name} #{self.version}"
671
+ if (self.name && self.version)
672
+ "#{self.name} #{self.version}"
673
+ elsif self.name
674
+ self.name
675
+ elsif self.version
676
+ self.version
677
+ end
351
678
  end
352
679
 
353
680
  #
354
681
  # Inspects the contents of the exploit.
355
682
  #
683
+ # @return [String]
684
+ # The inspected exploit.
685
+ #
356
686
  def inspect
357
687
  str = "#{self.class}: #{self}"
358
688
  str << " #{self.params.inspect}" unless self.params.empty?
@@ -364,11 +694,20 @@ module Ronin
364
694
 
365
695
  #
366
696
  # Extends the exploit with the helper module defined in
367
- # Ronin::Exploits::Helpers that has the similar specified
368
- # _name_. If no module can be found within
369
- # Ronin::Exploits::Helpers with the similar _name_, an
370
- # UnknownHelper exception will be raised.
697
+ # Ronin::Exploits::Helpers that has the similar name.
698
+ #
699
+ # @param [Symbol, String] name
700
+ # The snake-case name of the exploit helper to load and extend the
701
+ # exploit with.
702
+ #
703
+ # @return [true]
704
+ # The exploit helper was successfully loaded.
705
+ #
706
+ # @raise [UnknownHelper]
707
+ # No valid helper module could be found or loaded with the similar
708
+ # name.
371
709
  #
710
+ # @example
372
711
  # helper :buffer_overflow
373
712
  #
374
713
  def helper(name)
@@ -376,7 +715,7 @@ module Ronin
376
715
  module_name = name.to_const_string
377
716
 
378
717
  begin
379
- require File.join('ronin','exploits','helpers',name)
718
+ require_within File.join('ronin','exploits','helpers'), name
380
719
  rescue Gem::LoadError => e
381
720
  raise(e)
382
721
  rescue ::LoadError
@@ -398,8 +737,13 @@ module Ronin
398
737
  end
399
738
 
400
739
  #
401
- # Returns +true+ if the specified _text_ contains any restricted
402
- # characters, returns +false+ otherwise.
740
+ # Reviews the text for restricted characters.
741
+ #
742
+ # @param [String] text
743
+ # The text to check for restricted characters within.
744
+ #
745
+ # @return [Boolean]
746
+ # Specifies whether the text contains any restricted characters.
403
747
  #
404
748
  def is_restricted?(text)
405
749
  text.each_byte do |b|
@@ -422,13 +766,26 @@ module Ronin
422
766
  end
423
767
 
424
768
  #
425
- # Default exploit deploy method, passes the exploit object to the
426
- # given _block_ by default.
769
+ # Default exploit deploy method.
427
770
  #
428
771
  def deploy(&block)
429
772
  block.call(self) if block
430
773
  end
431
774
 
775
+ #
776
+ # Relays method calls to the payload, if the payload is a kind of
777
+ # Ronin::Payloads::Payload.
778
+ #
779
+ # @since 0.3.0
780
+ #
781
+ def method_missing(name,*arguments,&block)
782
+ if @payload.kind_of?(Ronin::Payloads::Payload)
783
+ return @payload.send(name,*arguments,&block)
784
+ end
785
+
786
+ super(name,*arguments,&block)
787
+ end
788
+
432
789
  end
433
790
  end
434
791
  end