ronin-support 0.4.1 → 0.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/ChangeLog.md +75 -32
  2. data/Gemfile +17 -18
  3. data/README.md +9 -10
  4. data/Rakefile +10 -2
  5. data/gemspec.yml +1 -1
  6. data/lib/ronin/binary.rb +21 -0
  7. data/lib/ronin/binary/hexdump.rb +20 -0
  8. data/lib/ronin/binary/hexdump/parser.rb +411 -0
  9. data/lib/ronin/binary/struct.rb +579 -0
  10. data/lib/ronin/binary/template.rb +437 -0
  11. data/lib/ronin/extensions/ip_addr.rb +17 -13
  12. data/lib/ronin/extensions/regexp.rb +45 -0
  13. data/lib/ronin/extensions/string.rb +3 -3
  14. data/lib/ronin/formatting/extensions/binary.rb +1 -0
  15. data/lib/ronin/formatting/extensions/binary/array.rb +63 -0
  16. data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
  17. data/lib/ronin/formatting/extensions/binary/file.rb +39 -6
  18. data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
  19. data/lib/ronin/formatting/extensions/binary/integer.rb +56 -43
  20. data/lib/ronin/formatting/extensions/binary/string.rb +75 -187
  21. data/lib/ronin/formatting/extensions/text/string.rb +61 -0
  22. data/lib/ronin/fuzzing/extensions/string.rb +21 -8
  23. data/lib/ronin/fuzzing/fuzzing.rb +19 -17
  24. data/lib/ronin/network.rb +2 -1
  25. data/lib/ronin/network/dns.rb +57 -15
  26. data/lib/ronin/network/extensions.rb +0 -1
  27. data/lib/ronin/network/ftp.rb +145 -0
  28. data/lib/ronin/network/http/http.rb +13 -14
  29. data/lib/ronin/network/imap.rb +11 -10
  30. data/lib/ronin/network/mixins.rb +1 -0
  31. data/lib/ronin/network/mixins/ftp.rb +155 -0
  32. data/lib/ronin/network/mixins/ssl.rb +1 -1
  33. data/lib/ronin/network/mixins/tcp.rb +39 -6
  34. data/lib/ronin/network/mixins/udp.rb +121 -1
  35. data/lib/ronin/network/mixins/unix.rb +279 -0
  36. data/lib/ronin/network/pop3.rb +5 -5
  37. data/lib/ronin/network/proxy.rb +578 -0
  38. data/lib/ronin/network/smtp/email.rb +1 -1
  39. data/lib/ronin/network/smtp/smtp.rb +7 -8
  40. data/lib/ronin/network/ssl.rb +1 -6
  41. data/lib/ronin/network/tcp.rb +2 -305
  42. data/lib/ronin/network/tcp/proxy.rb +377 -0
  43. data/lib/ronin/network/tcp/tcp.rb +435 -0
  44. data/lib/ronin/network/telnet.rb +27 -23
  45. data/lib/ronin/network/udp.rb +2 -266
  46. data/lib/ronin/network/udp/proxy.rb +169 -0
  47. data/lib/ronin/network/udp/udp.rb +442 -0
  48. data/lib/ronin/network/unix.rb +287 -0
  49. data/lib/ronin/path.rb +2 -2
  50. data/lib/ronin/spec/ui/output.rb +1 -7
  51. data/lib/ronin/support.rb +1 -0
  52. data/lib/ronin/support/inflector.rb +3 -7
  53. data/lib/ronin/support/support.rb +2 -1
  54. data/lib/ronin/support/version.rb +1 -1
  55. data/lib/ronin/ui/output/helpers.rb +13 -15
  56. data/lib/ronin/ui/output/output.rb +2 -2
  57. data/lib/ronin/ui/output/terminal/color.rb +10 -4
  58. data/lib/ronin/wordlist.rb +92 -17
  59. data/ronin-support.gemspec +38 -109
  60. data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
  61. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
  62. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
  63. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
  64. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
  65. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
  66. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
  67. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
  68. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
  69. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
  70. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
  71. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
  72. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
  73. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
  74. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
  75. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
  76. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
  77. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
  78. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
  79. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
  80. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
  81. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
  82. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
  83. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
  84. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
  85. data/spec/binary/hexdump/parser_spec.rb +302 -0
  86. data/spec/binary/struct_spec.rb +496 -0
  87. data/spec/binary/template_spec.rb +400 -0
  88. data/spec/extensions/ip_addr_spec.rb +58 -32
  89. data/spec/extensions/regexp_spec.rb +60 -0
  90. data/spec/extensions/string_spec.rb +1 -1
  91. data/spec/formatting/binary/array_spec.rb +22 -0
  92. data/spec/formatting/binary/base64_spec.rb +50 -0
  93. data/spec/formatting/binary/float_spec.rb +30 -0
  94. data/spec/formatting/binary/integer_spec.rb +54 -40
  95. data/spec/formatting/binary/string_spec.rb +69 -182
  96. data/spec/formatting/text/string_spec.rb +30 -0
  97. data/spec/network/dns_spec.rb +64 -0
  98. data/spec/network/ftp_spec.rb +65 -0
  99. data/spec/network/proxy_spec.rb +121 -0
  100. data/spec/network/shared/unix_server.rb +31 -0
  101. data/spec/network/tcp/proxy_spec.rb +116 -0
  102. data/spec/network/{tcp_spec.rb → tcp/tcp_spec.rb} +24 -1
  103. data/spec/network/telnet_spec.rb +67 -0
  104. data/spec/network/{udp_spec.rb → udp/udp_spec.rb} +24 -1
  105. data/spec/network/unix_spec.rb +183 -0
  106. data/spec/wordlist_spec.rb +74 -13
  107. metadata +129 -85
  108. data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
@@ -24,6 +24,14 @@ describe String do
24
24
  should respond_to(:insert_after)
25
25
  end
26
26
 
27
+ it "should provide String#escape" do
28
+ should respond_to(:escape)
29
+ end
30
+
31
+ it "should provide String#unescape" do
32
+ should respond_to(:unescape)
33
+ end
34
+
27
35
  describe "#format_bytes" do
28
36
  it "should format each byte in the String" do
29
37
  subject.format_bytes { |b|
@@ -129,4 +137,26 @@ describe String do
129
137
  subject.insert_after(/x/,'x').should == subject
130
138
  end
131
139
  end
140
+
141
+ describe "#unescape" do
142
+ it "should not unescape a normal String" do
143
+ "hello".unescape.should == "hello"
144
+ end
145
+
146
+ it "should unescape a hex String" do
147
+ "\\x68\\x65\\x6c\\x6c\\x6f\\x4e".unescape.should == "hello\x4e"
148
+ end
149
+
150
+ it "should unescape an octal String" do
151
+ "hello\012".unescape.should == "hello\n"
152
+ end
153
+
154
+ it "should unescape control characters" do
155
+ "hello\\n".unescape.should == "hello\n"
156
+ end
157
+
158
+ it "should unescape normal characters" do
159
+ "hell\\o".unescape.should == "hello"
160
+ end
161
+ end
132
162
  end
@@ -78,6 +78,28 @@ describe Network::DNS do
78
78
  it "should accept an additional nameserver argument" do
79
79
  subject.dns_lookup(hostname,server).should == address
80
80
  end
81
+
82
+ context "when given a block" do
83
+ it "should yield the resolved address" do
84
+ resolved_address = nil
85
+
86
+ subject.dns_lookup(hostname) do |address|
87
+ resolved_address = address
88
+ end
89
+
90
+ resolved_address.should == address
91
+ end
92
+
93
+ it "should not yield unresolved addresses" do
94
+ resolved_address = nil
95
+
96
+ subject.dns_lookup(bad_hostname) do |address|
97
+ resolved_address = address
98
+ end
99
+
100
+ resolved_address.should be_nil
101
+ end
102
+ end
81
103
  end
82
104
 
83
105
  describe "#dns_lookup_all" do
@@ -96,6 +118,16 @@ describe Network::DNS do
96
118
  it "should accept an additional nameserver argument" do
97
119
  subject.dns_lookup_all(hostname,server).should include(address)
98
120
  end
121
+
122
+ context "when given a block" do
123
+ it "should yield the resolved address" do
124
+ subject.enum_for(:dns_lookup,hostname).to_a.should == [address]
125
+ end
126
+
127
+ it "should not yield unresolved addresses" do
128
+ subject.enum_for(:dns_lookup,bad_hostname).to_a.should == []
129
+ end
130
+ end
99
131
  end
100
132
 
101
133
  describe "#dns_reverse_lookup" do
@@ -114,6 +146,28 @@ describe Network::DNS do
114
146
  it "should accept an additional nameserver argument" do
115
147
  subject.dns_reverse_lookup(address,server).should == reverse_hostname
116
148
  end
149
+
150
+ context "when given a block" do
151
+ it "should yield the resolved hostname" do
152
+ resolved_hostname = nil
153
+
154
+ subject.dns_reverse_lookup(address) do |hostname|
155
+ resolved_hostname = hostname
156
+ end
157
+
158
+ resolved_hostname.should == reverse_hostname
159
+ end
160
+
161
+ it "should not yield unresolved hostnames" do
162
+ resolved_hostname = nil
163
+
164
+ subject.dns_reverse_lookup(bad_address) do |hostname|
165
+ resolved_hostname = hostname
166
+ end
167
+
168
+ resolved_hostname.should be_nil
169
+ end
170
+ end
117
171
  end
118
172
 
119
173
  describe "#dns_reverse_lookup_all" do
@@ -132,6 +186,16 @@ describe Network::DNS do
132
186
  it "should accept an additional nameserver argument" do
133
187
  subject.dns_reverse_lookup_all(address,server).should include(reverse_hostname)
134
188
  end
189
+
190
+ context "when given a block" do
191
+ it "should yield the resolved hostnames" do
192
+ subject.enum_for(:dns_reverse_lookup_all,address).to_a.should == [reverse_hostname]
193
+ end
194
+
195
+ it "should not yield unresolved hostnames" do
196
+ subject.enum_for(:dns_reverse_lookup_all,bad_address).to_a.should == []
197
+ end
198
+ end
135
199
  end
136
200
  end
137
201
  end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/ftp'
3
+
4
+ describe Network::FTP do
5
+ describe "helpers", :network do
6
+ subject do
7
+ obj = Object.new
8
+ obj.extend described_class
9
+ obj
10
+ end
11
+
12
+ let(:host) { 'ftp.kernel.org' }
13
+
14
+ describe "#ftp_connect" do
15
+ it "should return a Net::FTP object" do
16
+ ftp = subject.ftp_connect(host)
17
+
18
+ ftp.should be_kind_of(Net::FTP)
19
+ ftp.close
20
+ end
21
+
22
+ it "should connect to an FTP service" do
23
+ ftp = subject.ftp_connect(host)
24
+
25
+ ftp.should_not be_closed
26
+ ftp.close
27
+ end
28
+
29
+ context "when given a block" do
30
+ it "should yield the new Net::FTP object" do
31
+ ftp = subject.ftp_connect(host) do |ftp|
32
+ ftp.should be_kind_of(Net::FTP)
33
+ end
34
+
35
+ ftp.close
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#ftp_session" do
41
+ it "should yield a new Net::FTP object" do
42
+ yielded_ftp = nil
43
+
44
+ subject.ftp_session(host) do |ftp|
45
+ yielded_ftp = ftp
46
+ end
47
+
48
+ yielded_ftp.should be_kind_of(Net::FTP)
49
+ end
50
+
51
+ it "should close the FTP session after yielding it" do
52
+ session = nil
53
+ was_open = nil
54
+
55
+ subject.ftp_session(host) do |ftp|
56
+ session = ftp
57
+ was_open = !ftp.closed?
58
+ end
59
+
60
+ was_open.should == true
61
+ session.should be_closed
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/proxy'
3
+
4
+ describe Network::Proxy do
5
+ let(:port) { 1337 }
6
+ let(:host) { '127.0.0.1' }
7
+ let(:server_host) { 'www.example.com' }
8
+ let(:server_port) { 80 }
9
+
10
+ let(:proxy) do
11
+ described_class.new(
12
+ :port => port,
13
+ :host => host,
14
+ :server => [server_host, server_port]
15
+ )
16
+ end
17
+
18
+ subject { proxy }
19
+
20
+ describe "#initialize" do
21
+ it "should default host to '0.0.0.0'" do
22
+ proxy = described_class.new(
23
+ :port => port,
24
+ :server => [server_host, server_port]
25
+ )
26
+
27
+ proxy.port.should == port
28
+ proxy.host.should == '0.0.0.0'
29
+ end
30
+
31
+ it "should allow setting both the host and port" do
32
+ proxy = described_class.new(
33
+ :port => port,
34
+ :host => host,
35
+ :server => [server_host, server_port]
36
+ )
37
+
38
+ proxy.port.should == port
39
+ proxy.host.should == host
40
+ end
41
+
42
+ it "should set the server_host and server_port" do
43
+ proxy = described_class.new(
44
+ :port => port,
45
+ :host => host,
46
+ :server => [server_host, server_port]
47
+ )
48
+
49
+ proxy.server_host.should == server_host
50
+ proxy.server_port.should == server_port
51
+ end
52
+ end
53
+
54
+ describe "#on_data" do
55
+ it "should call on_client_data" do
56
+ subject.should_receive(:on_client_data)
57
+
58
+ subject.on_data { |client,server,data| }
59
+ end
60
+
61
+ it "should call on_server_data" do
62
+ subject.should_receive(:on_server_data)
63
+
64
+ subject.on_data { |client,server,data| }
65
+ end
66
+ end
67
+
68
+ describe "actions" do
69
+ describe "#ignore!" do
70
+ it "should throw the :ignore action" do
71
+ lambda {
72
+ subject.ignore!
73
+ }.should throw_symbol(:action, :ignore)
74
+ end
75
+ end
76
+
77
+ describe "#close!" do
78
+ it "should throw the :close action" do
79
+ lambda {
80
+ subject.close!
81
+ }.should throw_symbol(:action, :close)
82
+ end
83
+ end
84
+
85
+ describe "#reset!" do
86
+ it "should throw the :reset action" do
87
+ lambda {
88
+ subject.reset!
89
+ }.should throw_symbol(:action, :reset)
90
+ end
91
+ end
92
+
93
+ describe "#stop!" do
94
+ it "should throw the :stop action" do
95
+ lambda {
96
+ subject.stop!
97
+ }.should throw_symbol(:action, :stop)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#to_s" do
103
+ subject { proxy.to_s }
104
+
105
+ it "should include the proxy host and port" do
106
+ subject.should include("#{host}:#{port}")
107
+ end
108
+
109
+ it "should include the server host and port" do
110
+ subject.should include("#{server_host}:#{server_port}")
111
+ end
112
+ end
113
+
114
+ describe "#inspect" do
115
+ subject { proxy.inspect }
116
+
117
+ it "should include the output of #to_s" do
118
+ subject.should include(proxy.to_s)
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,31 @@
1
+ require 'rspec'
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+ require 'socket'
6
+
7
+ shared_context "UNIX Server" do
8
+ def socket_path(name); File.join(Dir.tmpdir,name); end
9
+
10
+ let(:path) { socket_path('ronin_unix_server') }
11
+
12
+ before(:each) do
13
+ @server = UNIXServer.new(path)
14
+ @server_thread = Thread.new do
15
+ socket = @server.accept
16
+
17
+ begin
18
+ socket.puts socket.readline
19
+ ensure
20
+ socket.close
21
+ end
22
+ end
23
+ end
24
+
25
+ after(:each) do
26
+ @server_thread.kill
27
+ @server.close
28
+
29
+ FileUtils.rm(path)
30
+ end
31
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+ require 'ronin/network/tcp/proxy'
3
+
4
+ describe Network::TCP::Proxy, :network => true do
5
+ let(:port) { 1337 }
6
+ let(:host) { 'localhost' }
7
+ let(:server) { ['www.example.com', 80] }
8
+
9
+ before(:each) do
10
+ @proxy = described_class.new(
11
+ :port => port,
12
+ :host => host,
13
+ :server => server
14
+ )
15
+ @thread = Thread.new { @proxy.start }
16
+
17
+ sleep 0.1
18
+ end
19
+
20
+ describe "#on_client_connect" do
21
+ let(:injection) { "Client connected\r\n" }
22
+
23
+ before do
24
+ @proxy.on_client_connect do |client|
25
+ client.write(injection)
26
+ end
27
+
28
+ @socket = TCPSocket.new(host,port)
29
+ end
30
+
31
+ it "should trigger when a new client connects" do
32
+ @socket.readline.should == injection
33
+ end
34
+
35
+ after { @socket.close }
36
+ end
37
+
38
+ describe "#on_server_connect" do
39
+ let(:injection) { "Server connected\r\n" }
40
+
41
+ before do
42
+ @proxy.on_server_connect do |client,server|
43
+ client.write(injection)
44
+ end
45
+
46
+ @socket = TCPSocket.new(host,port)
47
+ end
48
+
49
+ it "should trigger after a new client connects" do
50
+ @socket.readline.should == injection
51
+ end
52
+
53
+ after { @socket.close }
54
+ end
55
+
56
+ describe "#on_client_data" do
57
+ before do
58
+ @proxy.on_client_data do |client,server,data|
59
+ data.gsub!(/HTTP\/1.1/,'HTTP/1.0')
60
+ end
61
+
62
+ @socket = TCPSocket.new(host,port)
63
+ end
64
+
65
+ it "should trigger when the client sends data" do
66
+ @socket.write("GET / HTTP/1.1\r\n\r\n")
67
+
68
+ @socket.readline.should == "HTTP/1.0 302 Found\r\n"
69
+ end
70
+
71
+ after { @socket.close }
72
+ end
73
+
74
+ describe "#on_server_data" do
75
+ before do
76
+ @proxy.on_server_data do |client,server,data|
77
+ data.gsub!(/Connection: \S+/,'Connection: keep-alive')
78
+ end
79
+
80
+ @socket = TCPSocket.new(host,port)
81
+ end
82
+
83
+ it "should trigger when the server sends data" do
84
+ @socket.write("GET / HTTP/1.0\r\n\r\n")
85
+
86
+ @socket.read.should include("Connection: keep-alive\r\n")
87
+ end
88
+
89
+ after { @socket.close }
90
+ end
91
+
92
+ describe "#on_server_disconnect" do
93
+ let(:injection) { "Haha Internet!\r\n" }
94
+
95
+ before do
96
+ @proxy.on_server_disconnect do |client,server|
97
+ client.write(injection)
98
+ end
99
+
100
+ @socket = TCPSocket.new(host,port)
101
+ end
102
+
103
+ it "should trigger when the server closes the connection" do
104
+ @socket.write("GET / HTTP/1.0\r\n\r\n")
105
+
106
+ @socket.read.end_with?(injection).should be_true
107
+ end
108
+
109
+ after { @socket.close }
110
+ end
111
+
112
+ after(:each) do
113
+ @thread.kill
114
+ @proxy.close
115
+ end
116
+ end