ronin-support 0.4.0.rc2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.4.0 / 2012-01-01
1
+ ### 0.4.0 / 2012-02-12
2
2
 
3
3
  * Require uri-query_params ~> 0.6.
4
4
  * Require parameters ~> 0.4.
@@ -9,13 +9,13 @@
9
9
  * Added {Regexp::FILE_NAME}.
10
10
  * Added {Regexp::FILE}.
11
11
  * Added {Regexp::DIRECTORY}.
12
- * Added {Regexp::LOCAL_UNIX_PATH}.
12
+ * Added {Regexp::RELATIVE_UNIX_PATH}.
13
13
  * Added {Regexp::ABSOLUTE_UNIX_PATH}.
14
14
  * Added {Regexp::UNIX_PATH}.
15
- * Added {Regexp::LOCAL_WINDOWS_PATH}.
15
+ * Added {Regexp::RELATIVE_WINDOWS_PATH}.
16
16
  * Added {Regexp::ABSOLUTE_WINDOWS_PATH}.
17
17
  * Added {Regexp::WINDOWS_PATH}.
18
- * Added {Regexp::LOCAL_PATH}.
18
+ * Added {Regexp::RELATIVE_PATH}.
19
19
  * Added {Regexp::ABSOLUTE_PATH}.
20
20
  * Added {Regexp::PATH}.
21
21
  * Added {String#repeating}.
@@ -41,7 +41,9 @@
41
41
  * Added {Ronin::Fuzzing.sint32}.
42
42
  * Added {Ronin::Fuzzing.sint64}.
43
43
  * Added {Ronin::Wordlist}.
44
+ * Added {Ronin::Network::DNS}.
44
45
  * Added {Ronin::Network::Mixins::Mixin}.
46
+ * Added {Ronin::Network::Mixins::DNS}.
45
47
  * Added {Ronin::Network::Mixins::SSL}.
46
48
  * Added missing {Ronin::Network::UDP#udp_send} and
47
49
  {Ronin::Network::Mixins::UDP#udp_send} methods.
data/README.md CHANGED
@@ -28,6 +28,7 @@ or payloads over many common Source-Code-Management (SCM) systems.
28
28
  * SQL
29
29
  * Fuzzing
30
30
  * Networking:
31
+ * DNS
31
32
  * TCP
32
33
  * UDP
33
34
  * SMTP / ESMTP
@@ -28,10 +28,29 @@ class Regexp
28
28
  MAC = /[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5}/
29
29
 
30
30
  # A regular expression for matching IPv4 Addresses.
31
- IPv4 = /#{OCTET}(?:\.#{OCTET}){3}/
31
+ IPv4 = /#{OCTET}(?:\.#{OCTET}){3}(?:\/\d{1,2})?/
32
32
 
33
33
  # A regular expression for matching IPv6 Addresses.
34
- IPv6 = /:(:[0-9a-f]{1,4}){1,7}|([0-9a-f]{1,4}::?){1,7}[0-9a-f]{1,4}(:#{IPv4})?/
34
+ IPv6 = union(
35
+ /(?:[0-9a-f]{1,4}:){6}#{IPv4}/,
36
+ /(?:[0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:#{IPv4}/,
37
+ /(?:[0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:#{IPv4}/,
38
+ /(?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,4}:#{IPv4}/,
39
+ /(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,3}:#{IPv4}/,
40
+ /(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,2}:#{IPv4}/,
41
+ /(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,1}:#{IPv4}/,
42
+ /:(?::[0-9a-f]{1,4}){1,5}:#{IPv4}/,
43
+ /(?:(?:[0-9a-f]{1,4}:){1,5}|:):#{IPv4}/,
44
+ /(?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,6}(?:\/\d{1,3})?/,
45
+ /(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}(?:\/\d{1,3})?/,
46
+ /(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}(?:\/\d{1,3})?/,
47
+ /(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}(?:\/\d{1,3})?/,
48
+ /(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}(?:\/\d{1,3})?/,
49
+ /(?:[0-9a-f]{1,4}:){1,6}(?::[0-9a-f]{1,4}){1,1}(?:\/\d{1,3})?/,
50
+ /[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){7}(?:\/\d{1,3})?/,
51
+ /:(?::[0-9a-f]{1,4}){1,7}(?:\/\d{1,3})?/,
52
+ /(?:(?:[0-9a-f]{1,4}:){1,7}|:):(?:\/\d{1,3})?/
53
+ )
35
54
 
36
55
  # A regular expression for matching IP Addresses.
37
56
  IP = /#{IPv4}|#{IPv6}/
@@ -40,19 +59,19 @@ class Regexp
40
59
  HOST_NAME = /(?:[a-zA-Z0-9]+(?:[_-][a-zA-Z0-9]+)*\.)+(?:#{union(Resolv::TLDS)})/i
41
60
 
42
61
  # Regular expression to match a word in the username of an email address
43
- USER_NAME = /[A-Za-z](?:[A-Za-z0-9]+[\._-])*[A-Za-z0-9]+/
62
+ USER_NAME = /[A-Za-z](?:[A-Za-z0-9]*[\._-])*[A-Za-z0-9]+/
44
63
 
45
64
  # Regular expression to find email addresses in text
46
- EMAIL_ADDR = /#{USER_NAME}(?:\.#{USER_NAME})*\@#{HOST_NAME}/
65
+ EMAIL_ADDR = /#{USER_NAME}\@#{HOST_NAME}/
47
66
 
48
67
  # Regular expression to find deliminators in text
49
68
  DELIM = /[;&\n\r]/
50
69
 
51
70
  # Regular expression to find identifier in text
52
- IDENTIFIER = /[_a-zA-Z][a-zA-Z0-9_-]*/
71
+ IDENTIFIER = /[_]*[a-zA-Z]+[a-zA-Z0-9_-]*/
53
72
 
54
73
  # Regular expression to find File extensions in text
55
- FILE_EXT = /(?:\.[A-Za-z0-9_-]+)+/
74
+ FILE_EXT = /(?:\.[A-Za-z0-9]+)+/
56
75
 
57
76
  # Regular expression to find File names in text
58
77
  FILE_NAME = /(?:[^\/\\\. ]|\\[\/\\ ])+/
@@ -64,25 +83,25 @@ class Regexp
64
83
  DIRECTORY = /(?:\.\.|\.|#{FILE})/
65
84
 
66
85
  # Regular expression to find local UNIX Paths in text
67
- LOCAL_UNIX_PATH = /(?:#{DIRECTORY}\/)+#{DIRECTORY}\/?/
86
+ RELATIVE_UNIX_PATH = /(?:#{DIRECTORY}\/)+#{DIRECTORY}\/?/
68
87
 
69
88
  # Regular expression to find absolute UNIX Paths in text
70
89
  ABSOLUTE_UNIX_PATH = /(?:\/#{FILE})+\/?/
71
90
 
72
91
  # Regular expression to find UNIX Paths in text
73
- UNIX_PATH = /#{ABSOLUTE_UNIX_PATH}|#{LOCAL_UNIX_PATH}/
92
+ UNIX_PATH = /#{ABSOLUTE_UNIX_PATH}|#{RELATIVE_UNIX_PATH}/
74
93
 
75
94
  # Regular expression to find local Windows Paths in text
76
- LOCAL_WINDOWS_PATH = /(?:#{DIRECTORY}\\)+#{DIRECTORY}\\?/
95
+ RELATIVE_WINDOWS_PATH = /(?:#{DIRECTORY}\\)+#{DIRECTORY}\\?/
77
96
 
78
97
  # Regular expression to find absolute Windows Paths in text
79
- ABSOLUTE_WINDOWS_PATH = /[A-Za-z]:(?:\\#{DIRECTORY})+\\?/
98
+ ABSOLUTE_WINDOWS_PATH = /[A-Za-z]:(?:\\#{FILE})+\\?/
80
99
 
81
100
  # Regular expression to find Windows Paths in text
82
- WINDOWS_PATH = /#{ABSOLUTE_WINDOWS_PATH}|#{LOCAL_WINDOWS_PATH}/
101
+ WINDOWS_PATH = /#{ABSOLUTE_WINDOWS_PATH}|#{RELATIVE_WINDOWS_PATH}/
83
102
 
84
103
  # Regular expression to find local Paths in text
85
- LOCAL_PATH = /#{LOCAL_UNIX_PATH}|#{LOCAL_WINDOWS_PATH}/
104
+ RELATIVE_PATH = /#{RELATIVE_UNIX_PATH}|#{RELATIVE_WINDOWS_PATH}/
86
105
 
87
106
  # Regular expression to find absolute Paths in text
88
107
  ABSOLUTE_PATH = /#{ABSOLUTE_UNIX_PATH}|#{ABSOLUTE_WINDOWS_PATH}/
@@ -20,9 +20,18 @@
20
20
  require 'set'
21
21
 
22
22
  module Ronin
23
+ #
24
+ # Contains class-methods which generate malicious data for fuzzing.
25
+ #
26
+ # @see Fuzzing.[]
27
+ #
28
+ # @since 0.4.0
29
+ #
23
30
  module Fuzzing
31
+ # Short String lengths
24
32
  SHORT_LENGTHS = SortedSet[1, 100, 500, 1_000, 10_000]
25
33
 
34
+ # Long String lengths
26
35
  LONG_LENGTHS = SortedSet[
27
36
  128, 255, 256, 257, 511, 512, 513, 1023, 1024, 2048, 2049, 4095,
28
37
  4096, 4097, 5_000, 10_000, 20_000, 32762, 32763, 32764, 32765, 32766,
@@ -51,14 +60,23 @@ module Ronin
51
60
  #
52
61
  # @api semipublic
53
62
  #
54
- # @since 0.4.0
55
- #
56
63
  def self.[](name)
57
64
  if (!Object.respond_to?(name) && respond_to?(name))
58
65
  enum_for(name)
59
66
  end
60
67
  end
61
68
 
69
+ #
70
+ # Various bad-strings.
71
+ #
72
+ # @yield [string]
73
+ # The given block will be passed each bad-string.
74
+ #
75
+ # @yieldparam [String] string
76
+ # A bad-string containing known control characters, deliminators
77
+ # or null-bytes (see {NULL_BYTES}), of varying length
78
+ # (see {SHORT_LENGTHS} and {LONG_LENGTHS}).
79
+ #
62
80
  def self.bad_strings(&block)
63
81
  yield ''
64
82
 
@@ -91,6 +109,15 @@ module Ronin
91
109
  yield "<>" * 500
92
110
  end
93
111
 
112
+ #
113
+ # Various format-strings.
114
+ #
115
+ # @yield [fmt_string]
116
+ # The given block will be passed each format-string.
117
+ #
118
+ # @yieldparam [String] fmt_string
119
+ # A format-string containing format operators (see {FORMAT_STRINGS}).
120
+ #
94
121
  def self.format_strings(&block)
95
122
  FORMAT_STRINGS.each do |fmt|
96
123
  yield fmt
@@ -100,6 +127,15 @@ module Ronin
100
127
  end
101
128
  end
102
129
 
130
+ #
131
+ # Various bad paths and directory traversals.
132
+ #
133
+ # @yield [path]
134
+ # The given block will be passed each path.
135
+ #
136
+ # @yieldparam [String] path
137
+ # A known bad path.
138
+ #
103
139
  def self.bad_paths(&block)
104
140
  padding = 'A' * 5_000
105
141
 
@@ -121,6 +157,15 @@ module Ronin
121
157
  end
122
158
  end
123
159
 
160
+ #
161
+ # The range of bit-fields.
162
+ #
163
+ # @yield [bitfield]
164
+ # The given block will be passed each bit-field.
165
+ #
166
+ # @yieldparam [String] bitfield
167
+ # A bit-field (8bit - 64bit).
168
+ #
124
169
  def self.bit_fields(&block)
125
170
  ("\x00".."\xff").each do |c|
126
171
  yield c
@@ -130,6 +175,15 @@ module Ronin
130
175
  end
131
176
  end
132
177
 
178
+ #
179
+ # The range of signed bit-fields.
180
+ #
181
+ # @yield [bitfield]
182
+ # The given block will be passed each bit-field.
183
+ #
184
+ # @yieldparam [String] bitfield
185
+ # A signed bit-field (8bit - 64bit).
186
+ #
133
187
  def self.signed_bit_fields(&block)
134
188
  ("\x80".."\xff").each do |c|
135
189
  yield c
@@ -139,50 +193,158 @@ module Ronin
139
193
  end
140
194
  end
141
195
 
196
+ #
197
+ # The range of unsigned 8bit integers.
198
+ #
199
+ # @yield [int]
200
+ # The given block will be passed each integer.
201
+ #
202
+ # @yieldparam [String] int
203
+ # A unsigned 8bit integer.
204
+ #
142
205
  def self.uint8(&block)
143
206
  ("\x00".."\xff").each(&block)
144
207
  end
145
208
 
209
+ #
210
+ # The range of unsigned 16bit integers.
211
+ #
212
+ # @yield [int]
213
+ # The given block will be passed each integer.
214
+ #
215
+ # @yieldparam [String] int
216
+ # A unsigned 16bit integer.
217
+ #
146
218
  def self.uint16
147
219
  uint8 { |c| yield c * 2 }
148
220
  end
149
221
 
222
+ #
223
+ # The range of unsigned 32bit integers.
224
+ #
225
+ # @yield [int]
226
+ # The given block will be passed each integer.
227
+ #
228
+ # @yieldparam [String] int
229
+ # A unsigned 32bit integer.
230
+ #
150
231
  def self.uint32
151
232
  uint8 { |c| yield c * 4 }
152
233
  end
153
234
 
235
+ #
236
+ # The range of unsigned 64bit integers.
237
+ #
238
+ # @yield [int]
239
+ # The given block will be passed each integer.
240
+ #
241
+ # @yieldparam [String] int
242
+ # A unsigned 64bit integer.
243
+ #
154
244
  def self.uint64
155
245
  uint8 { |c| yield c * 8 }
156
246
  end
157
247
 
248
+ #
249
+ # The range of signed 8bit integers.
250
+ #
251
+ # @yield [int]
252
+ # The given block will be passed each integer.
253
+ #
254
+ # @yieldparam [String] int
255
+ # A signed 8bit integer.
256
+ #
158
257
  def self.int8(&block)
159
258
  ("\x00".."\x70").each(&block)
160
259
  end
161
260
 
261
+ #
262
+ # The range of signed 16bit integers.
263
+ #
264
+ # @yield [int]
265
+ # The given block will be passed each integer.
266
+ #
267
+ # @yieldparam [String] int
268
+ # A signed 16bit integer.
269
+ #
162
270
  def self.int16
163
271
  int8 { |c| yield c * 2 }
164
272
  end
165
273
 
274
+ #
275
+ # The range of signed 32bit integers.
276
+ #
277
+ # @yield [int]
278
+ # The given block will be passed each integer.
279
+ #
280
+ # @yieldparam [String] int
281
+ # A signed 32bit integer.
282
+ #
166
283
  def self.int32
167
284
  int8 { |c| yield c * 4 }
168
285
  end
169
286
 
287
+ #
288
+ # The range of signed 64bit integers.
289
+ #
290
+ # @yield [int]
291
+ # The given block will be passed each integer.
292
+ #
293
+ # @yieldparam [String] int
294
+ # A signed 64bit integer.
295
+ #
170
296
  def self.int64
171
297
  int8 { |c| yield c * 8 }
172
298
  end
173
299
 
300
+ #
301
+ # The range of negative-signed 8bit integers.
302
+ #
303
+ # @yield [int]
304
+ # The given block will be passed each integer.
305
+ #
306
+ # @yieldparam [String] int
307
+ # A negative-signed 8bit integer.
308
+ #
174
309
  def self.sint8(&block)
175
310
  ("\x80".."\xff").each(&block)
176
311
  end
177
312
 
313
+ #
314
+ # The range of negative-signed 16bit integers.
315
+ #
316
+ # @yield [int]
317
+ # The given block will be passed each integer.
318
+ #
319
+ # @yieldparam [String] int
320
+ # A negative-signed 16bit integer.
321
+ #
178
322
  def self.sint16
179
323
  sint8 { |c| yield c * 2 }
180
324
  end
181
325
 
326
+ #
327
+ # The range of negative-signed 32bit integers.
328
+ #
329
+ # @yield [int]
330
+ # The given block will be passed each integer.
331
+ #
332
+ # @yieldparam [String] int
333
+ # A negative-signed 32bit integer.
334
+ #
182
335
  def self.sint32
183
336
  sint8 { |c| yield c * 4 }
184
337
  end
185
338
 
339
+ #
340
+ # The range of negative-signed 64bit integers.
341
+ #
342
+ # @yield [int]
343
+ # The given block will be passed each integer.
344
+ #
345
+ # @yieldparam [String] int
346
+ # A negative-signed 64bit integer.
347
+ #
186
348
  def self.sint64
187
349
  sint8 { |c| yield c * 8 }
188
350
  end
data/lib/ronin/network.rb CHANGED
@@ -17,6 +17,7 @@
17
17
  # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
+ require 'ronin/network/dns'
20
21
  require 'ronin/network/tcp'
21
22
  require 'ronin/network/udp'
22
23
  require 'ronin/network/smtp'
@@ -0,0 +1,161 @@
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 'resolv'
21
+
22
+ module Ronin
23
+ module Network
24
+ #
25
+ # Provides helper methods for performing DNS queries.
26
+ #
27
+ # @since 0.4.0
28
+ #
29
+ module DNS
30
+ #
31
+ # The DNS nameserver to query.
32
+ #
33
+ # @return [String, nil]
34
+ # The address of the nameserver.
35
+ #
36
+ # @api public
37
+ #
38
+ def self.nameserver
39
+ @nameserver
40
+ end
41
+
42
+ #
43
+ # Sets the DNS nameserver to be queried.
44
+ #
45
+ # @param [IPAddr, String, nil]
46
+ # The address of the nameserver.
47
+ #
48
+ # @return [String, nil]
49
+ # The address of the new nameserver.
50
+ #
51
+ # @api public
52
+ #
53
+ def self.nameserver=(address)
54
+ @nameserver = if address
55
+ address.to_s
56
+ end
57
+ end
58
+
59
+ #
60
+ # Creates a DNS Resolver for the nameserver.
61
+ #
62
+ # @param [String, nil] nameserver
63
+ # Optional DNS nameserver to query.
64
+ #
65
+ # @return [Resolv, Resolv::DNS]
66
+ # The DNS Resolver.
67
+ #
68
+ # @api public
69
+ #
70
+ def dns_resolver(nameserver=DNS.nameserver)
71
+ if nameserver
72
+ Resolv::DNS.new(:nameserver => nameserver)
73
+ else
74
+ Resolv
75
+ end
76
+ end
77
+
78
+ #
79
+ # Looks up the address of a hostname.
80
+ #
81
+ # @param [String] hostname
82
+ # The hostname to lookup.
83
+ #
84
+ # @param [String, nil] nameserver
85
+ # Optional DNS nameserver to query.
86
+ #
87
+ # @return [String, nil]
88
+ # The address of the hostname.
89
+ #
90
+ # @api public
91
+ #
92
+ def dns_lookup(hostname,nameserver=DNS.nameserver)
93
+ resolv = dns_resolver(nameserver)
94
+
95
+ begin
96
+ resolv.getaddress(hostname.to_s).to_s
97
+ rescue Resolv::ResolvError
98
+ end
99
+ end
100
+
101
+ #
102
+ # Looks up all addresses of a hostname.
103
+ #
104
+ # @param [String] hostname
105
+ # The hostname to lookup.
106
+ #
107
+ # @param [String, nil] nameserver
108
+ # Optional DNS nameserver to query.
109
+ #
110
+ # @return [Array<String>]
111
+ # The addresses of the hostname.
112
+ #
113
+ # @api public
114
+ #
115
+ def dns_lookup_all(hostname,nameserver=DNS.nameserver)
116
+ dns_resolver(nameserver).getaddresses(hostname.to_s).map(&:to_s)
117
+ end
118
+
119
+ #
120
+ # Looks up the hostname of the address.
121
+ #
122
+ # @param [String] address
123
+ # The address to lookup.
124
+ #
125
+ # @param [String, nil] nameserver
126
+ # Optional DNS nameserver to query.
127
+ #
128
+ # @return [String, nil]
129
+ # The hostname of the address.
130
+ #
131
+ # @api public
132
+ #
133
+ def dns_reverse_lookup(address,nameserver=DNS.nameserver)
134
+ resolv = dns_resolver(nameserver)
135
+
136
+ begin
137
+ resolv.getname(address.to_s).to_s
138
+ rescue Resolv::ResolvError
139
+ end
140
+ end
141
+
142
+ #
143
+ # Looks up all hostnames associated with the address.
144
+ #
145
+ # @param [String] address
146
+ # The address to lookup.
147
+ #
148
+ # @param [String, nil] nameserver
149
+ # Optional DNS nameserver to query.
150
+ #
151
+ # @return [Array<String>]
152
+ # The hostnames of the address.
153
+ #
154
+ # @api public
155
+ #
156
+ def dns_reverse_lookup_all(address,nameserver=DNS.nameserver)
157
+ dns_resolver(nameserver).getnames(address.to_s).map(&:to_s)
158
+ end
159
+ end
160
+ end
161
+ end