ronin-support 0.1.0 → 0.2.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/ChangeLog.md +24 -0
  2. data/Gemfile +9 -1
  3. data/README.md +6 -3
  4. data/gemspec.yml +3 -1
  5. data/lib/ronin/extensions.rb +2 -1
  6. data/lib/ronin/extensions/file.rb +4 -0
  7. data/lib/ronin/extensions/ip_addr.rb +8 -0
  8. data/lib/ronin/extensions/kernel.rb +2 -0
  9. data/lib/ronin/extensions/string.rb +50 -11
  10. data/lib/ronin/formatting/extensions/binary.rb +2 -0
  11. data/lib/ronin/formatting/extensions/binary/file.rb +12 -1
  12. data/lib/ronin/formatting/extensions/binary/integer.rb +6 -0
  13. data/lib/ronin/formatting/extensions/binary/string.rb +20 -0
  14. data/lib/ronin/formatting/extensions/digest/file.rb +14 -0
  15. data/lib/ronin/formatting/extensions/digest/string.rb +8 -0
  16. data/lib/ronin/formatting/extensions/html.rb +21 -0
  17. data/lib/ronin/formatting/extensions/html/integer.rb +126 -0
  18. data/lib/ronin/formatting/extensions/html/string.rb +184 -0
  19. data/lib/ronin/formatting/extensions/http/integer.rb +7 -1
  20. data/lib/ronin/formatting/extensions/http/string.rb +10 -0
  21. data/lib/ronin/formatting/extensions/text.rb +2 -0
  22. data/lib/ronin/formatting/extensions/text/array.rb +10 -0
  23. data/lib/ronin/formatting/extensions/text/string.rb +44 -12
  24. data/lib/ronin/formatting/html.rb +20 -0
  25. data/lib/ronin/mixin.rb +89 -0
  26. data/lib/ronin/network/extensions/esmtp/net.rb +6 -0
  27. data/lib/ronin/network/extensions/http/net.rb +124 -51
  28. data/lib/ronin/network/extensions/imap/net.rb +4 -0
  29. data/lib/ronin/network/extensions/pop3/net.rb +4 -0
  30. data/lib/ronin/network/extensions/smtp/net.rb +73 -2
  31. data/lib/ronin/network/extensions/ssl/net.rb +4 -0
  32. data/lib/ronin/network/extensions/tcp/net.rb +16 -0
  33. data/lib/ronin/network/extensions/telnet/net.rb +4 -0
  34. data/lib/ronin/network/extensions/udp/net.rb +12 -0
  35. data/lib/ronin/network/http/http.rb +50 -29
  36. data/lib/ronin/network/http/proxy.rb +26 -0
  37. data/lib/ronin/network/imap.rb +4 -0
  38. data/lib/ronin/network/network.rb +2 -0
  39. data/lib/ronin/network/pop3.rb +4 -0
  40. data/lib/ronin/network/smtp/email.rb +43 -14
  41. data/lib/ronin/network/smtp/smtp.rb +6 -0
  42. data/lib/ronin/network/ssl.rb +2 -0
  43. data/lib/ronin/network/telnet.rb +16 -0
  44. data/lib/ronin/path.rb +6 -0
  45. data/lib/ronin/support/inflector.rb +3 -1
  46. data/lib/ronin/support/version.rb +1 -1
  47. data/lib/ronin/templates/erb.rb +4 -0
  48. data/lib/ronin/templates/template.rb +10 -0
  49. data/spec/extensions/string_spec.rb +4 -4
  50. data/spec/formatting/html/integer_spec.rb +66 -0
  51. data/spec/formatting/html/string_spec.rb +103 -0
  52. data/spec/formatting/http/string_spec.rb +1 -1
  53. data/spec/formatting/text/string_spec.rb +18 -66
  54. data/spec/mixin_spec.rb +53 -0
  55. data/spec/network/http/http_spec.rb +0 -7
  56. data/spec/network/http/proxy_spec.rb +2 -2
  57. data/spec/network/smtp/email_spec.rb +100 -0
  58. data/spec/path_spec.rb +13 -13
  59. data/spec/templates/helpers/data.rb +1 -1
  60. metadata +52 -33
@@ -1,3 +1,27 @@
1
+ ### 0.2.0 / 2011-05-14
2
+
3
+ * Require data_paths ~> 0.3.
4
+ * Added {Ronin::Mixin}.
5
+ * Added {Ronin::Network::SMTP::Email#headers}.
6
+ * Added {Integer#html_escape}.
7
+ * Added {Integer#js_escape}.
8
+ * Added {Integer#format_js}.
9
+ * Added {String#html_escape}.
10
+ * Added {String#html_unescape}.
11
+ * Added {String#js_escape}.
12
+ * Added {String#js_unescape}.
13
+ * Added {String#format_js}.
14
+ * Added {Net.smtp_send_message}.
15
+ * Added {Net.http_status}.
16
+ * Added YARD `@api` tags to define the public, semi-public and private APIs.
17
+ * Allow `:method` to be used with {Net.http_ok?}.
18
+ * Fixed a bug in {Ronin::Network::HTTP.expand_url} where `:host` and `:port`
19
+ options were being overridden.
20
+ * Fixed a bug in {String#format_chars}, where it was not using `each_char`
21
+ for unicode characters.
22
+ * Deprecated {String#common_postfix}, in favor of {String#common_suffix}.
23
+ {String#common_postfix} will be removed in ronin-support 1.0.0.
24
+
1
25
  ### 0.1.0 / 2011-03-20
2
26
 
3
27
  * Initial release:
data/Gemfile CHANGED
@@ -18,5 +18,13 @@ end
18
18
  group :test do
19
19
  gem 'i18n', '~> 0.4'
20
20
  gem 'tzinfo', '~> 0.3.0'
21
- gem 'activesupport', '~> 3.0.0'
21
+
22
+ INFLECTORS = {
23
+ 'activesupport' => '~> 3.0.0',
24
+ 'dm-core' => '~> 1.0',
25
+ 'extlib' => '~> 0.9.15'
26
+ }
27
+
28
+ inflector = ENV.fetch('INFLECTOR','dm-core')
29
+ gem(inflector,INFLECTORS[inflector])
22
30
  end
data/README.md CHANGED
@@ -22,6 +22,7 @@ or payloads over many common Source-Code-Management (SCM) systems.
22
22
  * Binary
23
23
  * Text
24
24
  * HTTP
25
+ * HTML
25
26
  * URIs
26
27
  * Generating random text.
27
28
  * Networking:
@@ -41,23 +42,25 @@ or payloads over many common Source-Code-Management (SCM) systems.
41
42
  ## Examples
42
43
 
43
44
  For examples of the convenience methods provided by ronin-support,
44
- please see [Everyday Ronin](http://ronin-ruby.github.com/resources/everyday_ronin.html).
45
+ please see [Everyday Ronin](http://ronin-ruby.github.com/guides/everyday_ronin.html).
45
46
 
46
47
  ## Requirements
47
48
 
48
49
  * [Ruby](http://www.ruby-lang.org/) >= 1.8.7
49
50
  * [chars](http://github.com/postmodern/chars#readme)
50
51
  ~> 0.2
52
+ * [hexdump](http://github.com/postmodern/hexdump#readme)
53
+ ~> 0.1
51
54
  * [combinatorics](http://github.com/postmodern/combinatorics#readme)
52
55
  ~> 0.3
53
56
  * [uri-query_params](http://github.com/postmodern/uri-query_params#readme)
54
57
  ~> 0.5, >= 0.5.2
55
58
  * [data_paths](http://github.com/postmodern/data_paths#readme)
56
- ~> 0.2, >= 0.2.1
59
+ ~> 0.3
57
60
 
58
61
  ## Install
59
62
 
60
- $ sudo gem install ronin-support
63
+ $ gem install ronin-support
61
64
 
62
65
  ## License
63
66
 
@@ -14,9 +14,11 @@ required_ruby_version: ">= 1.8.7"
14
14
 
15
15
  dependencies:
16
16
  chars: ~> 0.2
17
+ hexdump: ~> 0.1
17
18
  combinatorics: ~> 0.3
18
19
  uri-query_params: ~> 0.5, >= 0.5.2
19
- data_paths: ~> 0.2, >= 0.2.1
20
+ # data_paths: ~> 0.3
21
+ data_paths: 0.3.0.rc1
20
22
 
21
23
  development_dependencies:
22
24
  bundler: ~> 1.0.10
@@ -23,4 +23,5 @@ require 'ronin/extensions/file'
23
23
  require 'ronin/extensions/ip_addr'
24
24
  require 'ronin/extensions/kernel'
25
25
 
26
- require 'uri/query_params'
26
+ require 'hexdump/extensions'
27
+ require 'uri/query_params/extensions'
@@ -30,6 +30,8 @@ class File
30
30
  #
31
31
  # @return [nil]
32
32
  #
33
+ # @api public
34
+ #
33
35
  def File.write(path,data)
34
36
  File.open(path,'w') { |file| file.write(data) }
35
37
  end
@@ -43,6 +45,8 @@ class File
43
45
  # @return [String]
44
46
  # The escaped path.
45
47
  #
48
+ # @api public
49
+ #
46
50
  def File.escape_path(path)
47
51
  path = path.to_s
48
52
 
@@ -53,6 +53,8 @@ class IPAddr
53
53
  # @return [Array<String>]
54
54
  # The IP Addresses found in the text.
55
55
  #
56
+ # @api public
57
+ #
56
58
  def IPAddr.extract(text,version=nil,&block)
57
59
  regexp = case version
58
60
  when :ipv4
@@ -108,6 +110,8 @@ class IPAddr
108
110
  # puts ip
109
111
  # end
110
112
  #
113
+ # @api public
114
+ #
111
115
  def IPAddr.each(cidr_or_glob,&block)
112
116
  unless (cidr_or_glob.include?('*') || cidr_or_glob.include?('-'))
113
117
  return IPAddr.new(cidr_or_glob).each(&block)
@@ -168,6 +172,8 @@ class IPAddr
168
172
  # @return [Array<String>]
169
173
  # The host-names for the IP address.
170
174
  #
175
+ # @api public
176
+ #
171
177
  def lookup
172
178
  Resolv.getnames(self.to_s)
173
179
  end
@@ -190,6 +196,8 @@ class IPAddr
190
196
  # puts ip
191
197
  # end
192
198
  #
199
+ # @api public
200
+ #
193
201
  def each
194
202
  return enum_for(:each) unless block_given?
195
203
 
@@ -33,6 +33,8 @@ module Kernel
33
33
  # Resolv.getaddress('might.not.exist.com')
34
34
  # end
35
35
  #
36
+ # @api public
37
+ #
36
38
  def attempt
37
39
  begin
38
40
  yield() if block_given?
@@ -39,6 +39,8 @@ class String
39
39
  # @return [String]
40
40
  # The original string
41
41
  #
42
+ # @api public
43
+ #
42
44
  def each_substring(min=0,&block)
43
45
  return enum_for(:each_substring,min) unless block
44
46
 
@@ -79,6 +81,8 @@ class String
79
81
  #
80
82
  # @see each_substring
81
83
  #
84
+ # @api public
85
+ #
82
86
  def each_unique_substring(min=0,&block)
83
87
  return enum_for(:each_unique_substring,min) unless block
84
88
 
@@ -100,9 +104,15 @@ class String
100
104
  end
101
105
 
102
106
  #
103
- # Returns the common prefix of the string and the specified other
104
- # string. If no common prefix can be found an empty string will be
105
- # returned.
107
+ # The common prefix of the string and the specified other string.
108
+ #
109
+ # @param [String] other
110
+ # The other String to compare against.
111
+ #
112
+ # @return [String]
113
+ # The common prefix between the two Strings.
114
+ #
115
+ # @api public
106
116
  #
107
117
  def common_prefix(other)
108
118
  min_length = [length, other.length].min
@@ -117,11 +127,19 @@ class String
117
127
  end
118
128
 
119
129
  #
120
- # Returns the common postfix of the string and the specified other
121
- # string. If no common postfix can be found an empty string will be
122
- # returned.
130
+ # Finds the common suffix of the string and the specified other string.
123
131
  #
124
- def common_postfix(other)
132
+ # @param [String] pther
133
+ # The other String to compare against.
134
+ #
135
+ # @return [String]
136
+ # The common suffix of the two Strings.
137
+ #
138
+ # @since 0.2.0
139
+ #
140
+ # @api public
141
+ #
142
+ def common_suffix(other)
125
143
  min_length = [length, other.length].min
126
144
 
127
145
  (min_length - 1).times do |i|
@@ -137,13 +155,32 @@ class String
137
155
  end
138
156
 
139
157
  #
140
- # Returns the uncommon substring within the specified other string,
141
- # which does not occur within the string. If no uncommon substring can be
142
- # found, an empty string will be returned.
158
+ # @deprecated
159
+ # Deprecates as of 0.2.0, and will be removed in 1.0.0.
160
+ # Please use {#common_suffix} instead.
161
+ #
162
+ def common_postfix(other)
163
+ STDERR.puts "DEPRECATED: String#common_postfix was deprecated in 0.2.0."
164
+ STDERR.puts "DEPRECATED: Please use String#common_suffix instead."
165
+
166
+ common_suffix(other)
167
+ end
168
+
169
+ #
170
+ # Finds the uncommon substring within the specified other string,
171
+ # which does not occur within the string.
172
+ #
173
+ # @param [String] other
174
+ # The other String to compare against.
175
+ #
176
+ # @return [String]
177
+ # The uncommon substring between the two Strings.
178
+ #
179
+ # @api public
143
180
  #
144
181
  def uncommon_substring(other)
145
182
  prefix = common_prefix(other)
146
- postfix = self[prefix.length..-1].common_postfix(other[prefix.length..-1])
183
+ postfix = self[prefix.length..-1].common_suffix(other[prefix.length..-1])
147
184
 
148
185
  return self[prefix.length...(length - postfix.length)]
149
186
  end
@@ -158,6 +195,8 @@ class String
158
195
  # "hello\x00\073\x90\r\n".dump
159
196
  # # => "hello\0;\x90\r\n"
160
197
  #
198
+ # @api public
199
+ #
161
200
  def dump
162
201
  c_string = ''
163
202
 
@@ -20,3 +20,5 @@
20
20
  require 'ronin/formatting/extensions/binary/integer'
21
21
  require 'ronin/formatting/extensions/binary/string'
22
22
  require 'ronin/formatting/extensions/binary/file'
23
+
24
+ require 'hexdump/extensions'
@@ -22,10 +22,21 @@ require 'ronin/formatting/extensions/binary/string'
22
22
  class File
23
23
 
24
24
  #
25
- # Converts the hexdump at the given path back into raw-data.
25
+ # Converts a hexdump file to it's original binary data.
26
+ #
27
+ # @param [Pathname, String] path
28
+ # The path of the hexdump file.
29
+ #
30
+ # @param [Hash] options
31
+ # Hexdump options.
32
+ #
33
+ # @return [String]
34
+ # The original binary data.
26
35
  #
27
36
  # @see String#unhexdump.
28
37
  #
38
+ # @api public
39
+ #
29
40
  def File.unhexdump(path,options={})
30
41
  File.read(path).unhexdump(options)
31
42
  end
@@ -44,6 +44,8 @@ class Integer
44
44
  # 0xff41.bytes(4, :big)
45
45
  # # => [0, 0, 255, 65]
46
46
  #
47
+ # @api public
48
+ #
47
49
  def bytes(address_length,endian=:little)
48
50
  endian = endian.to_sym
49
51
  buffer = []
@@ -107,6 +109,8 @@ class Integer
107
109
  #
108
110
  # @see http://ruby-doc.org/core/classes/Array.html#M002222
109
111
  #
112
+ # @api public
113
+ #
110
114
  def pack(arch,address_length=nil)
111
115
  if arch.kind_of?(String)
112
116
  return [self].pack(arch)
@@ -136,6 +140,8 @@ class Integer
136
140
  # 42.hex_escape
137
141
  # # => "\\x2a"
138
142
  #
143
+ # @api public
144
+ #
139
145
  def hex_escape
140
146
  "\\x%.2x" % self
141
147
  end
@@ -69,6 +69,8 @@ class String
69
69
  #
70
70
  # @see http://ruby-doc.org/core/classes/String.html#M000760
71
71
  #
72
+ # @api public
73
+ #
72
74
  def depack(arch,address_length=nil)
73
75
  if arch.kind_of?(String)
74
76
  return self.unpack(arch)
@@ -118,10 +120,14 @@ class String
118
120
  #
119
121
  # @see String#format_bytes
120
122
  #
123
+ # @api public
124
+ #
121
125
  def hex_escape(options={})
122
126
  format_bytes(options) { |b| b.hex_escape }
123
127
  end
124
128
 
129
+ #
130
+ # Unescapes the hex-escaped String.
125
131
  #
126
132
  # @return [String]
127
133
  # The unescaped version of the hex escaped String.
@@ -130,6 +136,8 @@ class String
130
136
  # "\\x68\\x65\\x6c\\x6c\\x6f".hex_unescape
131
137
  # # => "hello"
132
138
  #
139
+ # @api public
140
+ #
133
141
  def hex_unescape
134
142
  buffer = ''
135
143
  hex_index = 0
@@ -196,6 +204,8 @@ class String
196
204
  # "hello again".xor([0x55, 0x41, 0xe1])
197
205
  # # => "=$\x8d9.\xc14&\x80</"
198
206
  #
207
+ # @api public
208
+ #
199
209
  def xor(key)
200
210
  key = if key.kind_of?(Integer)
201
211
  [key]
@@ -219,6 +229,8 @@ class String
219
229
  # @return [String]
220
230
  # The base64 encoded form of the string.
221
231
  #
232
+ # @api public
233
+ #
222
234
  def base64_encode
223
235
  Base64.encode64(self)
224
236
  end
@@ -229,6 +241,8 @@ class String
229
241
  # @return [String]
230
242
  # The base64 decoded form of the string.
231
243
  #
244
+ # @api public
245
+ #
232
246
  def base64_decode
233
247
  Base64.decode64(self)
234
248
  end
@@ -239,6 +253,8 @@ class String
239
253
  # @return [String]
240
254
  # The Zlib inflated form of the string.
241
255
  #
256
+ # @api public
257
+ #
242
258
  def zlib_inflate
243
259
  Zlib::Inflate.inflate(self)
244
260
  end
@@ -249,6 +265,8 @@ class String
249
265
  # @return [String]
250
266
  # The Zlib deflated form of the string.
251
267
  #
268
+ # @api public
269
+ #
252
270
  def zlib_deflate
253
271
  Zlib::Deflate.deflate(self)
254
272
  end
@@ -288,6 +306,8 @@ class String
288
306
  #
289
307
  # @return [String] The raw-data from the hexdump.
290
308
  #
309
+ # @api public
310
+ #
291
311
  def unhexdump(options={})
292
312
  case (format = options[:format])
293
313
  when :od
@@ -36,6 +36,8 @@ class File
36
36
  # File.md5('data.txt')
37
37
  # # => "5d41402abc4b2a76b9719d911017c592"
38
38
  #
39
+ # @api public
40
+ #
39
41
  def File.md5(path)
40
42
  Digest::MD5.file(path).hexdigest
41
43
  end
@@ -53,6 +55,8 @@ class File
53
55
  # File.sha1('data.txt')
54
56
  # # => "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"
55
57
  #
58
+ # @api public
59
+ #
56
60
  def File.sha1(path)
57
61
  Digest::SHA1.file(path).hexdigest
58
62
  end
@@ -60,6 +64,8 @@ class File
60
64
  #
61
65
  # @see File.sha1
62
66
  #
67
+ # @api public
68
+ #
63
69
  def File.sha128(path)
64
70
  File.sha1(path)
65
71
  end
@@ -77,6 +83,8 @@ class File
77
83
  # File.sha256('data.txt')
78
84
  # # => "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
79
85
  #
86
+ # @api public
87
+ #
80
88
  def File.sha256(path)
81
89
  Digest::SHA256.file(path).hexdigest
82
90
  end
@@ -84,6 +92,8 @@ class File
84
92
  #
85
93
  # @see File.sha256
86
94
  #
95
+ # @api public
96
+ #
87
97
  def File.sha2(path)
88
98
  File.sha256(path)
89
99
  end
@@ -101,6 +111,8 @@ class File
101
111
  # File.sha512('data.txt')
102
112
  # # => "9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043"
103
113
  #
114
+ # @api public
115
+ #
104
116
  def File.sha512(path)
105
117
  Digest::SHA512.file(path).hexdigest
106
118
  end
@@ -108,6 +120,8 @@ class File
108
120
  #
109
121
  # @see File.sha512
110
122
  #
123
+ # @api public
124
+ #
111
125
  def File.sha5(path)
112
126
  File.sha512(path)
113
127
  end