ronin-support 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +28 -0
  4. data/.ruby-version +1 -0
  5. data/.yardopts +1 -1
  6. data/ChangeLog.md +121 -33
  7. data/Gemfile +17 -18
  8. data/README.md +57 -33
  9. data/Rakefile +10 -3
  10. data/gemspec.yml +16 -7
  11. data/lib/ronin/binary.rb +21 -0
  12. data/lib/ronin/binary/hexdump.rb +20 -0
  13. data/lib/ronin/binary/hexdump/parser.rb +403 -0
  14. data/lib/ronin/binary/struct.rb +567 -0
  15. data/lib/ronin/binary/template.rb +454 -0
  16. data/lib/ronin/extensions.rb +5 -5
  17. data/lib/ronin/extensions/enumerable.rb +5 -5
  18. data/lib/ronin/extensions/file.rb +39 -33
  19. data/lib/ronin/extensions/ip_addr.rb +29 -31
  20. data/lib/ronin/extensions/kernel.rb +5 -5
  21. data/lib/ronin/extensions/meta.rb +5 -5
  22. data/lib/ronin/extensions/regexp.rb +50 -5
  23. data/lib/ronin/extensions/resolv.rb +7 -9
  24. data/lib/ronin/extensions/string.rb +10 -10
  25. data/lib/ronin/formatting.rb +5 -5
  26. data/lib/ronin/formatting/binary.rb +5 -5
  27. data/lib/ronin/formatting/digest.rb +5 -5
  28. data/lib/ronin/formatting/extensions.rb +5 -5
  29. data/lib/ronin/formatting/extensions/binary.rb +7 -5
  30. data/lib/ronin/formatting/extensions/binary/array.rb +61 -0
  31. data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
  32. data/lib/ronin/formatting/extensions/binary/file.rb +44 -11
  33. data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
  34. data/lib/ronin/formatting/extensions/binary/integer.rb +66 -50
  35. data/lib/ronin/formatting/extensions/binary/string.rb +81 -205
  36. data/lib/ronin/formatting/extensions/digest.rb +5 -5
  37. data/lib/ronin/formatting/extensions/digest/file.rb +5 -5
  38. data/lib/ronin/formatting/extensions/digest/string.rb +5 -5
  39. data/lib/ronin/formatting/extensions/html.rb +5 -5
  40. data/lib/ronin/formatting/extensions/html/integer.rb +9 -13
  41. data/lib/ronin/formatting/extensions/html/string.rb +31 -39
  42. data/lib/ronin/formatting/extensions/http.rb +5 -5
  43. data/lib/ronin/formatting/extensions/http/integer.rb +6 -6
  44. data/lib/ronin/formatting/extensions/http/string.rb +7 -7
  45. data/lib/ronin/formatting/extensions/sql.rb +5 -5
  46. data/lib/ronin/formatting/extensions/sql/string.rb +22 -24
  47. data/lib/ronin/formatting/extensions/text.rb +5 -5
  48. data/lib/ronin/formatting/extensions/text/array.rb +13 -11
  49. data/lib/ronin/formatting/extensions/text/string.rb +70 -13
  50. data/lib/ronin/formatting/html.rb +5 -5
  51. data/lib/ronin/formatting/http.rb +5 -5
  52. data/lib/ronin/formatting/sql.rb +5 -5
  53. data/lib/ronin/formatting/text.rb +5 -5
  54. data/lib/ronin/fuzzing.rb +5 -5
  55. data/lib/ronin/fuzzing/extensions.rb +5 -5
  56. data/lib/ronin/fuzzing/extensions/string.rb +42 -213
  57. data/lib/ronin/fuzzing/fuzzer.rb +110 -0
  58. data/lib/ronin/fuzzing/fuzzing.rb +33 -26
  59. data/lib/ronin/fuzzing/mutator.rb +161 -0
  60. data/lib/ronin/fuzzing/repeater.rb +81 -0
  61. data/lib/ronin/fuzzing/template.rb +133 -0
  62. data/lib/ronin/mixin.rb +2 -2
  63. data/lib/ronin/network.rb +7 -5
  64. data/lib/ronin/network/dns.rb +64 -24
  65. data/lib/ronin/network/esmtp.rb +5 -5
  66. data/lib/ronin/network/extensions.rb +5 -5
  67. data/lib/ronin/network/extensions/dns.rb +5 -5
  68. data/lib/ronin/network/extensions/dns/net.rb +5 -5
  69. data/lib/ronin/network/extensions/esmtp.rb +5 -5
  70. data/lib/ronin/network/extensions/esmtp/net.rb +5 -5
  71. data/lib/ronin/network/extensions/http.rb +5 -5
  72. data/lib/ronin/network/extensions/http/net.rb +5 -5
  73. data/lib/ronin/network/extensions/http/uri/http.rb +5 -5
  74. data/lib/ronin/network/extensions/imap.rb +5 -5
  75. data/lib/ronin/network/extensions/imap/net.rb +5 -5
  76. data/lib/ronin/network/extensions/pop3.rb +5 -5
  77. data/lib/ronin/network/extensions/pop3/net.rb +5 -5
  78. data/lib/ronin/network/extensions/smtp.rb +5 -5
  79. data/lib/ronin/network/extensions/smtp/net.rb +5 -5
  80. data/lib/ronin/network/extensions/ssl.rb +5 -5
  81. data/lib/ronin/network/extensions/ssl/net.rb +5 -5
  82. data/lib/ronin/network/extensions/tcp.rb +5 -5
  83. data/lib/ronin/network/extensions/tcp/net.rb +5 -5
  84. data/lib/ronin/network/extensions/telnet.rb +5 -5
  85. data/lib/ronin/network/extensions/telnet/net.rb +5 -5
  86. data/lib/ronin/network/extensions/udp.rb +5 -5
  87. data/lib/ronin/network/extensions/udp/net.rb +5 -5
  88. data/lib/ronin/network/ftp.rb +149 -0
  89. data/lib/ronin/network/http.rb +5 -5
  90. data/lib/ronin/network/http/exceptions.rb +5 -5
  91. data/lib/ronin/network/http/exceptions/unknown_request.rb +5 -5
  92. data/lib/ronin/network/http/http.rb +65 -70
  93. data/lib/ronin/network/http/proxy.rb +5 -5
  94. data/lib/ronin/network/imap.rb +16 -15
  95. data/lib/ronin/network/mixins.rb +6 -5
  96. data/lib/ronin/network/mixins/dns.rb +5 -5
  97. data/lib/ronin/network/mixins/esmtp.rb +5 -5
  98. data/lib/ronin/network/mixins/ftp.rb +155 -0
  99. data/lib/ronin/network/mixins/http.rb +58 -587
  100. data/lib/ronin/network/mixins/imap.rb +5 -5
  101. data/lib/ronin/network/mixins/mixin.rb +5 -5
  102. data/lib/ronin/network/mixins/pop3.rb +5 -5
  103. data/lib/ronin/network/mixins/smtp.rb +5 -5
  104. data/lib/ronin/network/mixins/ssl.rb +5 -5
  105. data/lib/ronin/network/mixins/tcp.rb +43 -10
  106. data/lib/ronin/network/mixins/telnet.rb +5 -5
  107. data/lib/ronin/network/mixins/udp.rb +126 -6
  108. data/lib/ronin/network/mixins/unix.rb +279 -0
  109. data/lib/ronin/network/network.rb +5 -5
  110. data/lib/ronin/network/pop3.rb +10 -10
  111. data/lib/ronin/network/proxy.rb +578 -0
  112. data/lib/ronin/network/smtp.rb +5 -5
  113. data/lib/ronin/network/smtp/email.rb +6 -6
  114. data/lib/ronin/network/smtp/smtp.rb +12 -13
  115. data/lib/ronin/network/ssl.rb +16 -17
  116. data/lib/ronin/network/tcp.rb +7 -310
  117. data/lib/ronin/network/tcp/proxy.rb +417 -0
  118. data/lib/ronin/network/tcp/tcp.rb +452 -0
  119. data/lib/ronin/network/telnet.rb +34 -28
  120. data/lib/ronin/network/udp.rb +7 -271
  121. data/lib/ronin/network/udp/proxy.rb +191 -0
  122. data/lib/ronin/network/udp/udp.rb +452 -0
  123. data/lib/ronin/network/unix.rb +286 -0
  124. data/lib/ronin/path.rb +35 -39
  125. data/lib/ronin/spec/ui/output.rb +6 -12
  126. data/lib/ronin/support.rb +6 -5
  127. data/lib/ronin/support/inflector.rb +8 -12
  128. data/lib/ronin/support/support.rb +7 -5
  129. data/lib/ronin/support/version.rb +6 -6
  130. data/lib/ronin/templates.rb +5 -5
  131. data/lib/ronin/templates/erb.rb +5 -5
  132. data/lib/ronin/templates/template.rb +5 -5
  133. data/lib/ronin/ui/output.rb +5 -5
  134. data/lib/ronin/ui/output/helpers.rb +42 -28
  135. data/lib/ronin/ui/output/output.rb +17 -21
  136. data/lib/ronin/ui/output/terminal.rb +5 -5
  137. data/lib/ronin/ui/output/terminal/color.rb +15 -9
  138. data/lib/ronin/ui/output/terminal/raw.rb +5 -5
  139. data/lib/ronin/ui/shell.rb +8 -11
  140. data/lib/ronin/wordlist.rb +110 -30
  141. data/ronin-support.gemspec +39 -109
  142. data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
  143. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
  144. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
  145. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
  146. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
  147. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
  148. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
  149. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
  150. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
  151. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
  152. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
  153. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
  154. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
  155. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
  156. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
  157. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
  158. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
  159. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
  160. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
  161. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
  162. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
  163. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
  164. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
  165. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
  166. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
  167. data/spec/binary/hexdump/parser_spec.rb +302 -0
  168. data/spec/binary/struct_spec.rb +496 -0
  169. data/spec/binary/template_spec.rb +416 -0
  170. data/spec/extensions/enumerable_spec.rb +4 -4
  171. data/spec/extensions/file_spec.rb +12 -14
  172. data/spec/extensions/ip_addr_spec.rb +76 -50
  173. data/spec/extensions/kernel_spec.rb +7 -7
  174. data/spec/extensions/regexp_spec.rb +119 -59
  175. data/spec/extensions/resolv_spec.rb +2 -2
  176. data/spec/extensions/string_spec.rb +31 -30
  177. data/spec/formatting/binary/array_spec.rb +26 -0
  178. data/spec/formatting/binary/base64_spec.rb +50 -0
  179. data/spec/formatting/binary/float_spec.rb +36 -0
  180. data/spec/formatting/binary/integer_spec.rb +76 -50
  181. data/spec/formatting/binary/string_spec.rb +91 -198
  182. data/spec/formatting/digest/string_spec.rb +5 -5
  183. data/spec/formatting/html/integer_spec.rb +6 -6
  184. data/spec/formatting/html/string_spec.rb +10 -10
  185. data/spec/formatting/http/integer_spec.rb +3 -3
  186. data/spec/formatting/http/string_spec.rb +5 -5
  187. data/spec/formatting/sql/string_spec.rb +21 -19
  188. data/spec/formatting/text/array_spec.rb +15 -15
  189. data/spec/formatting/text/string_spec.rb +58 -28
  190. data/spec/fuzzing/extensions/string_spec.rb +87 -0
  191. data/spec/fuzzing/fuzzer_spec.rb +109 -0
  192. data/spec/fuzzing/fuzzing_spec.rb +24 -0
  193. data/spec/fuzzing/mutator_spec.rb +112 -0
  194. data/spec/fuzzing/repeater_spec.rb +57 -0
  195. data/spec/fuzzing/template_spec.rb +54 -0
  196. data/spec/mixin_spec.rb +10 -12
  197. data/spec/network/dns_spec.rb +89 -23
  198. data/spec/network/ftp_spec.rb +81 -0
  199. data/spec/network/http/http_spec.rb +237 -144
  200. data/spec/network/http/proxy_spec.rb +37 -37
  201. data/spec/network/network_spec.rb +2 -2
  202. data/spec/network/proxy_spec.rb +121 -0
  203. data/spec/network/shared/unix_server.rb +31 -0
  204. data/spec/network/smtp/email_spec.rb +14 -14
  205. data/spec/network/ssl_spec.rb +53 -3
  206. data/spec/network/tcp/proxy_spec.rb +118 -0
  207. data/spec/network/tcp/tcp_spec.rb +316 -0
  208. data/spec/network/telnet_spec.rb +67 -0
  209. data/spec/network/udp/udp_spec.rb +298 -0
  210. data/spec/network/unix_spec.rb +182 -0
  211. data/spec/path_spec.rb +43 -18
  212. data/spec/spec_helper.rb +2 -3
  213. data/spec/support/inflector_spec.rb +4 -4
  214. data/spec/support_spec.rb +1 -1
  215. data/spec/templates/erb_spec.rb +3 -3
  216. data/spec/templates/template_spec.rb +10 -10
  217. data/spec/ui/shell_spec.rb +15 -15
  218. data/spec/wordlist_spec.rb +80 -19
  219. metadata +176 -121
  220. data/.gemtest +0 -0
  221. data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
  222. data/spec/fuzzing/string_spec.rb +0 -158
  223. data/spec/network/tcp_spec.rb +0 -247
  224. data/spec/network/udp_spec.rb +0 -248
@@ -7,47 +7,47 @@ describe IPAddr do
7
7
  it "should extract a single IPv4 address" do
8
8
  addr = '127.0.0.1'
9
9
 
10
- IPAddr.extract(addr,:ipv4).should == [addr]
10
+ expect(IPAddr.extract(addr,:ipv4)).to eq([addr])
11
11
  end
12
12
 
13
13
  it "should extract multiple IPv4 addresses" do
14
14
  addrs = %w[127.0.0.1 192.168.0.1]
15
15
  text = "#{addrs[0]} #{addrs[1]}"
16
16
 
17
- IPAddr.extract(text,:ipv4).should == addrs
17
+ expect(IPAddr.extract(text,:ipv4)).to eq(addrs)
18
18
  end
19
19
 
20
20
  it "should extract IPv4 addresses from text" do
21
21
  addr = '127.0.0.1'
22
22
  text = "ip (#{addr})"
23
23
 
24
- IPAddr.extract(text,:ipv4).should == [addr]
24
+ expect(IPAddr.extract(text,:ipv4)).to eq([addr])
25
25
  end
26
26
 
27
27
  it "should ignore leading periods" do
28
28
  addr = '127.0.0.1'
29
29
  text = ".#{addr}"
30
30
 
31
- IPAddr.extract(text,:ipv4).should == [addr]
31
+ expect(IPAddr.extract(text,:ipv4)).to eq([addr])
32
32
  end
33
33
 
34
34
  it "should ignore tailing periods" do
35
35
  addr = '127.0.0.1'
36
36
  text = "#{addr}."
37
37
 
38
- IPAddr.extract(text,:ipv4).should == [addr]
38
+ expect(IPAddr.extract(text,:ipv4)).to eq([addr])
39
39
  end
40
40
 
41
41
  it "should ignore less than 3 octet IPv4 addresses" do
42
42
  text = '127.0.0. 1'
43
43
 
44
- IPAddr.extract(text,:ipv4).should be_empty
44
+ expect(IPAddr.extract(text,:ipv4)).to be_empty
45
45
  end
46
46
 
47
47
  it "should ignore IPv4 addresses with more than 3 diget octets" do
48
48
  text = '127.1111.0.1'
49
49
 
50
- IPAddr.extract(text,:ipv4).should be_empty
50
+ expect(IPAddr.extract(text,:ipv4)).to be_empty
51
51
  end
52
52
  end
53
53
 
@@ -55,42 +55,42 @@ describe IPAddr do
55
55
  it "should extract a single IPv6 address" do
56
56
  addr = 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'
57
57
 
58
- IPAddr.extract(addr,:ipv6).should == [addr]
58
+ expect(IPAddr.extract(addr,:ipv6)).to eq([addr])
59
59
  end
60
60
 
61
61
  it "should extract multiple IPv6 addresses" do
62
62
  addrs = %w[::1 fe80:0000:0000:0000:0204:61ff:fe9d:f156]
63
63
  text = "#{addrs[0]} #{addrs[1]}"
64
64
 
65
- IPAddr.extract(text,:ipv6).should == addrs
65
+ expect(IPAddr.extract(text,:ipv6)).to eq(addrs)
66
66
  end
67
67
 
68
68
  it "should extract collapsed IPv6 addresses" do
69
69
  addr = 'fe80::0204:61ff:fe9d:f156'
70
70
  text = "ipv6: #{addr}"
71
71
 
72
- IPAddr.extract(text,:ipv6).should == [addr]
72
+ expect(IPAddr.extract(text,:ipv6)).to eq([addr])
73
73
  end
74
74
 
75
75
  it "should extract IPv6 addresses from text" do
76
76
  addr = 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'
77
77
  text = "hello #{addr} world"
78
78
 
79
- IPAddr.extract(text,:ipv6).should == [addr]
79
+ expect(IPAddr.extract(text,:ipv6)).to eq([addr])
80
80
  end
81
81
 
82
82
  it "should extract trailing IPv4 suffixes" do
83
83
  addr = '::ffff:192.0.2.128'
84
84
  text = "#{addr} 1.1.1.1"
85
85
 
86
- IPAddr.extract(text,:ipv6).should == [addr]
86
+ expect(IPAddr.extract(text,:ipv6)).to eq([addr])
87
87
  end
88
88
 
89
89
  it "should extract short-hand IPv6 addresses" do
90
90
  addr = '::f0:0d'
91
91
  text = "ipv6: #{addr}"
92
92
 
93
- IPAddr.extract(text,:ipv6).should == [addr]
93
+ expect(IPAddr.extract(text,:ipv6)).to eq([addr])
94
94
  end
95
95
  end
96
96
 
@@ -99,60 +99,86 @@ describe IPAddr do
99
99
  ipv6 = '::1'
100
100
  text = "ipv4: #{ipv4}, ipv6: #{ipv6}"
101
101
 
102
- IPAddr.extract(text).should == [ipv4, ipv6]
102
+ expect(IPAddr.extract(text)).to eq([ipv4, ipv6])
103
103
  end
104
104
 
105
105
  it "should ignore non-IP addresses" do
106
106
  text = 'one: two.three.'
107
107
 
108
- IPAddr.extract(text).should be_empty
108
+ expect(IPAddr.extract(text)).to be_empty
109
109
  end
110
110
  end
111
111
 
112
- context "CIDR addresses" do
113
- let(:fixed_addr) { IPAddr.new('10.1.1.2') }
114
- let(:class_c) { IPAddr.new('10.1.1.2/24') }
112
+ describe "each" do
113
+ context "CIDR addresses" do
114
+ let(:fixed_addr) { IPAddr.new('10.1.1.2') }
115
+ let(:class_c) { IPAddr.new('10.1.1.2/24') }
115
116
 
116
- it "should only iterate over one IP address for an address" do
117
- addresses = fixed_addr.map { |ip| IPAddr.new(ip) }
117
+ it "should only iterate over one IP address for an address" do
118
+ addresses = fixed_addr.map { |ip| IPAddr.new(ip) }
118
119
 
119
- addresses.length.should == 1
120
- fixed_addr.should include(addresses.first)
121
- end
120
+ expect(addresses.length).to eq(1)
121
+ expect(fixed_addr).to include(addresses.first)
122
+ end
122
123
 
123
- it "should iterate over all IP addresses contained within the IP range" do
124
- class_c.each do |ip|
125
- class_c.should include(IPAddr.new(ip))
124
+ it "should iterate over all IP addresses contained within the IP range" do
125
+ class_c.each do |ip|
126
+ expect(class_c).to include(IPAddr.new(ip))
127
+ end
126
128
  end
127
- end
128
129
 
129
- it "should return an Enumerator when no block is given" do
130
- class_c.each.all? { |ip|
131
- class_c.include?(IPAddr.new(ip))
132
- }.should == true
130
+ it "should return an Enumerator when no block is given" do
131
+ expect(class_c.each.all? { |ip|
132
+ class_c.include?(IPAddr.new(ip))
133
+ }).to be(true)
134
+ end
133
135
  end
134
- end
135
136
 
136
- context "globbed addresses" do
137
- let(:ipv4_range) { '10.1.1-5.1' }
138
- let(:ipv6_range) { '::ff::02-0a::c3' }
137
+ context "globbed addresses" do
138
+ let(:ipv4_range) { '10.1.1-5.1' }
139
+ let(:ipv6_range) { '::ff::02-0a::c3' }
140
+
141
+ it "should expand '*' ranges" do
142
+ octets = IPAddr.each("10.1.1.*").map { |ip| ip.split('.',4).last }
139
143
 
140
- it "should iterate over all IP addresses in an IPv4 range" do
141
- IPAddr.each(ipv4_range) do |ip|
142
- ip.should =~ /^10\.1\.[1-5]\.1$/
144
+ expect(octets).to eq(('1'..'254').to_a)
143
145
  end
144
- end
145
146
 
146
- it "should iterate over all IP addresses in an IPv6 range" do
147
- IPAddr.each(ipv6_range) do |ip|
148
- ip.should =~ /^::ff::0[2-9a]::c3$/
147
+ it "should expend 'i-j' ranges" do
148
+ octets = IPAddr.each("10.1.1.10-20").map { |ip| ip.split('.',4).last }
149
+
150
+ expect(octets).to eq(('10'..'20').to_a)
149
151
  end
150
- end
151
152
 
152
- it "should return an Enumerator when no block is given" do
153
- ips = IPAddr.each(ipv4_range)
154
-
155
- ips.all? { |ip| ip =~ /^10\.1\.[1-5]\.1$/ }.should == true
153
+ it "should expand 'i,j,k' ranges" do
154
+ octets = IPAddr.each("10.1.1.1,2,3").map { |ip| ip.split('.',4).last }
155
+
156
+ expect(octets).to eq(['1', '2', '3'])
157
+ end
158
+
159
+ it "should expand combination 'i,j-k' ranges" do
160
+ octets = IPAddr.each("10.1.1.1,3-4").map { |ip| ip.split('.',4).last }
161
+
162
+ expect(octets).to eq(['1', '3', '4'])
163
+ end
164
+
165
+ it "should iterate over all IP addresses in an IPv4 range" do
166
+ IPAddr.each(ipv4_range) do |ip|
167
+ expect(ip).to match(/^10\.1\.[1-5]\.1$/)
168
+ end
169
+ end
170
+
171
+ it "should iterate over all IP addresses in an IPv6 range" do
172
+ IPAddr.each(ipv6_range) do |ip|
173
+ expect(ip).to match(/^::ff::0[2-9a]::c3$/)
174
+ end
175
+ end
176
+
177
+ it "should return an Enumerator when no block is given" do
178
+ ips = IPAddr.each(ipv4_range)
179
+
180
+ expect(ips.all? { |ip| ip =~ /^10\.1\.[1-5]\.1$/ }).to be(true)
181
+ end
156
182
  end
157
183
  end
158
184
 
@@ -163,15 +189,15 @@ describe IPAddr do
163
189
  let(:nameserver) { '4.2.2.1' }
164
190
 
165
191
  it "should lookup the host-name for an IP" do
166
- ip.lookup.should include('localhost')
192
+ expect(ip.lookup).to include('localhost')
167
193
  end
168
194
 
169
195
  it "may lookup host-names via other nameservers" do
170
- ip.lookup(nameserver).should be_empty
196
+ expect(ip.lookup(nameserver)).to be_empty
171
197
  end
172
198
 
173
199
  it "should return an empty Array for unknown IP addresses" do
174
- bad_ip.lookup.should be_empty
200
+ expect(bad_ip.lookup).to be_empty
175
201
  end
176
202
  end
177
203
  end
@@ -3,28 +3,28 @@ require 'ronin/extensions/kernel'
3
3
 
4
4
  describe Kernel do
5
5
  it "should provide Kernel#try" do
6
- Kernel.should respond_to('try')
6
+ expect(Kernel).to respond_to('try')
7
7
  end
8
8
 
9
9
  describe "#try" do
10
10
  it "should return the result of the block if nothing is raised" do
11
- try { 2 + 2 }.should == 4
11
+ expect(try { 2 + 2 }).to eq(4)
12
12
  end
13
13
 
14
14
  it "should return nil if an exception is raised" do
15
- try { 2 + 'a' }.should be_nil
15
+ expect(try { 2 + 'a' }).to be_nil
16
16
  end
17
17
 
18
18
  it "should rescue RuntimeError exceptions" do
19
- lambda {
19
+ expect {
20
20
  try { raise(RuntimeError,"something happened",caller) }
21
- }.should_not raise_error(RuntimeError)
21
+ }.not_to raise_error
22
22
  end
23
23
 
24
24
  it "should rescue StandardError exceptions" do
25
- lambda {
25
+ expect {
26
26
  try { raise(StandardError,"not allowed to do that",caller) }
27
- }.should_not raise_error(StandardError)
27
+ }.not_to raise_error
28
28
  end
29
29
  end
30
30
  end
@@ -2,17 +2,49 @@ require 'spec_helper'
2
2
  require 'ronin/extensions/regexp'
3
3
 
4
4
  describe Regexp do
5
+ describe "WORD" do
6
+ let(:word) { 'dog' }
7
+
8
+ subject { Regexp::WORD }
9
+
10
+ it "should not match single letters" do
11
+ expect(subject.match('A')).to be_nil
12
+ end
13
+
14
+ it "should not match numeric letters" do
15
+ expect(subject.match("123#{word}123")[0]).to eq(word)
16
+ end
17
+
18
+ it "should not include ending periods" do
19
+ expect(subject.match("#{word}.")[0]).to eq(word)
20
+ end
21
+
22
+ it "should not include leading punctuation" do
23
+ expect(subject.match("'#{word}")[0]).to eq(word)
24
+ end
25
+
26
+ it "should not include tailing punctuation" do
27
+ expect(subject.match("#{word}'")[0]).to eq(word)
28
+ end
29
+
30
+ it "should include punctuation in the middle of the word" do
31
+ name = "O'Brian"
32
+
33
+ expect(subject.match(name)[0]).to eq(name)
34
+ end
35
+ end
36
+
5
37
  describe "OCTET" do
6
38
  subject { Regexp::OCTET }
7
39
 
8
40
  it "should match 0 - 255" do
9
- (0..255).all? { |n|
41
+ expect((0..255).all? { |n|
10
42
  subject.match(n.to_s)[0] == n.to_s
11
- }.should be_true
43
+ }).to be(true)
12
44
  end
13
45
 
14
46
  it "should not match numbers greater than 255" do
15
- subject.match('256')[0].should == '25'
47
+ expect(subject.match('256')[0]).to eq('25')
16
48
  end
17
49
  end
18
50
 
@@ -22,7 +54,7 @@ describe Regexp do
22
54
  it "should match six hexadecimal bytes" do
23
55
  mac = '12:34:56:78:9a:bc'
24
56
 
25
- subject.match(mac)[0].should == mac
57
+ expect(subject.match(mac)[0]).to eq(mac)
26
58
  end
27
59
  end
28
60
 
@@ -32,37 +64,37 @@ describe Regexp do
32
64
  it "should match valid addresses" do
33
65
  ip = '127.0.0.1'
34
66
 
35
- subject.match(ip)[0].should == ip
67
+ expect(subject.match(ip)[0]).to eq(ip)
36
68
  end
37
69
 
38
70
  it "should match the Any address" do
39
71
  ip = '0.0.0.0'
40
72
 
41
- subject.match(ip)[0].should == ip
73
+ expect(subject.match(ip)[0]).to eq(ip)
42
74
  end
43
75
 
44
76
  it "should match the broadcast address" do
45
77
  ip = '255.255.255.255'
46
78
 
47
- subject.match(ip)[0].should == ip
79
+ expect(subject.match(ip)[0]).to eq(ip)
48
80
  end
49
81
 
50
82
  it "should match addresses with netmasks" do
51
83
  ip = '10.1.1.1/24'
52
84
 
53
- subject.match(ip)[0].should == ip
85
+ expect(subject.match(ip)[0]).to eq(ip)
54
86
  end
55
87
 
56
88
  it "should not match addresses with octets > 255" do
57
89
  ip = '10.1.256.1'
58
90
 
59
- subject.match(ip).should be_nil
91
+ expect(subject.match(ip)).to be_nil
60
92
  end
61
93
 
62
94
  it "should not match addresses with more than three digits per octet" do
63
95
  ip = '10.1111.1.1'
64
96
 
65
- subject.match(ip).should be_nil
97
+ expect(subject.match(ip)).to be_nil
66
98
  end
67
99
  end
68
100
 
@@ -72,25 +104,25 @@ describe Regexp do
72
104
  it "should match valid IPv6 addresses" do
73
105
  ip = '2001:db8:85a3:0:0:8a2e:370:7334'
74
106
 
75
- subject.match(ip)[0].should == ip
107
+ expect(subject.match(ip)[0]).to eq(ip)
76
108
  end
77
109
 
78
110
  it "should match IPv6 addresses with netmasks" do
79
111
  ip = '2001:db8:1234::/48'
80
112
 
81
- subject.match(ip)[0].should == ip
113
+ expect(subject.match(ip)[0]).to eq(ip)
82
114
  end
83
115
 
84
116
  it "should match truncated IPv6 addresses" do
85
117
  ip = '2001:db8:85a3::8a2e:370:7334'
86
118
 
87
- subject.match(ip)[0].should == ip
119
+ expect(subject.match(ip)[0]).to eq(ip)
88
120
  end
89
121
 
90
122
  it "should match IPv4-mapped IPv6 addresses" do
91
123
  ip = '::ffff:192.0.2.128'
92
124
 
93
- subject.match(ip)[0].should == ip
125
+ expect(subject.match(ip)[0]).to eq(ip)
94
126
  end
95
127
  end
96
128
 
@@ -100,13 +132,13 @@ describe Regexp do
100
132
  it "should match IPv4 addresses" do
101
133
  ip = '10.1.1.1'
102
134
 
103
- subject.match(ip)[0].should == ip
135
+ expect(subject.match(ip)[0]).to eq(ip)
104
136
  end
105
137
 
106
138
  it "should match IPv6 addresses" do
107
139
  ip = '2001:db8:85a3:0:0:8a2e:370:7334'
108
140
 
109
- subject.match(ip)[0].should == ip
141
+ expect(subject.match(ip)[0]).to eq(ip)
110
142
  end
111
143
  end
112
144
 
@@ -116,15 +148,15 @@ describe Regexp do
116
148
  it "should match valid hostnames" do
117
149
  hostname = 'www.google.com'
118
150
 
119
- subject.match(hostname)[0].should == hostname
151
+ expect(subject.match(hostname)[0]).to eq(hostname)
120
152
  end
121
153
 
122
154
  it "should not match hostnames without a TLD" do
123
- subject.match('foo').should be_nil
155
+ expect(subject.match('foo')).to be_nil
124
156
  end
125
157
 
126
158
  it "should not match hostnames with unknown TLDs" do
127
- subject.match('foo.zzz').should be_nil
159
+ expect(subject.match('foo.zzz')).to be_nil
128
160
  end
129
161
  end
130
162
 
@@ -134,31 +166,31 @@ describe Regexp do
134
166
  it "should match valid user-names" do
135
167
  username = 'alice1234'
136
168
 
137
- subject.match(username)[0].should == username
169
+ expect(subject.match(username)[0]).to eq(username)
138
170
  end
139
171
 
140
172
  it "should match user-names containing '_' characters" do
141
173
  username = 'alice_1234'
142
174
 
143
- subject.match(username)[0].should == username
175
+ expect(subject.match(username)[0]).to eq(username)
144
176
  end
145
177
 
146
178
  it "should match user-names containing '.' characters" do
147
179
  username = 'alice.1234'
148
180
 
149
- subject.match(username)[0].should == username
181
+ expect(subject.match(username)[0]).to eq(username)
150
182
  end
151
183
 
152
184
  it "should not match user-names beginning with numbers" do
153
- subject.match('1234bob')[0].should == 'bob'
185
+ expect(subject.match('1234bob')[0]).to eq('bob')
154
186
  end
155
187
 
156
188
  it "should not match user-names containing spaces" do
157
- subject.match('alice eve')[0].should == 'alice'
189
+ expect(subject.match('alice eve')[0]).to eq('alice')
158
190
  end
159
191
 
160
192
  it "should not match user-names containing other symbols" do
161
- subject.match('alice^eve')[0].should == 'alice'
193
+ expect(subject.match('alice^eve')[0]).to eq('alice')
162
194
  end
163
195
  end
164
196
 
@@ -168,7 +200,35 @@ describe Regexp do
168
200
  it "should match valid email addresses" do
169
201
  email = 'alice@example.com'
170
202
 
171
- subject.match(email)[0].should == email
203
+ expect(subject.match(email)[0]).to eq(email)
204
+ end
205
+ end
206
+
207
+ describe "PHONE_NUMBER" do
208
+ subject { Regexp::PHONE_NUMBER }
209
+
210
+ it "should match 111-2222" do
211
+ number = '111-2222'
212
+
213
+ expect(subject.match(number)[0]).to eq(number)
214
+ end
215
+
216
+ it "should match 111-2222x9" do
217
+ number = '111-2222x9'
218
+
219
+ expect(subject.match(number)[0]).to eq(number)
220
+ end
221
+
222
+ it "should match 800-111-2222" do
223
+ number = '800-111-2222'
224
+
225
+ expect(subject.match(number)[0]).to eq(number)
226
+ end
227
+
228
+ it "should match 1-800-111-2222" do
229
+ number = '1-800-111-2222'
230
+
231
+ expect(subject.match(number)[0]).to eq(number)
172
232
  end
173
233
  end
174
234
 
@@ -178,23 +238,23 @@ describe Regexp do
178
238
  it "should match Strings beginning with a '_' character" do
179
239
  identifier = '_foo'
180
240
 
181
- subject.match(identifier)[0].should == identifier
241
+ expect(subject.match(identifier)[0]).to eq(identifier)
182
242
  end
183
243
 
184
244
  it "should match Strings ending with a '_' character" do
185
245
  identifier = 'foo_'
186
246
 
187
- subject.match(identifier)[0].should == identifier
247
+ expect(subject.match(identifier)[0]).to eq(identifier)
188
248
  end
189
249
 
190
250
  it "should not match Strings beginning with numberic characters" do
191
- subject.match('1234foo')[0].should == 'foo'
251
+ expect(subject.match('1234foo')[0]).to eq('foo')
192
252
  end
193
253
 
194
254
  it "should not match Strings not containing any alpha characters" do
195
255
  identifier = '_1234_'
196
256
 
197
- subject.match(identifier).should be_nil
257
+ expect(subject.match(identifier)).to be_nil
198
258
  end
199
259
  end
200
260
 
@@ -204,15 +264,15 @@ describe Regexp do
204
264
  it "should match the '.' separator character" do
205
265
  ext = '.txt'
206
266
 
207
- subject.match(ext)[0].should == ext
267
+ expect(subject.match(ext)[0]).to eq(ext)
208
268
  end
209
269
 
210
270
  it "should not allow '_' characters" do
211
- subject.match('.foo_bar')[0].should == '.foo'
271
+ expect(subject.match('.foo_bar')[0]).to eq('.foo')
212
272
  end
213
273
 
214
274
  it "should not allow '-' characters" do
215
- subject.match('.foo-bar')[0].should == '.foo'
275
+ expect(subject.match('.foo-bar')[0]).to eq('.foo')
216
276
  end
217
277
  end
218
278
 
@@ -222,13 +282,13 @@ describe Regexp do
222
282
  it "should match file names" do
223
283
  filename = 'foo_bar'
224
284
 
225
- subject.match(filename)[0].should == filename
285
+ expect(subject.match(filename)[0]).to eq(filename)
226
286
  end
227
287
 
228
288
  it "should match '\\' escapped characters" do
229
289
  filename = 'foo\\ bar'
230
290
 
231
- subject.match(filename)[0].should == filename
291
+ expect(subject.match(filename)[0]).to eq(filename)
232
292
  end
233
293
  end
234
294
 
@@ -238,7 +298,7 @@ describe Regexp do
238
298
  it "should match the filename and extension" do
239
299
  filename = 'foo_bar.txt'
240
300
 
241
- subject.match(filename)[0].should == filename
301
+ expect(subject.match(filename)[0]).to eq(filename)
242
302
  end
243
303
  end
244
304
 
@@ -248,19 +308,19 @@ describe Regexp do
248
308
  it "should match directory names" do
249
309
  dir = 'foo_bar'
250
310
 
251
- subject.match(dir)[0].should == dir
311
+ expect(subject.match(dir)[0]).to eq(dir)
252
312
  end
253
313
 
254
314
  it "should match '.'" do
255
315
  dir = '.'
256
316
 
257
- subject.match(dir)[0].should == dir
317
+ expect(subject.match(dir)[0]).to eq(dir)
258
318
  end
259
319
 
260
320
  it "should match '..'" do
261
321
  dir = '..'
262
322
 
263
- subject.match(dir)[0].should == dir
323
+ expect(subject.match(dir)[0]).to eq(dir)
264
324
  end
265
325
  end
266
326
 
@@ -270,7 +330,7 @@ describe Regexp do
270
330
  it "should match multiple directories" do
271
331
  path = 'foo/./bar/../baz'
272
332
 
273
- subject.match(path)[0].should == path
333
+ expect(subject.match(path)[0]).to eq(path)
274
334
  end
275
335
  end
276
336
 
@@ -280,19 +340,19 @@ describe Regexp do
280
340
  it "should match absolute paths" do
281
341
  path = '/foo/bar/baz'
282
342
 
283
- subject.match(path)[0].should == path
343
+ expect(subject.match(path)[0]).to eq(path)
284
344
  end
285
345
 
286
346
  it "should match trailing '/' characters" do
287
347
  path = '/foo/bar/baz/'
288
348
 
289
- subject.match(path)[0].should == path
349
+ expect(subject.match(path)[0]).to eq(path)
290
350
  end
291
351
 
292
352
  it "should not match relative directories" do
293
353
  path = '/foo/./bar/../baz'
294
354
 
295
- subject.match(path)[0].should == '/foo/'
355
+ expect(subject.match(path)[0]).to eq('/foo/')
296
356
  end
297
357
  end
298
358
 
@@ -302,13 +362,13 @@ describe Regexp do
302
362
  it "should match relative paths" do
303
363
  path = 'foo/./bar/../baz'
304
364
 
305
- subject.match(path)[0].should == path
365
+ expect(subject.match(path)[0]).to eq(path)
306
366
  end
307
367
 
308
368
  it "should match absolute paths" do
309
369
  path = '/foo/bar/baz'
310
370
 
311
- subject.match(path)[0].should == path
371
+ expect(subject.match(path)[0]).to eq(path)
312
372
  end
313
373
  end
314
374
 
@@ -318,7 +378,7 @@ describe Regexp do
318
378
  it "should match multiple directories" do
319
379
  path = 'foo\\.\\bar\\..\\baz'
320
380
 
321
- subject.match(path)[0].should == path
381
+ expect(subject.match(path)[0]).to eq(path)
322
382
  end
323
383
  end
324
384
 
@@ -328,19 +388,19 @@ describe Regexp do
328
388
  it "should match absolute paths" do
329
389
  path = 'C:\\foo\\bar\\baz'
330
390
 
331
- subject.match(path)[0].should == path
391
+ expect(subject.match(path)[0]).to eq(path)
332
392
  end
333
393
 
334
394
  it "should match trailing '/' characters" do
335
395
  path = 'C:\\foo\\bar\\baz\\'
336
396
 
337
- subject.match(path)[0].should == path
397
+ expect(subject.match(path)[0]).to eq(path)
338
398
  end
339
399
 
340
400
  it "should not match relative directories" do
341
401
  path = 'C:\\foo\\.\\bar\\..\\baz'
342
402
 
343
- subject.match(path)[0].should == 'C:\\foo\\'
403
+ expect(subject.match(path)[0]).to eq('C:\\foo\\')
344
404
  end
345
405
  end
346
406
 
@@ -350,13 +410,13 @@ describe Regexp do
350
410
  it "should match relative paths" do
351
411
  path = 'foo\\.\\bar\\..\\baz'
352
412
 
353
- subject.match(path)[0].should == path
413
+ expect(subject.match(path)[0]).to eq(path)
354
414
  end
355
415
 
356
416
  it "should match absolute paths" do
357
417
  path = 'C:\\foo\\bar\\baz'
358
418
 
359
- subject.match(path)[0].should == path
419
+ expect(subject.match(path)[0]).to eq(path)
360
420
  end
361
421
  end
362
422
 
@@ -366,13 +426,13 @@ describe Regexp do
366
426
  it "should match relative UNIX paths" do
367
427
  path = 'foo/./bar/../baz'
368
428
 
369
- subject.match(path)[0].should == path
429
+ expect(subject.match(path)[0]).to eq(path)
370
430
  end
371
431
 
372
432
  it "should match relative Windows paths" do
373
433
  path = 'foo\\.\\bar\\..\\baz'
374
434
 
375
- subject.match(path)[0].should == path
435
+ expect(subject.match(path)[0]).to eq(path)
376
436
  end
377
437
  end
378
438
 
@@ -382,13 +442,13 @@ describe Regexp do
382
442
  it "should match absolute UNIX paths" do
383
443
  path = '/foo/bar/baz'
384
444
 
385
- subject.match(path)[0].should == path
445
+ expect(subject.match(path)[0]).to eq(path)
386
446
  end
387
447
 
388
448
  it "should match absolute Windows paths" do
389
449
  path = 'C:\\foo\\bar\\baz'
390
450
 
391
- subject.match(path)[0].should == path
451
+ expect(subject.match(path)[0]).to eq(path)
392
452
  end
393
453
  end
394
454
 
@@ -398,25 +458,25 @@ describe Regexp do
398
458
  it "should match relative UNIX paths" do
399
459
  path = 'foo/./bar/../baz'
400
460
 
401
- subject.match(path)[0].should == path
461
+ expect(subject.match(path)[0]).to eq(path)
402
462
  end
403
463
 
404
464
  it "should match absolute UNIX paths" do
405
465
  path = '/foo/bar/baz'
406
466
 
407
- subject.match(path)[0].should == path
467
+ expect(subject.match(path)[0]).to eq(path)
408
468
  end
409
469
 
410
470
  it "should match relative Windows paths" do
411
471
  path = 'foo\\.\\bar\\..\\baz'
412
472
 
413
- subject.match(path)[0].should == path
473
+ expect(subject.match(path)[0]).to eq(path)
414
474
  end
415
475
 
416
476
  it "should match absolute Windows paths" do
417
477
  path = 'C:\\foo\\bar\\baz'
418
478
 
419
- subject.match(path)[0].should == path
479
+ expect(subject.match(path)[0]).to eq(path)
420
480
  end
421
481
  end
422
482
  end