ronin-support 0.4.0.rc2 → 0.4.0

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.
@@ -970,6 +970,41 @@ module Ronin
970
970
  http_post(options).body
971
971
  end
972
972
 
973
+ #
974
+ # Performs an HTTP PUT request.
975
+ #
976
+ # @param [Hash] options
977
+ # Additional options.
978
+ #
979
+ # @option options [String] :body
980
+ # The body for the request.
981
+ #
982
+ # @option options [Hash, String] :form_data
983
+ # The form data to send with the HTTP PUT request.
984
+ #
985
+ # @yield [response]
986
+ # If a block is given, it will be passed the response received from
987
+ # the request.
988
+ #
989
+ # @yieldparam [Net::HTTP::Response] response
990
+ # The HTTP response object.
991
+ #
992
+ # @return [Net::HTTP::Response]
993
+ # The response of the HTTP request.
994
+ #
995
+ # @see http_request
996
+ #
997
+ # @since 0.4.0
998
+ #
999
+ # @api public
1000
+ #
1001
+ def http_put(options={})
1002
+ response = http_request(options.merge(:method => :put))
1003
+
1004
+ yield response if block_given?
1005
+ return response
1006
+ end
1007
+
973
1008
  #
974
1009
  # Performs an HTTP Propfind request.
975
1010
  #
@@ -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/mixins/dns'
20
21
  require 'ronin/network/mixins/tcp'
21
22
  require 'ronin/network/mixins/udp'
22
23
  require 'ronin/network/mixins/smtp'
@@ -0,0 +1,55 @@
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 'ronin/network/mixins/mixin'
21
+ require 'ronin/network/dns'
22
+
23
+ module Ronin
24
+ module Network
25
+ module Mixins
26
+ #
27
+ # Adds DNS convenience methods and parameters to a class.
28
+ #
29
+ # Defines the following parameters:
30
+ #
31
+ # * `nameserver` (`String`) - DNS nameserver to query.
32
+ #
33
+ # @since 0.4.0
34
+ #
35
+ module DNS
36
+ include Mixin, Network::DNS
37
+
38
+ parameter :nameserver, :type => String,
39
+ :description => 'DNS nameserver'
40
+
41
+ protected
42
+
43
+ #
44
+ # The DNS Resolver to use.
45
+ #
46
+ # @see DNS#dns_resolver
47
+ #
48
+ def dns_resolver(nameserver=self.nameserver)
49
+ super(nameserver)
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -549,6 +549,41 @@ module Ronin
549
549
  return super(options,&block)
550
550
  end
551
551
 
552
+ #
553
+ # Performs an HTTP PUT request.
554
+ #
555
+ # @param [Hash] options
556
+ # Additional options.
557
+ #
558
+ # @option options [String] :body
559
+ # The body for the request.
560
+ #
561
+ # @option options [String] :post_data
562
+ # The `POSTDATA` to send with the HTTP PUT request.
563
+ #
564
+ # @yield [response]
565
+ # If a block is given, it will be passed the response received
566
+ # from the request.
567
+ #
568
+ # @yieldparam [Net::HTTP::Response] response
569
+ # The HTTP response object.
570
+ #
571
+ # @return [Net::HTTP::Response]
572
+ # The response of the HTTP request.
573
+ #
574
+ # @see #http_request
575
+ #
576
+ # @since 0.4.0
577
+ #
578
+ # @api public
579
+ #
580
+ def http_put(options={},&block)
581
+ options = http_merge_options(options)
582
+ print_info "HTTP PUT #{http_options_to_s(options)}"
583
+
584
+ return super(options,&block)
585
+ end
586
+
552
587
  #
553
588
  # Performs an HTTP Propfind request.
554
589
  #
@@ -26,6 +26,7 @@ module Ronin
26
26
  #
27
27
  module Support
28
28
  include UI::Output::Helpers
29
+ include Network::DNS
29
30
  include Network::TCP
30
31
  include Network::UDP
31
32
  include Network::SMTP
@@ -20,6 +20,6 @@
20
20
  module Ronin
21
21
  module Support
22
22
  # ronin-support version
23
- VERSION = '0.4.0.rc2'
23
+ VERSION = '0.4.0'
24
24
  end
25
25
  end
@@ -67,7 +67,7 @@ describe IPAddr do
67
67
 
68
68
  it "should extract collapsed IPv6 addresses" do
69
69
  addr = 'fe80::0204:61ff:fe9d:f156'
70
- text = ":: #{addr} ::"
70
+ text = "ipv6: #{addr}"
71
71
 
72
72
  IPAddr.extract(text,:ipv6).should == [addr]
73
73
  end
@@ -80,7 +80,7 @@ describe IPAddr do
80
80
  end
81
81
 
82
82
  it "should extract trailing IPv4 suffixes" do
83
- addr = 'fe80:0000:0000:0000:0204:61ff:fe9d:f156:222.1.1.1'
83
+ addr = '::ffff:192.0.2.128'
84
84
  text = "#{addr} 1.1.1.1"
85
85
 
86
86
  IPAddr.extract(text,:ipv6).should == [addr]
@@ -103,7 +103,7 @@ describe IPAddr do
103
103
  end
104
104
 
105
105
  it "should ignore non-IP addresses" do
106
- text = 'one :: two.three.'
106
+ text = 'one: two.three.'
107
107
 
108
108
  IPAddr.extract(text).should be_empty
109
109
  end
@@ -2,7 +2,31 @@ require 'spec_helper'
2
2
  require 'ronin/extensions/regexp'
3
3
 
4
4
  describe Regexp do
5
- describe Regexp::IPv4 do
5
+ describe "OCTET" do
6
+ subject { Regexp::OCTET }
7
+
8
+ it "should match 0 - 255" do
9
+ (0..255).all? { |n|
10
+ subject.match(n.to_s)[0] == n.to_s
11
+ }.should be_true
12
+ end
13
+
14
+ it "should not match numbers greater than 255" do
15
+ subject.match('256')[0].should == '25'
16
+ end
17
+ end
18
+
19
+ describe "MAC" do
20
+ subject { Regexp::MAC }
21
+
22
+ it "should match six hexadecimal bytes" do
23
+ mac = '12:34:56:78:9a:bc'
24
+
25
+ subject.match(mac)[0].should == mac
26
+ end
27
+ end
28
+
29
+ describe "IPv4" do
6
30
  subject { Regexp::IPv4 }
7
31
 
8
32
  it "should match valid addresses" do
@@ -23,6 +47,12 @@ describe Regexp do
23
47
  subject.match(ip)[0].should == ip
24
48
  end
25
49
 
50
+ it "should match addresses with netmasks" do
51
+ ip = '10.1.1.1/24'
52
+
53
+ subject.match(ip)[0].should == ip
54
+ end
55
+
26
56
  it "should not match addresses with octets > 255" do
27
57
  ip = '10.1.256.1'
28
58
 
@@ -35,4 +65,358 @@ describe Regexp do
35
65
  subject.match(ip).should be_nil
36
66
  end
37
67
  end
68
+
69
+ describe "IPv6" do
70
+ subject { Regexp::IPv6 }
71
+
72
+ it "should match valid IPv6 addresses" do
73
+ ip = '2001:db8:85a3:0:0:8a2e:370:7334'
74
+
75
+ subject.match(ip)[0].should == ip
76
+ end
77
+
78
+ it "should match IPv6 addresses with netmasks" do
79
+ ip = '2001:db8:1234::/48'
80
+
81
+ subject.match(ip)[0].should == ip
82
+ end
83
+
84
+ it "should match truncated IPv6 addresses" do
85
+ ip = '2001:db8:85a3::8a2e:370:7334'
86
+
87
+ subject.match(ip)[0].should == ip
88
+ end
89
+
90
+ it "should match IPv4-mapped IPv6 addresses" do
91
+ ip = '::ffff:192.0.2.128'
92
+
93
+ subject.match(ip)[0].should == ip
94
+ end
95
+ end
96
+
97
+ describe "IP" do
98
+ subject { Regexp::IP }
99
+
100
+ it "should match IPv4 addresses" do
101
+ ip = '10.1.1.1'
102
+
103
+ subject.match(ip)[0].should == ip
104
+ end
105
+
106
+ it "should match IPv6 addresses" do
107
+ ip = '2001:db8:85a3:0:0:8a2e:370:7334'
108
+
109
+ subject.match(ip)[0].should == ip
110
+ end
111
+ end
112
+
113
+ describe "HOST_NAME" do
114
+ subject { Regexp::HOST_NAME }
115
+
116
+ it "should match valid hostnames" do
117
+ hostname = 'www.google.com'
118
+
119
+ subject.match(hostname)[0].should == hostname
120
+ end
121
+
122
+ it "should not match hostnames without a TLD" do
123
+ subject.match('foo').should be_nil
124
+ end
125
+
126
+ it "should not match hostnames with unknown TLDs" do
127
+ subject.match('foo.zzz').should be_nil
128
+ end
129
+ end
130
+
131
+ describe "USER_NAME" do
132
+ subject { Regexp::USER_NAME }
133
+
134
+ it "should match valid user-names" do
135
+ username = 'alice1234'
136
+
137
+ subject.match(username)[0].should == username
138
+ end
139
+
140
+ it "should match user-names containing '_' characters" do
141
+ username = 'alice_1234'
142
+
143
+ subject.match(username)[0].should == username
144
+ end
145
+
146
+ it "should match user-names containing '.' characters" do
147
+ username = 'alice.1234'
148
+
149
+ subject.match(username)[0].should == username
150
+ end
151
+
152
+ it "should not match user-names beginning with numbers" do
153
+ subject.match('1234bob')[0].should == 'bob'
154
+ end
155
+
156
+ it "should not match user-names containing spaces" do
157
+ subject.match('alice eve')[0].should == 'alice'
158
+ end
159
+
160
+ it "should not match user-names containing other symbols" do
161
+ subject.match('alice^eve')[0].should == 'alice'
162
+ end
163
+ end
164
+
165
+ describe "EMAIL_ADDR" do
166
+ subject { Regexp::EMAIL_ADDR }
167
+
168
+ it "should match valid email addresses" do
169
+ email = 'alice@example.com'
170
+
171
+ subject.match(email)[0].should == email
172
+ end
173
+ end
174
+
175
+ describe "IDENTIFIER" do
176
+ subject { Regexp::IDENTIFIER }
177
+
178
+ it "should match Strings beginning with a '_' character" do
179
+ identifier = '_foo'
180
+
181
+ subject.match(identifier)[0].should == identifier
182
+ end
183
+
184
+ it "should match Strings ending with a '_' character" do
185
+ identifier = 'foo_'
186
+
187
+ subject.match(identifier)[0].should == identifier
188
+ end
189
+
190
+ it "should not match Strings beginning with numberic characters" do
191
+ subject.match('1234foo')[0].should == 'foo'
192
+ end
193
+
194
+ it "should not match Strings not containing any alpha characters" do
195
+ identifier = '_1234_'
196
+
197
+ subject.match(identifier).should be_nil
198
+ end
199
+ end
200
+
201
+ describe "FILE_EXT" do
202
+ subject { Regexp::FILE_EXT }
203
+
204
+ it "should match the '.' separator character" do
205
+ ext = '.txt'
206
+
207
+ subject.match(ext)[0].should == ext
208
+ end
209
+
210
+ it "should not allow '_' characters" do
211
+ subject.match('.foo_bar')[0].should == '.foo'
212
+ end
213
+
214
+ it "should not allow '-' characters" do
215
+ subject.match('.foo-bar')[0].should == '.foo'
216
+ end
217
+ end
218
+
219
+ describe "FILE_NAME" do
220
+ subject { Regexp::FILE_NAME }
221
+
222
+ it "should match file names" do
223
+ filename = 'foo_bar'
224
+
225
+ subject.match(filename)[0].should == filename
226
+ end
227
+
228
+ it "should match '\\' escapped characters" do
229
+ filename = 'foo\\ bar'
230
+
231
+ subject.match(filename)[0].should == filename
232
+ end
233
+ end
234
+
235
+ describe "FILE" do
236
+ subject { Regexp::FILE }
237
+
238
+ it "should match the filename and extension" do
239
+ filename = 'foo_bar.txt'
240
+
241
+ subject.match(filename)[0].should == filename
242
+ end
243
+ end
244
+
245
+ describe "DIRECTORY" do
246
+ subject { Regexp::DIRECTORY }
247
+
248
+ it "should match directory names" do
249
+ dir = 'foo_bar'
250
+
251
+ subject.match(dir)[0].should == dir
252
+ end
253
+
254
+ it "should match '.'" do
255
+ dir = '.'
256
+
257
+ subject.match(dir)[0].should == dir
258
+ end
259
+
260
+ it "should match '..'" do
261
+ dir = '..'
262
+
263
+ subject.match(dir)[0].should == dir
264
+ end
265
+ end
266
+
267
+ describe "RELATIVE_UNIX_PATH" do
268
+ subject { Regexp::RELATIVE_UNIX_PATH }
269
+
270
+ it "should match multiple directories" do
271
+ path = 'foo/./bar/../baz'
272
+
273
+ subject.match(path)[0].should == path
274
+ end
275
+ end
276
+
277
+ describe "ABSOLUTE_UNIX_PATH" do
278
+ subject { Regexp::ABSOLUTE_UNIX_PATH }
279
+
280
+ it "should match absolute paths" do
281
+ path = '/foo/bar/baz'
282
+
283
+ subject.match(path)[0].should == path
284
+ end
285
+
286
+ it "should match trailing '/' characters" do
287
+ path = '/foo/bar/baz/'
288
+
289
+ subject.match(path)[0].should == path
290
+ end
291
+
292
+ it "should not match relative directories" do
293
+ path = '/foo/./bar/../baz'
294
+
295
+ subject.match(path)[0].should == '/foo/'
296
+ end
297
+ end
298
+
299
+ describe "UNIX_PATH" do
300
+ subject { Regexp::UNIX_PATH }
301
+
302
+ it "should match relative paths" do
303
+ path = 'foo/./bar/../baz'
304
+
305
+ subject.match(path)[0].should == path
306
+ end
307
+
308
+ it "should match absolute paths" do
309
+ path = '/foo/bar/baz'
310
+
311
+ subject.match(path)[0].should == path
312
+ end
313
+ end
314
+
315
+ describe "RELATIVE_WINDOWS_PATH" do
316
+ subject { Regexp::RELATIVE_WINDOWS_PATH }
317
+
318
+ it "should match multiple directories" do
319
+ path = 'foo\\.\\bar\\..\\baz'
320
+
321
+ subject.match(path)[0].should == path
322
+ end
323
+ end
324
+
325
+ describe "ABSOLUTE_WINDOWS_PATH" do
326
+ subject { Regexp::ABSOLUTE_WINDOWS_PATH }
327
+
328
+ it "should match absolute paths" do
329
+ path = 'C:\\foo\\bar\\baz'
330
+
331
+ subject.match(path)[0].should == path
332
+ end
333
+
334
+ it "should match trailing '/' characters" do
335
+ path = 'C:\\foo\\bar\\baz\\'
336
+
337
+ subject.match(path)[0].should == path
338
+ end
339
+
340
+ it "should not match relative directories" do
341
+ path = 'C:\\foo\\.\\bar\\..\\baz'
342
+
343
+ subject.match(path)[0].should == 'C:\\foo\\'
344
+ end
345
+ end
346
+
347
+ describe "WINDOWS_PATH" do
348
+ subject { Regexp::WINDOWS_PATH }
349
+
350
+ it "should match relative paths" do
351
+ path = 'foo\\.\\bar\\..\\baz'
352
+
353
+ subject.match(path)[0].should == path
354
+ end
355
+
356
+ it "should match absolute paths" do
357
+ path = 'C:\\foo\\bar\\baz'
358
+
359
+ subject.match(path)[0].should == path
360
+ end
361
+ end
362
+
363
+ describe "RELATIVE_PATH" do
364
+ subject { Regexp::RELATIVE_PATH }
365
+
366
+ it "should match relative UNIX paths" do
367
+ path = 'foo/./bar/../baz'
368
+
369
+ subject.match(path)[0].should == path
370
+ end
371
+
372
+ it "should match relative Windows paths" do
373
+ path = 'foo\\.\\bar\\..\\baz'
374
+
375
+ subject.match(path)[0].should == path
376
+ end
377
+ end
378
+
379
+ describe "ABSOLUTE_PATH" do
380
+ subject { Regexp::ABSOLUTE_PATH }
381
+
382
+ it "should match absolute UNIX paths" do
383
+ path = '/foo/bar/baz'
384
+
385
+ subject.match(path)[0].should == path
386
+ end
387
+
388
+ it "should match absolute Windows paths" do
389
+ path = 'C:\\foo\\bar\\baz'
390
+
391
+ subject.match(path)[0].should == path
392
+ end
393
+ end
394
+
395
+ describe "PATH" do
396
+ subject { Regexp::PATH }
397
+
398
+ it "should match relative UNIX paths" do
399
+ path = 'foo/./bar/../baz'
400
+
401
+ subject.match(path)[0].should == path
402
+ end
403
+
404
+ it "should match absolute UNIX paths" do
405
+ path = '/foo/bar/baz'
406
+
407
+ subject.match(path)[0].should == path
408
+ end
409
+
410
+ it "should match relative Windows paths" do
411
+ path = 'foo\\.\\bar\\..\\baz'
412
+
413
+ subject.match(path)[0].should == path
414
+ end
415
+
416
+ it "should match absolute Windows paths" do
417
+ path = 'C:\\foo\\bar\\baz'
418
+
419
+ subject.match(path)[0].should == path
420
+ end
421
+ end
38
422
  end