CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/proto/proxy/socks5/packet_spec.rb
Views: 11791
1
# -*- coding:binary -*-
2
3
RSpec.describe Rex::Proto::Proxy::Socks5::Packet do
4
Socks5 = Rex::Proto::Proxy::Socks5
5
6
describe "#address" do
7
it "should parse an IPv4 address" do
8
packet = Socks5::Packet.read("\x05\x02\x00\x01\x7f\x00\x00\x01\x00\x00")
9
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV4)
10
expect(packet.address).to eq('127.0.0.1')
11
end
12
13
it "should parse an IPv6 address" do
14
packet = Socks5::Packet.read("\x05\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00")
15
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV6)
16
expect(packet.address).to eq('::1')
17
end
18
19
it "should parse a domain name" do
20
packet = Socks5::Packet.read("\x05\x02\x00\x03\x12www.metasploit.com\x00\x00")
21
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_DOMAINNAME)
22
expect(packet.address).to eq('www.metasploit.com')
23
end
24
end
25
26
describe "#address=" do
27
it "should set an IPv4 address" do
28
packet = Socks5::Packet.new
29
packet.address = '127.0.0.1'
30
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV4)
31
expect(packet.address_array).to eq([0x7f, 0x00, 0x00, 0x01])
32
end
33
34
it "should set an IPv6 address" do
35
packet = Socks5::Packet.new
36
packet.address = '::1'
37
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV6)
38
expect(packet.address_array).to eq([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])
39
end
40
41
it "should set a domain name" do
42
packet = Socks5::Packet.new
43
packet.address = 'www.metasploit.com'
44
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_DOMAINNAME)
45
expect(packet.address_array).to eq([0x77, 0x77, 0x77, 0x2e, 0x6d, 0x65, 0x74, 0x61, 0x73, 0x70, 0x6c, 0x6f, 0x69, 0x74, 0x2e, 0x63, 0x6f, 0x6d])
46
end
47
end
48
49
describe "#command" do
50
it "should parse a connect command" do
51
packet = Socks5::Packet.read("\x05\x01\x00\x01\x7f\x00\x00\x01\x00\x00")
52
expect(packet.command).to eq(Socks5::ServerClient::COMMAND_CONNECT)
53
end
54
55
it "should parse a bind command" do
56
packet = Socks5::Packet.read("\x05\x02\x00\x01\x7f\x00\x00\x01\x00\x00")
57
expect(packet.command).to eq(Socks5::ServerClient::COMMAND_BIND)
58
end
59
60
it "should parse a UDP associate command" do
61
packet = Socks5::Packet.read("\x05\x03\x00\x01\x7f\x00\x00\x01\x00\x00")
62
expect(packet.command).to eq(Socks5::ServerClient::COMMAND_UDP_ASSOCIATE)
63
end
64
end
65
66
describe "#read" do
67
it "should parse all fields" do
68
packet = Socks5::Packet.read("\x05\x01\x00\x01\x7f\x00\x00\x01\x00\x50")
69
expect(packet.version).to eq(Socks5::SOCKS_VERSION)
70
expect(packet.command).to eq(Socks5::ServerClient::COMMAND_CONNECT)
71
expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV4)
72
expect(packet.address).to eq('127.0.0.1')
73
expect(packet.port).to eq(80)
74
end
75
end
76
77
describe "#to_binary_s" do
78
it "should pack the data to a binary string" do
79
packet = Socks5::Packet.new
80
expect(packet.to_binary_s).to eq("\x05\x00\x00\x00\x00\x00")
81
end
82
end
83
84
describe "#version" do
85
it "should have the SOCKS5 version set by default" do
86
packet = Socks5::Packet.new
87
packet.version = Socks5::SOCKS_VERSION
88
end
89
end
90
91
end
92
93