ronin-support 0.4.1 → 0.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/ChangeLog.md +75 -32
  2. data/Gemfile +17 -18
  3. data/README.md +9 -10
  4. data/Rakefile +10 -2
  5. data/gemspec.yml +1 -1
  6. data/lib/ronin/binary.rb +21 -0
  7. data/lib/ronin/binary/hexdump.rb +20 -0
  8. data/lib/ronin/binary/hexdump/parser.rb +411 -0
  9. data/lib/ronin/binary/struct.rb +579 -0
  10. data/lib/ronin/binary/template.rb +437 -0
  11. data/lib/ronin/extensions/ip_addr.rb +17 -13
  12. data/lib/ronin/extensions/regexp.rb +45 -0
  13. data/lib/ronin/extensions/string.rb +3 -3
  14. data/lib/ronin/formatting/extensions/binary.rb +1 -0
  15. data/lib/ronin/formatting/extensions/binary/array.rb +63 -0
  16. data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
  17. data/lib/ronin/formatting/extensions/binary/file.rb +39 -6
  18. data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
  19. data/lib/ronin/formatting/extensions/binary/integer.rb +56 -43
  20. data/lib/ronin/formatting/extensions/binary/string.rb +75 -187
  21. data/lib/ronin/formatting/extensions/text/string.rb +61 -0
  22. data/lib/ronin/fuzzing/extensions/string.rb +21 -8
  23. data/lib/ronin/fuzzing/fuzzing.rb +19 -17
  24. data/lib/ronin/network.rb +2 -1
  25. data/lib/ronin/network/dns.rb +57 -15
  26. data/lib/ronin/network/extensions.rb +0 -1
  27. data/lib/ronin/network/ftp.rb +145 -0
  28. data/lib/ronin/network/http/http.rb +13 -14
  29. data/lib/ronin/network/imap.rb +11 -10
  30. data/lib/ronin/network/mixins.rb +1 -0
  31. data/lib/ronin/network/mixins/ftp.rb +155 -0
  32. data/lib/ronin/network/mixins/ssl.rb +1 -1
  33. data/lib/ronin/network/mixins/tcp.rb +39 -6
  34. data/lib/ronin/network/mixins/udp.rb +121 -1
  35. data/lib/ronin/network/mixins/unix.rb +279 -0
  36. data/lib/ronin/network/pop3.rb +5 -5
  37. data/lib/ronin/network/proxy.rb +578 -0
  38. data/lib/ronin/network/smtp/email.rb +1 -1
  39. data/lib/ronin/network/smtp/smtp.rb +7 -8
  40. data/lib/ronin/network/ssl.rb +1 -6
  41. data/lib/ronin/network/tcp.rb +2 -305
  42. data/lib/ronin/network/tcp/proxy.rb +377 -0
  43. data/lib/ronin/network/tcp/tcp.rb +435 -0
  44. data/lib/ronin/network/telnet.rb +27 -23
  45. data/lib/ronin/network/udp.rb +2 -266
  46. data/lib/ronin/network/udp/proxy.rb +169 -0
  47. data/lib/ronin/network/udp/udp.rb +442 -0
  48. data/lib/ronin/network/unix.rb +287 -0
  49. data/lib/ronin/path.rb +2 -2
  50. data/lib/ronin/spec/ui/output.rb +1 -7
  51. data/lib/ronin/support.rb +1 -0
  52. data/lib/ronin/support/inflector.rb +3 -7
  53. data/lib/ronin/support/support.rb +2 -1
  54. data/lib/ronin/support/version.rb +1 -1
  55. data/lib/ronin/ui/output/helpers.rb +13 -15
  56. data/lib/ronin/ui/output/output.rb +2 -2
  57. data/lib/ronin/ui/output/terminal/color.rb +10 -4
  58. data/lib/ronin/wordlist.rb +92 -17
  59. data/ronin-support.gemspec +38 -109
  60. data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
  61. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
  62. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
  63. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
  64. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
  65. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
  66. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
  67. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
  68. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
  69. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
  70. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
  71. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
  72. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
  73. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
  74. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
  75. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
  76. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
  77. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
  78. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
  79. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
  80. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
  81. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
  82. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
  83. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
  84. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
  85. data/spec/binary/hexdump/parser_spec.rb +302 -0
  86. data/spec/binary/struct_spec.rb +496 -0
  87. data/spec/binary/template_spec.rb +400 -0
  88. data/spec/extensions/ip_addr_spec.rb +58 -32
  89. data/spec/extensions/regexp_spec.rb +60 -0
  90. data/spec/extensions/string_spec.rb +1 -1
  91. data/spec/formatting/binary/array_spec.rb +22 -0
  92. data/spec/formatting/binary/base64_spec.rb +50 -0
  93. data/spec/formatting/binary/float_spec.rb +30 -0
  94. data/spec/formatting/binary/integer_spec.rb +54 -40
  95. data/spec/formatting/binary/string_spec.rb +69 -182
  96. data/spec/formatting/text/string_spec.rb +30 -0
  97. data/spec/network/dns_spec.rb +64 -0
  98. data/spec/network/ftp_spec.rb +65 -0
  99. data/spec/network/proxy_spec.rb +121 -0
  100. data/spec/network/shared/unix_server.rb +31 -0
  101. data/spec/network/tcp/proxy_spec.rb +116 -0
  102. data/spec/network/{tcp_spec.rb → tcp/tcp_spec.rb} +24 -1
  103. data/spec/network/telnet_spec.rb +67 -0
  104. data/spec/network/{udp_spec.rb → udp/udp_spec.rb} +24 -1
  105. data/spec/network/unix_spec.rb +183 -0
  106. data/spec/wordlist_spec.rb +74 -13
  107. metadata +129 -85
  108. data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
@@ -0,0 +1,287 @@
1
+ #
2
+ # Copyright (c) 2006-2012 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin Support.
5
+ #
6
+ # Ronin Support is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Lesser General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin Support 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 Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'socket'
21
+ require 'timeout'
22
+
23
+ module Ronin
24
+ module Network
25
+ #
26
+ # Provides helper methods for communicating with UNIX sockets.
27
+ #
28
+ # @since 0.5.0
29
+ #
30
+ module UNIX
31
+ #
32
+ # Tests whether a UNIX socket is open.
33
+ #
34
+ # @param [String] path
35
+ # The path to the socket.
36
+ #
37
+ # @param [Integer] timeout (5)
38
+ # The maximum time to attempt connecting.
39
+ #
40
+ # @return [Boolean, nil]
41
+ # Specifies whether the UNIX socket is open.
42
+ # If the connection was not accepted, `nil` will be returned.
43
+ #
44
+ # @api public
45
+ #
46
+ # @since 0.5.0
47
+ #
48
+ def unix_open?(path,timeout=nil)
49
+ timeout ||= 5
50
+
51
+ begin
52
+ Timeout.timeout(timeout) { unix_session(path) }
53
+ return true
54
+ rescue Timeout::Error
55
+ return nil
56
+ rescue SocketError, SystemCallError
57
+ return false
58
+ end
59
+ end
60
+
61
+ #
62
+ # Connects to a UNIX socket.
63
+ #
64
+ # @param [String] path
65
+ # The path to the UNIX socket.
66
+ #
67
+ # @yield [socket]
68
+ # If a block is given, it will be passed an UNIX socket object.
69
+ #
70
+ # @yieldparam [UNIXSocket] socket
71
+ # The UNIX socket.
72
+ #
73
+ # @return [UNIXSocket]
74
+ # The UNIX socket.
75
+ #
76
+ # @example
77
+ # unix_connect('/tmp/haproxy.stats.socket')
78
+ #
79
+ # @see http://rubydoc.info/stdlib/socket/UNIXSocket
80
+ #
81
+ # @api public
82
+ #
83
+ def unix_connect(path)
84
+ socket = UNIXSocket.new(path)
85
+
86
+ yield socket if block_given?
87
+ return socket
88
+ end
89
+
90
+ #
91
+ # Creates a new UNIXSocket object, connected to the given path.
92
+ # The given data will then be written to the newly created UNIXSocket.
93
+ #
94
+ # @param [String] data
95
+ # The data to send to the socket.
96
+ #
97
+ # @param [String] path
98
+ # The path to the socket.
99
+ #
100
+ # @yield [socket]
101
+ # If a block is given, it will be passed the newly created socket.
102
+ #
103
+ # @yieldparam [UNIXSocket] socket
104
+ # The newly created UNIXSocket object.
105
+ #
106
+ # @return [UNIXSocket]
107
+ # The newly created UNIXSocket object.
108
+ #
109
+ # @api public
110
+ #
111
+ def unix_connect_and_send(data,path)
112
+ socket = unix_connect(path)
113
+ socket.write(data)
114
+
115
+ yield socket if block_given?
116
+ return socket
117
+ end
118
+
119
+ #
120
+ # Connects temporarily to a UNIX socket.
121
+ #
122
+ # @param [String] path
123
+ # The path to the UNIX socket.
124
+ #
125
+ # @yield [socket]
126
+ # If a block is given, it will be passed an UNIX socket object.
127
+ #
128
+ # @yieldparam [UNIXSocket] socket
129
+ # The UNIX socket.
130
+ #
131
+ # @example
132
+ # unix_session('/tmp/haproxy.stats.socket') do |socket|
133
+ # # ...
134
+ # end
135
+ #
136
+ # @api public
137
+ #
138
+ def unix_session(path)
139
+ socket = unix_connect(path)
140
+
141
+ yield socket if block_given?
142
+ socket.close
143
+ return nil
144
+ end
145
+
146
+ #
147
+ # Connects to a UNIX socket, sends the given data and then closes the
148
+ # socket.
149
+ #
150
+ # @param [String] data
151
+ # The data to send to the UNIX socket.
152
+ #
153
+ # @param [String] path
154
+ # The UNIX socket to connect to.
155
+ #
156
+ # @return [true]
157
+ # The data was successfully sent.
158
+ #
159
+ # @example
160
+ # buffer = "GET /" + ('A' * 4096) + "\n\r"
161
+ # unix_send(buffer,'/tmp/thin.socket')
162
+ # # => true
163
+ #
164
+ # @api public
165
+ #
166
+ def unix_send(data,path)
167
+ unix_session(path) do |socket|
168
+ socket.write(data)
169
+ end
170
+
171
+ return true
172
+ end
173
+
174
+ #
175
+ # Opens a UNIX socket.
176
+ #
177
+ # @param [String] path
178
+ # The path for the new UNIX socket.
179
+ #
180
+ # @yield [server]
181
+ # If a block is given, it will be passed an UNIX socket object.
182
+ #
183
+ # @yieldparam [UNIXServer] server
184
+ # The new UNIX socket.
185
+ #
186
+ # @return [UNIXServer]
187
+ # The new UNIX socket.
188
+ #
189
+ # @example
190
+ # unix_server('/tmp/test.socket')
191
+ #
192
+ # @see http://rubydoc.info/stdlib/socket/UNIXServer
193
+ #
194
+ # @api public
195
+ #
196
+ def unix_server(path)
197
+ socket = UNIXServer.new(path)
198
+
199
+ yield socket if block_given?
200
+ return socket
201
+ end
202
+
203
+ #
204
+ # Opens a UNIX socket temporarily.
205
+ #
206
+ # @param [String] path
207
+ # The path for the new UNIX socket.
208
+ #
209
+ # @yield [server]
210
+ # If a block is given, it will be passed an UNIX socket object.
211
+ #
212
+ # @yieldparam [UNIXServer] server
213
+ # The new UNIX socket.
214
+ #
215
+ # @example
216
+ # unix_server_session('/tmp/test.socket') do |server|
217
+ # # ...
218
+ # end
219
+ #
220
+ # @api public
221
+ #
222
+ def unix_server_session(path,&block)
223
+ socket = unix_server(path,&block)
224
+ socket.close
225
+ return nil
226
+ end
227
+
228
+ #
229
+ # Opens a UNIX socket, accepts connections in a loop.
230
+ #
231
+ # @param [String] path
232
+ # The path for the new UNIX socket.
233
+ #
234
+ # @yield [client]
235
+ # If a block is given, it will be passed each accepted connection.
236
+ #
237
+ # @yieldparam [UNIXSocket] client
238
+ # An accepted connection to UNIX socket.
239
+ #
240
+ # @example
241
+ # unix_server_loop('/tmp/test.socket') do |client|
242
+ # # ...
243
+ # end
244
+ #
245
+ # @api public
246
+ #
247
+ def unix_server_loop(path)
248
+ unix_server_session(path) do |server|
249
+ loop do
250
+ client = server.accept
251
+
252
+ yield client if block_given?
253
+ client.close
254
+ end
255
+ end
256
+ end
257
+
258
+ #
259
+ # Opens a UNIX socket, accepts a connection, then closes the socket.
260
+ #
261
+ # @param [String] path
262
+ # The path for the new UNIX socket.
263
+ #
264
+ # @yield [client]
265
+ # If a block is given, it will be passed the accepted connection.
266
+ #
267
+ # @yieldparam [UNIXSocket] client
268
+ # The accepted connection to UNIX socket.
269
+ #
270
+ # @example
271
+ # unix_single_server('/tmp/test.socket') do |client|
272
+ # # ...
273
+ # end
274
+ #
275
+ # @api public
276
+ #
277
+ def unix_accept(path)
278
+ unix_server_session(path) do |server|
279
+ client = server.accept
280
+
281
+ yield client if block_given?
282
+ client.close
283
+ end
284
+ end
285
+ end
286
+ end
287
+ end
data/lib/ronin/path.rb CHANGED
@@ -62,11 +62,11 @@ module Ronin
62
62
  # @raise [ArgumentError]
63
63
  # A negative number was given as the first argument.
64
64
  #
65
- # @example Generate a relative path that goes up 7 directories.
65
+ # @example Generate a relative path that goes up 7 directories:
66
66
  # Path.up(7)
67
67
  # # => #<Ronin::Path:../../../../../../..>
68
68
  #
69
- # @example Generate multiple relative paths, going up 1 to 3 directories.
69
+ # @example Generate multiple relative paths, going up 1 to 3 directories:
70
70
  # Path.up(1..3)
71
71
  # # => [#<Ronin::Path:..>, #<Ronin::Path:../..>,
72
72
  # #<Ronin::Path:../../..>]
@@ -19,10 +19,4 @@
19
19
 
20
20
  require 'ronin/ui/output'
21
21
 
22
- require 'rspec'
23
-
24
- RSpec.configure do |spec|
25
- spec.before(:suite) do
26
- Ronin::UI::Output.silent! unless ENV['DEBUG']
27
- end
28
- end
22
+ Ronin::UI::Output.silent! unless ENV['DEBUG']
data/lib/ronin/support.rb CHANGED
@@ -20,6 +20,7 @@
20
20
  require 'ronin/extensions'
21
21
  require 'ronin/formatting'
22
22
  require 'ronin/fuzzing'
23
+ require 'ronin/binary'
23
24
  require 'ronin/network'
24
25
  require 'ronin/path'
25
26
  require 'ronin/templates'
@@ -21,17 +21,13 @@ module Ronin
21
21
  module Support
22
22
  # The Inflectors supported by ronin-support
23
23
  INFLECTORS = {
24
- :datamapper => {
24
+ :data_mapper => {
25
25
  :path => 'dm-core',
26
26
  :const => 'DataMapper::Inflector'
27
27
  },
28
28
  :active_support => {
29
29
  :path => 'active_support/inflector',
30
30
  :const => 'ActiveSupport::Inflector'
31
- },
32
- :extlib => {
33
- :path => 'extlib/inflection',
34
- :const => 'Extlib::Inflection'
35
31
  }
36
32
  }
37
33
 
@@ -41,7 +37,7 @@ module Ronin
41
37
  #
42
38
  # @param [Symbol, String] name
43
39
  # The name of the Inflector library to load. May be either
44
- # `:datamapper`, `:active_support` or `:extlib`.
40
+ # `:datamapper` or `:active_support`.
45
41
  #
46
42
  # @return [true]
47
43
  # Specifies that the Inflector library was successfully loaded.
@@ -81,7 +77,7 @@ module Ronin
81
77
  return true
82
78
  end
83
79
 
84
- [:datamapper, :active_support, :extlib].each do |name|
80
+ [:data_mapper, :active_support].each do |name|
85
81
  begin
86
82
  Support.load_inflector!(name)
87
83
  break
@@ -29,12 +29,13 @@ module Ronin
29
29
  include Network::DNS
30
30
  include Network::TCP
31
31
  include Network::UDP
32
- include Network::SSL
32
+ include Network::UNIX
33
33
  include Network::SMTP
34
34
  include Network::ESMTP
35
35
  include Network::POP3
36
36
  include Network::IMAP
37
37
  include Network::Telnet
38
+ include Network::FTP
38
39
  include Network::HTTP
39
40
  end
40
41
  end
@@ -20,6 +20,6 @@
20
20
  module Ronin
21
21
  module Support
22
22
  # ronin-support version
23
- VERSION = '0.4.1'
23
+ VERSION = '0.5.0.rc1'
24
24
  end
25
25
  end
@@ -123,7 +123,7 @@ module Ronin
123
123
  # @example
124
124
  # print_info "Connecting ..."
125
125
  #
126
- # @example Print a formatted message.
126
+ # @example Print a formatted message:
127
127
  # print_info "Connected to %s", host
128
128
  #
129
129
  # @since 0.3.0
@@ -132,7 +132,7 @@ module Ronin
132
132
  #
133
133
  def print_info(*message)
134
134
  unless Output.silent?
135
- Output.handler.print_info(format_message(message))
135
+ Output.handler.print_info(Helpers.format(message))
136
136
  return true
137
137
  end
138
138
 
@@ -148,7 +148,7 @@ module Ronin
148
148
  # @return [Boolean]
149
149
  # Specifies whether the messages were successfully printed.
150
150
  #
151
- # @example Print a formatted message.
151
+ # @example Print a formatted message:
152
152
  # print_debug "vars: %p %p", vars[0], vars[1]
153
153
  #
154
154
  # @since 0.3.0
@@ -157,7 +157,7 @@ module Ronin
157
157
  #
158
158
  def print_debug(*message)
159
159
  if (Output.verbose? && !(Output.silent?))
160
- Output.handler.print_debug(format_message(message))
160
+ Output.handler.print_debug(Helpers.format(message))
161
161
  return true
162
162
  end
163
163
 
@@ -176,7 +176,7 @@ module Ronin
176
176
  # @example
177
177
  # print_warning "Detecting a restricted character in the buffer"
178
178
  #
179
- # @example Print a formatted message.
179
+ # @example Print a formatted message:
180
180
  # print_warning "Malformed input detected: %p", user_input
181
181
  #
182
182
  # @since 0.3.0
@@ -185,7 +185,7 @@ module Ronin
185
185
  #
186
186
  def print_warning(*message)
187
187
  unless Output.silent?
188
- Output.handler.print_warning(format_message(message))
188
+ Output.handler.print_warning(Helpers.format(message))
189
189
  return true
190
190
  end
191
191
 
@@ -204,7 +204,7 @@ module Ronin
204
204
  # @example
205
205
  # print_error "Could not connect!"
206
206
  #
207
- # @example Print a formatted message.
207
+ # @example Print a formatted message:
208
208
  # print_error "%p: %s", error.class, error.message
209
209
  #
210
210
  # @since 0.3.0
@@ -213,7 +213,7 @@ module Ronin
213
213
  #
214
214
  def print_error(*message)
215
215
  unless Output.silent?
216
- Output.handler.print_error(format_message(message))
216
+ Output.handler.print_error(Helpers.format(message))
217
217
  return true
218
218
  end
219
219
 
@@ -259,21 +259,19 @@ module Ronin
259
259
  #
260
260
  # Formats a message to be printed.
261
261
  #
262
- # @param [Array] message
262
+ # @param [Array] arguments
263
263
  # The message and additional Objects to format.
264
264
  #
265
265
  # @return [String]
266
266
  # The formatted message.
267
267
  #
268
- # @since 1.0.0
269
- #
270
268
  # @api private
271
269
  #
272
- def format_message(message)
273
- if message.length == 1
274
- message[0]
270
+ def Helpers.format(arguments)
271
+ unless arguments.length == 1
272
+ arguments.first % arguments[1..-1]
275
273
  else
276
- message[0] % message[1..-1]
274
+ arguments.first
277
275
  end
278
276
  end
279
277
  end