ronin 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +95 -0
  3. data/Manifest.txt +55 -25
  4. data/README.txt +64 -52
  5. data/Rakefile +21 -14
  6. data/bin/ronin +1 -1
  7. data/bin/ronin-add +1 -1
  8. data/bin/ronin-console +1 -1
  9. data/bin/ronin-help +1 -1
  10. data/bin/ronin-install +1 -1
  11. data/bin/ronin-list +1 -1
  12. data/bin/ronin-remove +1 -1
  13. data/bin/ronin-uninstall +1 -1
  14. data/bin/ronin-update +1 -1
  15. data/lib/ronin.rb +2 -4
  16. data/lib/ronin/arch.rb +66 -21
  17. data/lib/ronin/author.rb +27 -18
  18. data/lib/ronin/cacheable.rb +63 -23
  19. data/lib/ronin/code/emittable.rb +1 -4
  20. data/lib/ronin/code/reference.rb +2 -5
  21. data/lib/ronin/code/symbol_table.rb +1 -4
  22. data/lib/ronin/code/token.rb +1 -4
  23. data/lib/ronin/config.rb +31 -10
  24. data/lib/ronin/database.rb +1 -4
  25. data/lib/ronin/database/database.rb +42 -23
  26. data/lib/ronin/database/exceptions.rb +1 -4
  27. data/lib/ronin/database/exceptions/invalid_config.rb +1 -4
  28. data/lib/ronin/environment.rb +1 -5
  29. data/lib/ronin/extensions.rb +1 -5
  30. data/lib/ronin/extensions/array.rb +8 -6
  31. data/lib/ronin/extensions/file.rb +9 -4
  32. data/lib/ronin/extensions/ip_addr.rb +33 -13
  33. data/lib/ronin/extensions/kernel.rb +44 -9
  34. data/lib/ronin/extensions/meta.rb +1 -4
  35. data/lib/ronin/extensions/string.rb +8 -7
  36. data/lib/ronin/extensions/uri.rb +1 -4
  37. data/lib/ronin/extensions/uri/http.rb +1 -48
  38. data/lib/ronin/extensions/uri/query_params.rb +27 -8
  39. data/lib/ronin/formatting.rb +1 -4
  40. data/lib/ronin/formatting/binary.rb +1 -4
  41. data/lib/ronin/formatting/digest.rb +1 -4
  42. data/lib/ronin/formatting/extensions.rb +1 -4
  43. data/lib/ronin/formatting/extensions/binary.rb +1 -4
  44. data/lib/ronin/formatting/extensions/binary/file.rb +3 -28
  45. data/lib/ronin/formatting/extensions/binary/integer.rb +31 -12
  46. data/lib/ronin/formatting/extensions/binary/string.rb +59 -36
  47. data/lib/ronin/formatting/extensions/digest.rb +1 -4
  48. data/lib/ronin/formatting/extensions/digest/string.rb +31 -9
  49. data/lib/ronin/formatting/extensions/http.rb +1 -4
  50. data/lib/ronin/formatting/extensions/http/string.rb +16 -9
  51. data/lib/ronin/formatting/extensions/text.rb +1 -4
  52. data/lib/ronin/formatting/extensions/text/array.rb +17 -7
  53. data/lib/ronin/formatting/extensions/text/string.rb +70 -27
  54. data/lib/ronin/formatting/http.rb +1 -4
  55. data/lib/ronin/formatting/text.rb +1 -4
  56. data/lib/ronin/license.rb +72 -65
  57. data/lib/ronin/model.rb +1 -4
  58. data/lib/ronin/model/has_description.rb +37 -8
  59. data/lib/ronin/model/has_license.rb +12 -8
  60. data/lib/ronin/model/has_name.rb +10 -7
  61. data/lib/ronin/model/has_version.rb +14 -4
  62. data/lib/ronin/model/model.rb +71 -14
  63. data/lib/ronin/network.rb +1 -4
  64. data/lib/ronin/network/esmtp.rb +1 -4
  65. data/lib/ronin/network/extensions.rb +1 -4
  66. data/lib/ronin/network/extensions/esmtp.rb +1 -4
  67. data/lib/ronin/network/extensions/esmtp/net.rb +49 -21
  68. data/lib/ronin/network/extensions/http.rb +1 -4
  69. data/lib/ronin/network/extensions/http/net.rb +319 -531
  70. data/lib/ronin/network/extensions/imap.rb +1 -4
  71. data/lib/ronin/network/extensions/imap/net.rb +50 -23
  72. data/lib/ronin/network/extensions/pop3.rb +1 -4
  73. data/lib/ronin/network/extensions/pop3/net.rb +40 -17
  74. data/lib/ronin/network/extensions/smtp.rb +1 -4
  75. data/lib/ronin/network/extensions/smtp/net.rb +49 -21
  76. data/lib/ronin/network/extensions/tcp.rb +1 -4
  77. data/lib/ronin/network/extensions/tcp/net.rb +234 -31
  78. data/lib/ronin/network/extensions/telnet.rb +1 -4
  79. data/lib/ronin/network/extensions/telnet/net.rb +83 -51
  80. data/lib/ronin/network/extensions/udp.rb +1 -4
  81. data/lib/ronin/network/extensions/udp/net.rb +164 -27
  82. data/lib/ronin/{sessions.rb → network/helpers.rb} +10 -13
  83. data/lib/ronin/network/helpers/esmtp.rb +129 -0
  84. data/lib/ronin/{sessions/session.rb → network/helpers/helper.rb} +25 -17
  85. data/lib/ronin/network/helpers/http.rb +444 -0
  86. data/lib/ronin/network/helpers/imap.rb +115 -0
  87. data/lib/ronin/network/helpers/pop3.rb +110 -0
  88. data/lib/ronin/network/helpers/smtp.rb +123 -0
  89. data/lib/ronin/network/helpers/tcp.rb +309 -0
  90. data/lib/ronin/network/helpers/telnet.rb +158 -0
  91. data/lib/ronin/network/helpers/udp.rb +197 -0
  92. data/lib/ronin/network/http.rb +3 -156
  93. data/lib/ronin/network/http/exceptions.rb +1 -4
  94. data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -4
  95. data/lib/ronin/network/http/http.rb +214 -0
  96. data/lib/ronin/network/http/proxy.rb +308 -0
  97. data/lib/ronin/network/imap.rb +7 -6
  98. data/lib/ronin/network/pop3.rb +7 -6
  99. data/lib/ronin/network/smtp.rb +1 -4
  100. data/lib/ronin/network/smtp/email.rb +34 -18
  101. data/lib/ronin/network/smtp/smtp.rb +19 -7
  102. data/lib/ronin/network/tcp.rb +1 -4
  103. data/lib/ronin/network/telnet.rb +25 -12
  104. data/lib/ronin/network/udp.rb +1 -4
  105. data/lib/ronin/os.rb +43 -21
  106. data/lib/ronin/path.rb +29 -9
  107. data/lib/ronin/platform.rb +1 -4
  108. data/lib/ronin/platform/exceptions.rb +1 -4
  109. data/lib/ronin/platform/exceptions/extension_not_found.rb +1 -4
  110. data/lib/ronin/platform/exceptions/overlay_cached.rb +1 -4
  111. data/lib/ronin/platform/exceptions/overlay_not_found.rb +1 -4
  112. data/lib/ronin/platform/extension.rb +195 -52
  113. data/lib/ronin/platform/extension_cache.rb +60 -24
  114. data/lib/ronin/platform/maintainer.rb +15 -8
  115. data/lib/ronin/platform/object_cache.rb +29 -8
  116. data/lib/ronin/platform/overlay.rb +82 -26
  117. data/lib/ronin/platform/overlay_cache.rb +179 -56
  118. data/lib/ronin/platform/platform.rb +154 -58
  119. data/lib/ronin/platform/ronin.rb +38 -11
  120. data/lib/ronin/product.rb +17 -17
  121. data/lib/ronin/rpc.rb +1 -4
  122. data/lib/ronin/rpc/call.rb +1 -4
  123. data/lib/ronin/rpc/client.rb +1 -4
  124. data/lib/ronin/rpc/console.rb +1 -4
  125. data/lib/ronin/rpc/exceptions.rb +1 -4
  126. data/lib/ronin/rpc/exceptions/not_implemented.rb +1 -4
  127. data/lib/ronin/rpc/exceptions/response_missing.rb +1 -4
  128. data/lib/ronin/rpc/response.rb +1 -4
  129. data/lib/ronin/rpc/service.rb +1 -4
  130. data/lib/ronin/rpc/shell.rb +1 -4
  131. data/lib/ronin/scanners.rb +1 -4
  132. data/lib/ronin/scanners/exceptions.rb +1 -4
  133. data/lib/ronin/scanners/exceptions/unknown_category.rb +1 -4
  134. data/lib/ronin/scanners/scanner.rb +82 -26
  135. data/lib/ronin/static.rb +1 -4
  136. data/lib/ronin/static/finders.rb +1 -4
  137. data/lib/ronin/static/static.rb +16 -7
  138. data/lib/ronin/templates.rb +2 -4
  139. data/lib/ronin/templates/erb.rb +24 -10
  140. data/lib/ronin/templates/template.rb +130 -0
  141. data/lib/ronin/ui.rb +2 -6
  142. data/lib/ronin/ui/command_line.rb +1 -4
  143. data/lib/ronin/ui/command_line/command.rb +137 -68
  144. data/lib/ronin/ui/command_line/command_line.rb +52 -29
  145. data/lib/ronin/ui/command_line/commands/add.rb +39 -67
  146. data/lib/ronin/ui/command_line/commands/console.rb +23 -27
  147. data/lib/ronin/ui/command_line/commands/help.rb +10 -29
  148. data/lib/ronin/ui/command_line/commands/install.rb +31 -56
  149. data/lib/ronin/ui/command_line/commands/list.rb +34 -52
  150. data/lib/ronin/ui/command_line/commands/remove.rb +12 -32
  151. data/lib/ronin/ui/command_line/commands/uninstall.rb +11 -31
  152. data/lib/ronin/ui/command_line/commands/update.rb +15 -35
  153. data/lib/ronin/ui/command_line/exceptions.rb +1 -4
  154. data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -4
  155. data/lib/ronin/ui/console.rb +54 -23
  156. data/lib/ronin/ui/hexdump.rb +1 -4
  157. data/lib/ronin/ui/hexdump/extensions.rb +1 -4
  158. data/lib/ronin/ui/hexdump/extensions/file.rb +8 -6
  159. data/lib/ronin/ui/hexdump/extensions/kernel.rb +4 -5
  160. data/lib/ronin/ui/hexdump/hexdump.rb +8 -5
  161. data/lib/ronin/{sessions/exceptions.rb → ui/output.rb} +3 -5
  162. data/lib/ronin/ui/output/handler.rb +121 -0
  163. data/lib/ronin/ui/output/helpers.rb +110 -0
  164. data/lib/ronin/ui/output/output.rb +144 -0
  165. data/lib/ronin/ui/shell.rb +38 -12
  166. data/lib/ronin/version.rb +2 -5
  167. data/lib/ronin/{sessions/exceptions/variable_missing.rb → yard.rb} +2 -10
  168. data/lib/ronin/{ronin.rb → yard/handlers.rb} +5 -15
  169. data/lib/ronin/yard/handlers/ruby.rb +27 -0
  170. data/lib/ronin/yard/handlers/ruby/base.rb +27 -0
  171. data/lib/ronin/yard/handlers/ruby/belongs_to_handler.rb +45 -0
  172. data/lib/ronin/yard/handlers/ruby/eval_block_handler.rb +18 -0
  173. data/lib/ronin/yard/handlers/ruby/has_handler.rb +49 -0
  174. data/lib/ronin/yard/handlers/ruby/legacy.rb +26 -0
  175. data/lib/ronin/yard/handlers/ruby/legacy/belongs_to_handler.rb +41 -0
  176. data/lib/ronin/yard/handlers/ruby/legacy/eval_block_handler.rb +19 -0
  177. data/lib/ronin/yard/handlers/ruby/legacy/has_handler.rb +34 -0
  178. data/lib/ronin/yard/handlers/ruby/legacy/metaclass_eval_handler.rb +21 -0
  179. data/lib/ronin/yard/handlers/ruby/legacy/property_handler.rb +41 -0
  180. data/lib/ronin/yard/handlers/ruby/legacy/scanner_handler.rb +61 -0
  181. data/lib/ronin/yard/handlers/ruby/metaclass_eval_handler.rb +18 -0
  182. data/lib/ronin/yard/handlers/ruby/property_handler.rb +45 -0
  183. data/lib/ronin/yard/handlers/ruby/scanner_handler.rb +66 -0
  184. data/spec/author_spec.rb +3 -3
  185. data/spec/extensions/classes/some_class.rb +2 -0
  186. data/spec/extensions/kernel_spec.rb +17 -0
  187. data/spec/extensions/uri/http_spec.rb +0 -31
  188. data/spec/formatting/binary/integer_spec.rb +4 -0
  189. data/spec/formatting/text/string_spec.rb +96 -0
  190. data/spec/license_spec.rb +6 -6
  191. data/spec/model/classes/basic_model.rb +13 -0
  192. data/spec/model/classes/custom_model.rb +17 -0
  193. data/spec/model/classes/described_model.rb +10 -0
  194. data/spec/model/has_description_spec.rb +42 -0
  195. data/spec/model/has_license_spec.rb +18 -4
  196. data/spec/model/model_spec.rb +68 -0
  197. data/spec/network/helpers/classes/test_helper.rb +11 -0
  198. data/spec/network/helpers/classes/uses_test_helper.rb +10 -0
  199. data/spec/network/helpers/helper_spec.rb +25 -0
  200. data/spec/network/{http_spec.rb → http/http_spec.rb} +0 -0
  201. data/spec/network/http/proxy_spec.rb +116 -0
  202. data/spec/os_spec.rb +4 -4
  203. data/spec/platform/extension_cache_spec.rb +14 -0
  204. data/spec/platform/extension_spec.rb +11 -0
  205. data/spec/platform/platform_spec.rb +8 -0
  206. data/spec/product_spec.rb +9 -9
  207. data/spec/spec_helper.rb +1 -1
  208. data/spec/templates/classes/{uses_erb.rb → example_erb.rb} +1 -1
  209. data/spec/templates/classes/example_template.rb +21 -0
  210. data/spec/templates/erb_spec.rb +2 -2
  211. data/spec/templates/helpers/static.rb +5 -0
  212. data/spec/templates/helpers/static/templates/_relative.erb +1 -0
  213. data/spec/templates/helpers/static/templates/example.erb +1 -0
  214. data/spec/templates/template_spec.rb +41 -0
  215. data/spec/ui/command_line/classes/test_command.rb +23 -0
  216. data/spec/ui/command_line/command_spec.rb +31 -0
  217. data/spec/ui/output_spec.rb +29 -0
  218. data/static/ronin/platform/overlay.xsl +135 -114
  219. data/tasks/spec.rb +1 -0
  220. data/tasks/yard.rb +18 -0
  221. metadata +98 -59
  222. metadata.gz.sig +0 -0
  223. data/TODO.txt +0 -15
  224. data/lib/ronin/extensions/hash.rb +0 -62
  225. data/lib/ronin/sessions/esmtp.rb +0 -57
  226. data/lib/ronin/sessions/http.rb +0 -678
  227. data/lib/ronin/sessions/imap.rb +0 -54
  228. data/lib/ronin/sessions/pop3.rb +0 -52
  229. data/lib/ronin/sessions/smtp.rb +0 -57
  230. data/lib/ronin/sessions/tcp.rb +0 -100
  231. data/lib/ronin/sessions/telnet.rb +0 -55
  232. data/lib/ronin/sessions/udp.rb +0 -73
  233. data/lib/ronin/ui/command_line/options.rb +0 -136
  234. data/lib/ronin/ui/diagnostics.rb +0 -66
  235. data/lib/ronin/ui/verbose.rb +0 -58
  236. data/spec/extensions/hash_spec.rb +0 -38
  237. data/spec/sessions/classes/test_session.rb +0 -11
  238. data/spec/sessions/classes/uses_test_session.rb +0 -10
  239. data/spec/sessions/session_spec.rb +0 -25
  240. data/spec/ui/verbose_spec.rb +0 -17
@@ -0,0 +1,115 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/network/helpers/helper'
22
+ require 'ronin/network/imap'
23
+
24
+ module Ronin
25
+ module Network
26
+ module Helpers
27
+ module IMAP
28
+ include Helper
29
+
30
+ protected
31
+
32
+ #
33
+ # Creates a connection to the IMAP server. The +@host+, +@port+,
34
+ # +@imap_auth+, +@imap_user+ and +@imap_password+ instance
35
+ # variables will also be used to make the connection.
36
+ #
37
+ # @param [Hash] options
38
+ # Additional options.
39
+ #
40
+ # @option options [Integer] :port (IMAP.default_port)
41
+ # The port the IMAP server is running on.
42
+ #
43
+ # @option options [String] :certs
44
+ # The path to the file containing CA certs of the server.
45
+ #
46
+ # @option options [Symbol] :auth
47
+ # The type of authentication to perform when connecting to the
48
+ # server. May be either +:login+ or +:cram_md5+.
49
+ #
50
+ # @option options [String] :user
51
+ # The user to authenticate as when connecting to the server.
52
+ #
53
+ # @option options [String] :password
54
+ # The password to authenticate with when connecting to the
55
+ # server.
56
+ #
57
+ # @option options [Boolean]
58
+ # Indicates wether or not to use SSL when connecting to the
59
+ # server.
60
+ #
61
+ # @since 0.3.0
62
+ #
63
+ def imap_connect(options={},&block)
64
+ require_variable :host
65
+
66
+ options[:port] ||= @port
67
+ options[:auth] ||= @imap_auth
68
+ options[:user] ||= @imap_user
69
+ options[:password] ||= @imap_password
70
+
71
+ if @port
72
+ print_info "Connecting to #{@host}:#{@port} ..."
73
+ else
74
+ print_info "Connecting to #{@host} ..."
75
+ end
76
+
77
+ return ::Net.imap_connect(@host,options,&block)
78
+ end
79
+
80
+ #
81
+ # Starts a session with the IMAP server. The +@host+, +@port+,
82
+ # +@imap_auth+, +@imap_user+ and +@imap_password+ instance
83
+ # variables will also be used to make the connection.
84
+ #
85
+ # @yield [session]
86
+ # If a _block_ is given, it will be passed the newly created
87
+ # IMAP session. After the _block_ has returned, the session will
88
+ # be closed.
89
+ #
90
+ # @yieldparam [Net::IMAP] session
91
+ # The newly created IMAP session object.
92
+ #
93
+ # @see imap_connect
94
+ # @since 0.3.0
95
+ #
96
+ def imap_session(options={},&block)
97
+ imap_connect(options) do |sess|
98
+ block.call(sess) if block
99
+
100
+ print_info "Logging out ..."
101
+
102
+ sess.close
103
+ sess.logout
104
+
105
+ if @port
106
+ print_info "Disconnecting from #{@host}:#{@port}"
107
+ else
108
+ print_info "Disconnecting from #{@host}"
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,110 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/network/helpers/helper'
22
+ require 'ronin/network/pop3'
23
+
24
+ module Ronin
25
+ module Network
26
+ module Helpers
27
+ module POP3
28
+ include Helper
29
+
30
+ protected
31
+
32
+ #
33
+ # Creates a connection to the POP3 server. The +@host+, +@port+,
34
+ # +@pop3_user+ and +@pop3_password+ instance variables will also
35
+ # be used to connect to the server.
36
+ #
37
+ # @param [Hash] options
38
+ # Additional options.
39
+ #
40
+ # @option options [Integer] :port (Ronin::Network::POP3.default_port)
41
+ # The port the POP3 server is running on.
42
+ #
43
+ # @option options [String] :user
44
+ # The user to authenticate with when connecting to the POP3
45
+ # server.
46
+ #
47
+ # @option options [String] :password
48
+ # The password to authenticate with when connecting to the POP3
49
+ # server.
50
+ #
51
+ # @yield [session]
52
+ # If a _block_ is given, it will be passed the newly created
53
+ # POP3 session.
54
+ #
55
+ # @yieldparam [Net::POP3] session
56
+ # The newly created POP3 session.
57
+ #
58
+ # @return [Net::POP3]
59
+ # The newly created POP3 session.
60
+ #
61
+ # @since 0.3.0
62
+ #
63
+ def pop3_connect(options={},&block)
64
+ require_variable :host
65
+
66
+ options[:port] ||= @port
67
+ options[:user] ||= @pop3_user
68
+ options[:password] ||= @pop3_password
69
+
70
+ if @port
71
+ print_info "Connecting to #{@host}:#{@port} ..."
72
+ else
73
+ print_info "Connecting to #{@host} ..."
74
+ end
75
+
76
+ return ::Net.pop3_connect(@host,options,&block)
77
+ end
78
+
79
+ #
80
+ # Starts a session with the POP3 server. The +@host+, +@port+,
81
+ # +@pop3_user+ and +@pop3_password+ instance variables will
82
+ # also be used to connect to the server.
83
+ #
84
+ # @yield [session]
85
+ # If a _block_ is given, it will be passed the newly created
86
+ # POP3 session. After the _block_ has returned, the session
87
+ # will be closed.
88
+ #
89
+ # @yieldparam [Net::POP3] session
90
+ # The newly created POP3 session.
91
+ #
92
+ # @see pop3_connect
93
+ # @since 0.3.0
94
+ #
95
+ def pop3_session(options={},&block)
96
+ pop3_connect(options) do |sess|
97
+ block.call(sess) if block
98
+ sess.finish
99
+
100
+ if @port
101
+ print_info "Disconnecting to #{@host}:#{@port}"
102
+ else
103
+ print_info "Disconnecting to #{@host}"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,123 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/network/helpers/helper'
22
+ require 'ronin/network/smtp'
23
+
24
+ module Ronin
25
+ module Network
26
+ module Helpers
27
+ module SMTP
28
+ include Helper
29
+
30
+ protected
31
+
32
+ #
33
+ # @see Ronin::Network::SMTP.message
34
+ #
35
+ # @since 0.3.0
36
+ #
37
+ def smtp_message(options={},&block)
38
+ Network::SMTP.message(options,&block)
39
+ end
40
+
41
+ #
42
+ # Creates a connection to the SMTP server. The +@host+, +@port+,
43
+ # +@smtp_login+, +@smtp_user+ and +@smtp_password+ instance
44
+ # variables will also be used to connect to the server.
45
+ #
46
+ # @param [Hash] options
47
+ # Additional options.
48
+ #
49
+ # @option options [Integer] :port (Ronin::Network::SMTP.default_port)
50
+ # The port to connect to.
51
+ #
52
+ # @option options [String] :helo
53
+ # The HELO domain.
54
+ #
55
+ # @option options [Symbol] :auth
56
+ # The type of authentication to use. Can be either +:login+,
57
+ # +:plain+ or +:cram_md5+.
58
+ #
59
+ # @option options [String] :user
60
+ # The user-name to authenticate with.
61
+ #
62
+ # @option options [String] :password
63
+ # The password to authenticate with.
64
+ #
65
+ # @yield [session]
66
+ # If a block is given, it will be passed an SMTP session object.
67
+ #
68
+ # @yieldparam [Net::SMTP] session
69
+ # The SMTP session.
70
+ #
71
+ # @return [Net::SMTP]
72
+ # The SMTP session.
73
+ #
74
+ # @since 0.3.0
75
+ #
76
+ def smtp_connect(options={},&block)
77
+ require_variable :host
78
+
79
+ options[:port] ||= @port
80
+ options[:login] ||= @smtp_login
81
+ options[:user] ||= @smtp_user
82
+ options[:password] ||= @smtp_password
83
+
84
+ if @port
85
+ print_info "Connecting to #{@host}:#{@port} ..."
86
+ else
87
+ print_info "Connecting to #{@host} ..."
88
+ end
89
+
90
+ return ::Net.smtp_connect(@host,options,&block)
91
+ end
92
+
93
+ #
94
+ # Starts a session with the SMTP server. The +@host+, +@port+,
95
+ # +@smtp_login+, +@smtp_user+ and +@smtp_password+ instance
96
+ # variables will also be used to connect to the server.
97
+ #
98
+ # @yield [session]
99
+ # If a block is given, it will be passed an SMTP session object.
100
+ # After the block has returned, the session will be closed.
101
+ #
102
+ # @yieldparam [Net::SMTP] session
103
+ # The SMTP session.
104
+ #
105
+ # @see smtp_connect
106
+ # @since 0.3.0
107
+ #
108
+ def smtp_session(options={},&block)
109
+ smtp_connect(options) do |sess|
110
+ block.call(sess) if block
111
+ sess.close
112
+
113
+ if @port
114
+ print_info "Disconnecting to #{@host}:#{@port}"
115
+ else
116
+ print_info "Disconnecting to #{@host}"
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,309 @@
1
+ #
2
+ # Ronin - A Ruby platform for exploit development and security research.
3
+ #
4
+ # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+
21
+ require 'ronin/network/helpers/helper'
22
+ require 'ronin/network/tcp'
23
+
24
+ module Ronin
25
+ module Network
26
+ module Helpers
27
+ module TCP
28
+ include Helper
29
+
30
+ protected
31
+
32
+ #
33
+ # Opens a TCP connection to the host and port specified by the
34
+ # +@host+ and +@port+ instance variables. If the +@local_host+ and
35
+ # +@local_port+ instance variables are set, they will be used for
36
+ # the local host and port of the TCP connection.
37
+ #
38
+ # @yield [socket]
39
+ # If a block is given, it will be passed the newly created socket.
40
+ #
41
+ # @yieldparam [TCPsocket] socket
42
+ # The newly created TCPSocket object.
43
+ #
44
+ # @return [TCPSocket]
45
+ # The newly created TCPSocket object.
46
+ #
47
+ # @example
48
+ # tcp_connect # => TCPSocket
49
+ #
50
+ # @example
51
+ # tcp_connect do |sock|
52
+ # sock.write("GET /\n\n")
53
+ # puts sock.readlines
54
+ # sock.close
55
+ # end
56
+ #
57
+ # @since 0.3.0
58
+ #
59
+ def tcp_connect(&block)
60
+ require_variable :host
61
+ require_variable :port
62
+
63
+ print_info "Connecting to #{@host}:#{@port} ..."
64
+
65
+ return ::Net.tcp_connect(@host,@port,@local_host,@local_port,&block)
66
+ end
67
+
68
+ #
69
+ # Connects to the host and port specified by the +@host+ and +@port+
70
+ # instance variables, then sends the specified _data_.
71
+ #
72
+ # @param [String] data
73
+ # The data to send through the connection.
74
+ #
75
+ # @yield [socket]
76
+ # If a block is given, it will be passed the newly created socket.
77
+ #
78
+ # @yieldparam [TCPsocket] socket
79
+ # The newly created TCPSocket object.
80
+ #
81
+ # @return [TCPSocket]
82
+ # The newly created TCPSocket object.
83
+ #
84
+ # @since 0.3.0
85
+ #
86
+ def tcp_connect_and_send(data,&block)
87
+ require_variable :host
88
+ require_variable :port
89
+
90
+ print_info "Connecting to #{@host}:#{@port} ..."
91
+ print_debug "Sending data: #{data.inspect}"
92
+
93
+ return ::Net.tcp_connect_and_send(data,@host,@port,@local_host,@local_port,&block)
94
+ end
95
+
96
+ #
97
+ # Creates a TCP session to the host and port specified by the
98
+ # +@host+ and +@port+ instance variables.
99
+ #
100
+ # @yield [socket]
101
+ # If a block is given, it will be passed the newly created socket.
102
+ # After the block has returned, the socket will be closed.
103
+ #
104
+ # @yieldparam [TCPsocket] socket
105
+ # The newly created TCPSocket object.
106
+ #
107
+ # @since 0.3.0
108
+ #
109
+ def tcp_session(&block)
110
+ require_variable :host
111
+ require_variable :port
112
+
113
+ print_info "Connecting to #{@host}:#{@port} ..."
114
+
115
+ Net.tcp_session(@host,@port,@local_host,@local_port,&block)
116
+
117
+ print_info "Disconnected from #{@host}:#{@port}"
118
+ return nil
119
+ end
120
+
121
+ #
122
+ # Connects to the host and port specified by the +@host+ and +@port+
123
+ # instance variables, reads the banner then closes the connection.
124
+ #
125
+ # @yield [banner]
126
+ # If a block is given, it will be passed the grabbed banner.
127
+ #
128
+ # @yieldparam [String] banner
129
+ # The grabbed banner.
130
+ #
131
+ # @return [String]
132
+ # The grabbed banner.
133
+ #
134
+ # @example
135
+ # tcp_banner
136
+ # # => "220 mx.google.com ESMTP c20sm3096959rvf.1"
137
+ #
138
+ # @since 0.3.0
139
+ #
140
+ def tcp_banner(&block)
141
+ require_variable :host
142
+ require_variable :port
143
+
144
+ print_debug "Grabbing banner from #{@host}:#{@port}"
145
+
146
+ return ::Net.tcp_banner(@host,@port,@local_host,@local_port,&block)
147
+ end
148
+
149
+ #
150
+ # Connects to the host and port specified by the +@host+ and +@port+
151
+ # instance variables, sends the specified _data_ and then closes the
152
+ # connection.
153
+ #
154
+ # @return [true]
155
+ # The data was successfully sent.
156
+ #
157
+ # @example
158
+ # buffer = "GET /" + ('A' * 4096) + "\n\r"
159
+ # Net.tcp_send(buffer)
160
+ # # => true
161
+ #
162
+ # @since 0.3.0
163
+ #
164
+ def tcp_send(data)
165
+ require_variable :host
166
+ require_variable :port
167
+
168
+ print_info "Connecting to #{@host}:#{@port} ..."
169
+ print_debug "Sending data: #{data.inspect}"
170
+
171
+ ::Net.tcp_send(data,@host,@port,@local_host,@local_port)
172
+
173
+ print_info "Disconnected from #{@host}:#{@port}"
174
+ return true
175
+ end
176
+
177
+ #
178
+ # Creates a new TCPServer object listening on the +@server_host+
179
+ # and +@server_port+ instance variables.
180
+ #
181
+ # @yield [server]
182
+ # The given block will be passed the newly created server.
183
+ #
184
+ # @yieldparam [TCPServer] server
185
+ # The newly created server.
186
+ #
187
+ # @return [TCPServer]
188
+ # The newly created server.
189
+ #
190
+ # @example
191
+ # tcp_server
192
+ #
193
+ # @since 0.3.0
194
+ #
195
+ def tcp_server(&block)
196
+ require_variable :server_port
197
+
198
+ if @server_host
199
+ print_info "Listening on #{@server_host}:#{@server_port} ..."
200
+ else
201
+ print_info "Listening on #{@server_port} ..."
202
+ end
203
+
204
+ return ::Net.tcp_server(@server_port,@server_host,&block)
205
+ end
206
+
207
+ #
208
+ # Creates a new TCPServer object listening on the +@server_host+
209
+ # and +@server_port+ instance variables, passing it to the given
210
+ # _block_ then closing the server.
211
+ #
212
+ # @yield [server]
213
+ # The given block will be passed the newly created server.
214
+ # When the block has finished, the server will be closed.
215
+ #
216
+ # @yieldparam [TCPServer] server
217
+ # The newly created server.
218
+ #
219
+ # @return [nil]
220
+ #
221
+ # @example
222
+ # tcp_server_session do |server|
223
+ # client1 = server.accept
224
+ # client2 = server.accept
225
+ #
226
+ # client2.write(server.read_line)
227
+ #
228
+ # client1.close
229
+ # client2.close
230
+ # end
231
+ #
232
+ # @since 0.3.0
233
+ #
234
+ def tcp_server_session(&block)
235
+ require_variable :server_port
236
+
237
+ if @server_host
238
+ print_info "Listening on #{@server_host}:#{@server_port} ..."
239
+ else
240
+ print_info "Listening on #{@server_port} ..."
241
+ end
242
+
243
+ ::Net.tcp_server_session(&block)
244
+
245
+ if @server_host
246
+ print_info "Closed #{@server_host}:#{@server_port}"
247
+ else
248
+ print_info "Closed #{@server_port}"
249
+ end
250
+
251
+ return nil
252
+ end
253
+
254
+ #
255
+ # Creates a new TCPServer object listening on +@server_host+
256
+ # and +@server_port+ instance variables, accepts one client passing
257
+ # it to the given _block_, then closes both the newly connected
258
+ # client and the server.
259
+ #
260
+ # @yield [client]
261
+ # The given block will be passed the newly connected client.
262
+ # When the block has finished, the newly connected client and
263
+ # the server will be closed.
264
+ #
265
+ # @yieldparam [TCPSocket] client
266
+ # The newly connected client.
267
+ #
268
+ # @return [nil]
269
+ #
270
+ # @example
271
+ # tcp_single_server do |client|
272
+ # client.puts 'lol'
273
+ # end
274
+ #
275
+ # @since 0.3.0
276
+ #
277
+ def tcp_single_server(&block)
278
+ require_variable :server_port
279
+
280
+ if @server_host
281
+ print_info "Listening on #{@server_host}:#{@server_port} ..."
282
+ else
283
+ print_info "Listening on #{@server_port} ..."
284
+ end
285
+
286
+ ::Net.tcp_single_server do |client|
287
+ client_addr = client.peeraddr
288
+ client_host = (client_addr[2] || client_addr[3])
289
+ client_port = client_addr[1]
290
+
291
+ print_info "Client connected #{client_host}:#{client_port}"
292
+
293
+ block.call(client) if block
294
+
295
+ print_info "Disconnecting client #{client_host}:#{client_port}"
296
+ end
297
+
298
+ if @server_host
299
+ print_info "Closed #{@server_host}:#{@server_port}"
300
+ else
301
+ print_info "Closed #{@server_port}"
302
+ end
303
+
304
+ return nil
305
+ end
306
+ end
307
+ end
308
+ end
309
+ end