ronin-support 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +13 -1
- data/README.md +5 -3
- data/lib/ronin/binary/hexdump/parser.rb +10 -18
- data/lib/ronin/binary/struct.rb +18 -32
- data/lib/ronin/binary/template.rb +29 -19
- data/lib/ronin/extensions/ip_addr.rb +5 -10
- data/lib/ronin/extensions/resolv.rb +2 -4
- data/lib/ronin/formatting/extensions/binary.rb +1 -0
- data/lib/ronin/formatting/extensions/binary/array.rb +5 -7
- data/lib/ronin/formatting/extensions/binary/float.rb +4 -4
- data/lib/ronin/formatting/extensions/binary/integer.rb +14 -11
- data/lib/ronin/formatting/extensions/binary/string.rb +14 -25
- data/lib/ronin/formatting/extensions/html/integer.rb +4 -8
- data/lib/ronin/formatting/extensions/html/string.rb +24 -32
- data/lib/ronin/formatting/extensions/sql/string.rb +9 -13
- data/lib/ronin/formatting/extensions/text/array.rb +8 -6
- data/lib/ronin/formatting/extensions/text/string.rb +4 -8
- data/lib/ronin/fuzzing/fuzzer.rb +8 -16
- data/lib/ronin/network/dns.rb +2 -4
- data/lib/ronin/network/ftp.rb +5 -1
- data/lib/ronin/network/ssl.rb +9 -10
- data/lib/ronin/network/tcp/tcp.rb +8 -0
- data/lib/ronin/network/udp/proxy.rb +2 -2
- data/lib/ronin/network/udp/udp.rb +8 -0
- data/lib/ronin/network/unix.rb +4 -5
- data/lib/ronin/path.rb +2 -2
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/ui/output/helpers.rb +2 -4
- data/lib/ronin/ui/shell.rb +3 -6
- data/spec/binary/template_spec.rb +14 -0
- data/spec/formatting/binary/array_spec.rb +8 -4
- data/spec/formatting/binary/float_spec.rb +8 -4
- data/spec/formatting/binary/integer_spec.rb +16 -4
- data/spec/formatting/binary/string_spec.rb +8 -4
- data/spec/network/ftp_spec.rb +16 -0
- data/spec/network/network_spec.rb +1 -1
- data/spec/network/ssl_spec.rb +50 -0
- metadata +359 -399
data/ChangeLog.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
+
### 0.5.1 / 2012-06-29
|
2
|
+
|
3
|
+
* Added {Ronin::Binary::Template#inspect}.
|
4
|
+
* Added the `:passive` option to {Ronin::Network::FTP#ftp_connect}.
|
5
|
+
* Forgot to require `ronin/formatting/extensions/binary/array`.
|
6
|
+
* Fixed a bug where {Array#pack} would not accept tuples (ex: `[:uint8, 2]`).
|
7
|
+
* Fixed a bug in {String#sql_decode} where `"\\'\\'"` would incorrectly be
|
8
|
+
converted to `'"'`.
|
9
|
+
* Ensure that {Integer#pack} only accepts one argument.
|
10
|
+
* Have {String#hex_unescape} to decode every two characters.
|
11
|
+
* Enable passive-mode by default in {Ronin::Network::FTP#ftp_connect}.
|
12
|
+
|
1
13
|
### 0.5.0 / 2012-06-16
|
2
14
|
|
15
|
+
* Require uri-query_params ~> 0.6.
|
3
16
|
* Added {Float#pack}.
|
4
17
|
* Added {Regexp::WORD}.
|
5
18
|
* Added {Regexp::PHONE_NUMBER}.
|
@@ -51,7 +64,6 @@
|
|
51
64
|
* {Ronin::Fuzzing.[]} now raises a `NoMethodError` for unknown fuzzing methods.
|
52
65
|
* Use `module_function` in {Ronin::Fuzzing}, so the generator methods can be
|
53
66
|
included into other Classes/Modules.
|
54
|
-
* Require uri-query_params ~> 0.6.
|
55
67
|
* Use `$stdout` instead of calling `Kernel.puts` or `STDOUT`.
|
56
68
|
Prevents infinite recursion if another library overrides `Kernel.puts`.
|
57
69
|
* Allow {Ronin::Network::DNS} methods to yield resolved addresses.
|
data/README.md
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
* [Source](https://github.com/ronin-ruby/ronin-support)
|
4
4
|
* [Issues](https://github.com/ronin-ruby/ronin-support/issues)
|
5
5
|
* [Documentation](http://ronin-ruby.github.com/docs/ronin-support/frames)
|
6
|
-
* [Mailing List](
|
7
|
-
* [irc.freenode.net #ronin](http://
|
6
|
+
* [Mailing List](https://groups.google.com/group/ronin-ruby)
|
7
|
+
* [irc.freenode.net #ronin](http://ronin-ruby.github.com/irc/)
|
8
8
|
|
9
9
|
## Description
|
10
10
|
|
@@ -21,17 +21,19 @@ or payloads over many common Source-Code-Management (SCM) systems.
|
|
21
21
|
* Formatting data:
|
22
22
|
* Binary
|
23
23
|
* Text
|
24
|
-
* HTTP
|
25
24
|
* URIs
|
25
|
+
* HTTP
|
26
26
|
* HTML
|
27
27
|
* JavaScript
|
28
28
|
* SQL
|
29
29
|
* Fuzzing
|
30
30
|
* Networking:
|
31
31
|
* DNS
|
32
|
+
* UNIX
|
32
33
|
* TCP
|
33
34
|
* UDP
|
34
35
|
* SSL
|
36
|
+
* FTP
|
35
37
|
* SMTP / ESMTP
|
36
38
|
* POP3
|
37
39
|
* Imap
|
@@ -137,10 +137,8 @@ module Ronin
|
|
137
137
|
@encoding = options[:encoding]
|
138
138
|
|
139
139
|
@type = case @encoding
|
140
|
-
when :floats, :doubles
|
141
|
-
|
142
|
-
else
|
143
|
-
:integer
|
140
|
+
when :floats, :doubles then :float
|
141
|
+
else :integer
|
144
142
|
end
|
145
143
|
@endian = options.fetch(:endian,:little)
|
146
144
|
|
@@ -164,12 +162,10 @@ module Ronin
|
|
164
162
|
@word_size = WORD_SIZES.fetch(options[:encoding])
|
165
163
|
end
|
166
164
|
|
167
|
-
case @encoding
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
@chars = CHARS.merge(NAMED_CHARS)
|
172
|
-
end
|
165
|
+
@chars = case @encoding
|
166
|
+
when :hex_chars then CHARS.merge(ESCAPED_CHARS)
|
167
|
+
when :named_chars then CHARS.merge(NAMED_CHARS)
|
168
|
+
end
|
173
169
|
end
|
174
170
|
|
175
171
|
#
|
@@ -352,10 +348,8 @@ module Ronin
|
|
352
348
|
# @api private
|
353
349
|
#
|
354
350
|
def parse_int(int)
|
355
|
-
if @chars
|
356
|
-
|
357
|
-
else
|
358
|
-
int.to_i(@base)
|
351
|
+
if @chars then parse_char(int)
|
352
|
+
else int.to_i(@base)
|
359
353
|
end
|
360
354
|
end
|
361
355
|
|
@@ -383,10 +377,8 @@ module Ronin
|
|
383
377
|
#
|
384
378
|
def parse_word(word)
|
385
379
|
case @type
|
386
|
-
when :integer
|
387
|
-
|
388
|
-
when :float
|
389
|
-
parse_float(word)
|
380
|
+
when :integer then parse_int(word)
|
381
|
+
when :float then parse_float(word)
|
390
382
|
end
|
391
383
|
end
|
392
384
|
|
data/lib/ronin/binary/struct.rb
CHANGED
@@ -39,7 +39,7 @@ module Ronin
|
|
39
39
|
#
|
40
40
|
# pkt = Packet.new
|
41
41
|
# pkt.length = 5
|
42
|
-
# pkt.data
|
42
|
+
# pkt.data = 'hello'
|
43
43
|
#
|
44
44
|
# buffer = pkt.pack
|
45
45
|
# # => "\x00\x00\x00\x05hello\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
@@ -96,7 +96,7 @@ module Ronin
|
|
96
96
|
# Unpacking options.
|
97
97
|
#
|
98
98
|
# @option options [:little, :big, :network] :endian
|
99
|
-
# The endianness to apply to types.
|
99
|
+
# The endianness to apply to the types.
|
100
100
|
#
|
101
101
|
# @return [Struct]
|
102
102
|
# The newly unpacked structure.
|
@@ -131,10 +131,8 @@ module Ronin
|
|
131
131
|
# The structure does not contain the field.
|
132
132
|
#
|
133
133
|
def [](name)
|
134
|
-
if field?(name)
|
135
|
-
|
136
|
-
else
|
137
|
-
raise(ArgumentError,"no such field '#{name}'")
|
134
|
+
if field?(name) then send(name)
|
135
|
+
else raise(ArgumentError,"no such field '#{name}'")
|
138
136
|
end
|
139
137
|
end
|
140
138
|
|
@@ -154,10 +152,8 @@ module Ronin
|
|
154
152
|
# The structure does not contain the field.
|
155
153
|
#
|
156
154
|
def []=(name,value)
|
157
|
-
if field?(name)
|
158
|
-
|
159
|
-
else
|
160
|
-
raise(ArgumentError,"no such field '#{name}'")
|
155
|
+
if field?(name) then send("#{name}=",value)
|
156
|
+
else raise(ArgumentError,"no such field '#{name}'")
|
161
157
|
end
|
162
158
|
end
|
163
159
|
|
@@ -170,19 +166,15 @@ module Ronin
|
|
170
166
|
def values
|
171
167
|
normalize = lambda { |value|
|
172
168
|
case value
|
173
|
-
when Struct
|
174
|
-
|
175
|
-
else
|
176
|
-
value
|
169
|
+
when Struct then value.values
|
170
|
+
else value
|
177
171
|
end
|
178
172
|
}
|
179
173
|
|
180
174
|
self.class.layout.map do |name|
|
181
175
|
case (value = self[name])
|
182
|
-
when Array
|
183
|
-
value
|
184
|
-
else
|
185
|
-
normalize[value]
|
176
|
+
when Array then value.map(&normalize)
|
177
|
+
else normalize[value]
|
186
178
|
end
|
187
179
|
end
|
188
180
|
end
|
@@ -208,7 +200,7 @@ module Ronin
|
|
208
200
|
# Pack options.
|
209
201
|
#
|
210
202
|
# @option options [:little, :big, :network] :endian
|
211
|
-
# The endianness to apply to types.
|
203
|
+
# The endianness to apply to the types.
|
212
204
|
#
|
213
205
|
# @return [String]
|
214
206
|
# The packed structure.
|
@@ -227,7 +219,7 @@ module Ronin
|
|
227
219
|
# Unpack options.
|
228
220
|
#
|
229
221
|
# @option options [:little, :big, :network] :endian
|
230
|
-
# The endianness to apply to types.
|
222
|
+
# The endianness to apply to the types.
|
231
223
|
#
|
232
224
|
# @return [Struct]
|
233
225
|
# The unpacked structure.
|
@@ -383,10 +375,8 @@ module Ronin
|
|
383
375
|
# The endianness of the structure.
|
384
376
|
#
|
385
377
|
def self.endian(type=nil)
|
386
|
-
if type
|
387
|
-
|
388
|
-
else
|
389
|
-
@endian
|
378
|
+
if type then @endian = type.to_sym
|
379
|
+
else @endian
|
390
380
|
end
|
391
381
|
end
|
392
382
|
|
@@ -484,14 +474,10 @@ module Ronin
|
|
484
474
|
end
|
485
475
|
else
|
486
476
|
if type.kind_of?(Symbol)
|
487
|
-
if
|
488
|
-
|
489
|
-
elsif Template::
|
490
|
-
|
491
|
-
elsif Template::CHAR_TYPES.include?(type)
|
492
|
-
"\0"
|
493
|
-
elsif Template::STRING_TYPES.include?(type)
|
494
|
-
''
|
477
|
+
if Template::INT_TYPES.include?(type) then 0
|
478
|
+
elsif Template::FLOAT_TYPES.include?(type) then 0.0
|
479
|
+
elsif Template::CHAR_TYPES.include?(type) then "\0"
|
480
|
+
elsif Template::STRING_TYPES.include?(type) then ''
|
495
481
|
end
|
496
482
|
elsif type < Struct
|
497
483
|
type.new
|
@@ -22,7 +22,7 @@ require 'set'
|
|
22
22
|
module Ronin
|
23
23
|
module Binary
|
24
24
|
#
|
25
|
-
# Provides a translation layer between C
|
25
|
+
# Provides a translation layer between C-types and Ruby `Array#pack`
|
26
26
|
# codes.
|
27
27
|
#
|
28
28
|
# ## Types
|
@@ -60,7 +60,7 @@ module Ronin
|
|
60
60
|
# * `:byte` (`c`) - signed byte.
|
61
61
|
# * `:string` (`Z*`) - binary String, `\0` terminated.
|
62
62
|
#
|
63
|
-
# ### Ruby 1.9 specific types
|
63
|
+
# ### Ruby 1.9 specific C-types
|
64
64
|
#
|
65
65
|
# * `:uint16_le` (`S<`) - unsigned 16-bit integer, little endian.
|
66
66
|
# * `:uint32_le` (`L<`) - unsigned 32-bit integer, little endian.
|
@@ -99,7 +99,7 @@ module Ronin
|
|
99
99
|
#
|
100
100
|
class Template
|
101
101
|
|
102
|
-
# Supported types and corresponding `Array#pack` codes.
|
102
|
+
# Supported C-types and corresponding `Array#pack` codes.
|
103
103
|
TYPES = {
|
104
104
|
:uint8 => 'C',
|
105
105
|
:uint16 => 'S',
|
@@ -144,7 +144,7 @@ module Ronin
|
|
144
144
|
:string => 'Z*'
|
145
145
|
}
|
146
146
|
|
147
|
-
# Additional types, not available on Ruby 1.8:
|
147
|
+
# Additional C-types, not available on Ruby 1.8:
|
148
148
|
if RUBY_VERSION > '1.9.'
|
149
149
|
TYPES.merge!(
|
150
150
|
:uint16_le => 'S<',
|
@@ -185,7 +185,7 @@ module Ronin
|
|
185
185
|
)
|
186
186
|
end
|
187
187
|
|
188
|
-
# Integer types
|
188
|
+
# Integer C-types
|
189
189
|
INT_TYPES = Set[
|
190
190
|
:uint8,
|
191
191
|
:uint16,
|
@@ -246,17 +246,17 @@ module Ronin
|
|
246
246
|
:long_long_be
|
247
247
|
]
|
248
248
|
|
249
|
-
# Float types
|
249
|
+
# Float C-types
|
250
250
|
FLOAT_TYPES = Set[
|
251
251
|
:float, :double,
|
252
252
|
:float_le, :double_le,
|
253
253
|
:float_be, :double_be
|
254
254
|
]
|
255
255
|
|
256
|
-
# Character types
|
256
|
+
# Character C-types
|
257
257
|
CHAR_TYPES = Set[:uchar, :char]
|
258
258
|
|
259
|
-
# String types
|
259
|
+
# String C-types
|
260
260
|
STRING_TYPES = CHAR_TYPES + Set[:string]
|
261
261
|
|
262
262
|
# Types which have little and big endian forms
|
@@ -275,19 +275,19 @@ module Ronin
|
|
275
275
|
# Creates a new Binary Template.
|
276
276
|
#
|
277
277
|
# @param [Array<type, (type, length)>] fields
|
278
|
-
# The types which the packer will use.
|
278
|
+
# The C-types which the packer will use.
|
279
279
|
#
|
280
280
|
# @param [Hash] options
|
281
281
|
# Template options.
|
282
282
|
#
|
283
283
|
# @option options [:little, :big, :network] :endian
|
284
|
-
# The endianness to apply to types.
|
284
|
+
# The endianness to apply to the C-types.
|
285
285
|
#
|
286
286
|
# @raise [ArgumentError]
|
287
287
|
# A given type is not known.
|
288
288
|
#
|
289
289
|
# @note
|
290
|
-
# The following types are **not supported** on Ruby 1.8:
|
290
|
+
# The following C-types are **not supported** on Ruby 1.8:
|
291
291
|
#
|
292
292
|
# * `:uint16_le`
|
293
293
|
# * `:uint32_le`
|
@@ -343,7 +343,7 @@ module Ronin
|
|
343
343
|
# Translation options.
|
344
344
|
#
|
345
345
|
# @option options [:little, :big, :network] :endian
|
346
|
-
# The endianness to apply to types.
|
346
|
+
# The endianness to apply to the C-types.
|
347
347
|
#
|
348
348
|
# @return [Symbol]
|
349
349
|
# The translated type.
|
@@ -354,10 +354,8 @@ module Ronin
|
|
354
354
|
def self.translate(type,options={})
|
355
355
|
if (options[:endian] && ENDIAN_TYPES.include?(type))
|
356
356
|
type = case options[:endian]
|
357
|
-
when :little
|
358
|
-
|
359
|
-
when :big, :network
|
360
|
-
:"#{type}_be"
|
357
|
+
when :little then :"#{type}_le"
|
358
|
+
when :big, :network then :"#{type}_be"
|
361
359
|
else
|
362
360
|
raise(ArgumentError,"unknown endianness: #{type}")
|
363
361
|
end
|
@@ -367,17 +365,17 @@ module Ronin
|
|
367
365
|
end
|
368
366
|
|
369
367
|
#
|
370
|
-
# Compiles
|
368
|
+
# Compiles C-types into an `Array#pack` / `String#unpack`
|
371
369
|
# template.
|
372
370
|
#
|
373
371
|
# @param [Array<type, (type, length)>] types
|
374
|
-
# The types which the packer will use.
|
372
|
+
# The C-types which the packer will use.
|
375
373
|
#
|
376
374
|
# @param [Hash] options
|
377
375
|
# Type options.
|
378
376
|
#
|
379
377
|
# @option options [:little, :big, :network] :endian
|
380
|
-
# The endianness to apply to types.
|
378
|
+
# The endianness to apply to the C-types.
|
381
379
|
#
|
382
380
|
# @return [String]
|
383
381
|
# The `Array#pack` / `String#unpack` template.
|
@@ -439,6 +437,18 @@ module Ronin
|
|
439
437
|
@template
|
440
438
|
end
|
441
439
|
|
440
|
+
#
|
441
|
+
# Inspects the template.
|
442
|
+
#
|
443
|
+
# @return [String]
|
444
|
+
# The inspected template.
|
445
|
+
#
|
446
|
+
# @since 1.5.1
|
447
|
+
#
|
448
|
+
def inspect
|
449
|
+
"<#{self.class}: #{@fields.inspect}>"
|
450
|
+
end
|
451
|
+
|
442
452
|
end
|
443
453
|
end
|
444
454
|
end
|
@@ -66,12 +66,9 @@ class IPAddr
|
|
66
66
|
return enum_for(__method__,text,version).to_a unless block_given?
|
67
67
|
|
68
68
|
regexp = case version
|
69
|
-
when :ipv4, :v4, 4
|
70
|
-
|
71
|
-
|
72
|
-
Regexp::IPv6
|
73
|
-
else
|
74
|
-
Regexp::IP
|
69
|
+
when :ipv4, :v4, 4 then Regexp::IPv4
|
70
|
+
when :ipv6, :v6, 6 then Regexp::IPv6
|
71
|
+
else Regexp::IP
|
75
72
|
end
|
76
73
|
|
77
74
|
text.scan(regexp) do |match|
|
@@ -128,10 +125,8 @@ class IPAddr
|
|
128
125
|
separator = '::'
|
129
126
|
base = 16
|
130
127
|
|
131
|
-
prefix = if cidr_or_glob.start_with?('::')
|
132
|
-
|
133
|
-
else
|
134
|
-
''
|
128
|
+
prefix = if cidr_or_glob.start_with?('::') then '::'
|
129
|
+
else ''
|
135
130
|
end
|
136
131
|
|
137
132
|
format = lambda { |address|
|
@@ -20,6 +20,7 @@
|
|
20
20
|
require 'ronin/formatting/extensions/binary/integer'
|
21
21
|
require 'ronin/formatting/extensions/binary/float'
|
22
22
|
require 'ronin/formatting/extensions/binary/string'
|
23
|
+
require 'ronin/formatting/extensions/binary/array'
|
23
24
|
require 'ronin/formatting/extensions/binary/file'
|
24
25
|
|
25
26
|
require 'hexdump/extensions'
|
@@ -26,14 +26,14 @@ class Array
|
|
26
26
|
#
|
27
27
|
# Packs the Array into a String.
|
28
28
|
#
|
29
|
-
# @param [String, Array<Symbol>] arguments
|
29
|
+
# @param [String, Array<Symbol, (Symbol, Integer)>] arguments
|
30
30
|
# The `Array#pack` template or a list of {Ronin::Binary::Template} types.
|
31
31
|
#
|
32
32
|
# @return [String]
|
33
33
|
# The packed Array.
|
34
34
|
#
|
35
35
|
# @raise [ArgumentError]
|
36
|
-
#
|
36
|
+
# One of the arguments was not a known {Ronin::Binary::Template} type.
|
37
37
|
#
|
38
38
|
# @example using {Ronin::Binary::Template} types:
|
39
39
|
# [0x1234, "hello"].pack(:uint16_le, :string)
|
@@ -44,19 +44,17 @@ class Array
|
|
44
44
|
# # => "\x34\x12hello\0"
|
45
45
|
#
|
46
46
|
# @see http://rubydoc.info/stdlib/core/Array:pack
|
47
|
+
# @see Ronin::Binary::Template
|
47
48
|
#
|
48
49
|
# @since 0.5.0
|
49
50
|
#
|
50
51
|
# @api public
|
51
52
|
#
|
52
53
|
def pack(*arguments)
|
53
|
-
|
54
|
-
when String
|
54
|
+
if (arguments.length == 1 && arguments.first.kind_of?(String))
|
55
55
|
pack_original(arguments.first)
|
56
|
-
when Symbol
|
57
|
-
pack_original(Ronin::Binary::Template.compile(arguments))
|
58
56
|
else
|
59
|
-
|
57
|
+
pack_original(Ronin::Binary::Template.compile(arguments))
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|