Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/proto/proxy/socks5/packet_spec.rb
Views: 11791
# -*- coding:binary -*-12RSpec.describe Rex::Proto::Proxy::Socks5::Packet do3Socks5 = Rex::Proto::Proxy::Socks545describe "#address" do6it "should parse an IPv4 address" do7packet = Socks5::Packet.read("\x05\x02\x00\x01\x7f\x00\x00\x01\x00\x00")8expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV4)9expect(packet.address).to eq('127.0.0.1')10end1112it "should parse an IPv6 address" do13packet = 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")14expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV6)15expect(packet.address).to eq('::1')16end1718it "should parse a domain name" do19packet = Socks5::Packet.read("\x05\x02\x00\x03\x12www.metasploit.com\x00\x00")20expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_DOMAINNAME)21expect(packet.address).to eq('www.metasploit.com')22end23end2425describe "#address=" do26it "should set an IPv4 address" do27packet = Socks5::Packet.new28packet.address = '127.0.0.1'29expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV4)30expect(packet.address_array).to eq([0x7f, 0x00, 0x00, 0x01])31end3233it "should set an IPv6 address" do34packet = Socks5::Packet.new35packet.address = '::1'36expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV6)37expect(packet.address_array).to eq([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])38end3940it "should set a domain name" do41packet = Socks5::Packet.new42packet.address = 'www.metasploit.com'43expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_DOMAINNAME)44expect(packet.address_array).to eq([0x77, 0x77, 0x77, 0x2e, 0x6d, 0x65, 0x74, 0x61, 0x73, 0x70, 0x6c, 0x6f, 0x69, 0x74, 0x2e, 0x63, 0x6f, 0x6d])45end46end4748describe "#command" do49it "should parse a connect command" do50packet = Socks5::Packet.read("\x05\x01\x00\x01\x7f\x00\x00\x01\x00\x00")51expect(packet.command).to eq(Socks5::ServerClient::COMMAND_CONNECT)52end5354it "should parse a bind command" do55packet = Socks5::Packet.read("\x05\x02\x00\x01\x7f\x00\x00\x01\x00\x00")56expect(packet.command).to eq(Socks5::ServerClient::COMMAND_BIND)57end5859it "should parse a UDP associate command" do60packet = Socks5::Packet.read("\x05\x03\x00\x01\x7f\x00\x00\x01\x00\x00")61expect(packet.command).to eq(Socks5::ServerClient::COMMAND_UDP_ASSOCIATE)62end63end6465describe "#read" do66it "should parse all fields" do67packet = Socks5::Packet.read("\x05\x01\x00\x01\x7f\x00\x00\x01\x00\x50")68expect(packet.version).to eq(Socks5::SOCKS_VERSION)69expect(packet.command).to eq(Socks5::ServerClient::COMMAND_CONNECT)70expect(packet.address_type).to eq(Socks5::Address::ADDRESS_TYPE_IPV4)71expect(packet.address).to eq('127.0.0.1')72expect(packet.port).to eq(80)73end74end7576describe "#to_binary_s" do77it "should pack the data to a binary string" do78packet = Socks5::Packet.new79expect(packet.to_binary_s).to eq("\x05\x00\x00\x00\x00\x00")80end81end8283describe "#version" do84it "should have the SOCKS5 version set by default" do85packet = Socks5::Packet.new86packet.version = Socks5::SOCKS_VERSION87end88end8990end919293