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/lib/rex/proto/proxy/socks5/packet.rb
Views: 11765
# -*- coding: binary -*-12require 'bindata'3require 'rex/socket'45module Rex6module Proto7module Proxy89module Socks510SOCKS_VERSION = 51112#13# Mixin for socks5 packets to include an address field.14#15module Address16ADDRESS_TYPE_IPV4 = 117ADDRESS_TYPE_DOMAINNAME = 318ADDRESS_TYPE_IPV6 = 41920def address21addr = address_array.to_ary.pack('C*')22if address_type == ADDRESS_TYPE_IPV4 || address_type == ADDRESS_TYPE_IPV623addr = Rex::Socket.addr_ntoa(addr)24end25addr26end2728def address=(value)29if Rex::Socket.is_ipv4?(value)30address_type.assign(ADDRESS_TYPE_IPV4)31domainname_length.assign(0)32value = Rex::Socket.addr_aton(value)33elsif Rex::Socket.is_ipv6?(value)34address_type.assign(ADDRESS_TYPE_IPV6)35domainname_length.assign(0)36value = Rex::Socket.addr_aton(value)37else38address_type.assign(ADDRESS_TYPE_DOMAINNAME)39domainname_length.assign(value.length)40end41address_array.assign(value.unpack('C*'))42end4344def address_length45case address_type46when ADDRESS_TYPE_IPV447448when ADDRESS_TYPE_DOMAINNAME49domainname_length50when ADDRESS_TYPE_IPV6511652else53054end55end56end5758class AuthRequestPacket < BinData::Record59endian :big6061uint8 :version, :initial_value => SOCKS_VERSION62uint8 :supported_methods_length63array :supported_methods, :type => :uint8, :initial_length => :supported_methods_length64end6566class AuthResponsePacket < BinData::Record67endian :big6869uint8 :version, :initial_value => SOCKS_VERSION70uint8 :chosen_method71end7273class Packet < BinData::Record74include Address75endian :big76hide :reserved, :domainname_length7778uint8 :version, :initial_value => SOCKS_VERSION79uint8 :command80uint8 :reserved81uint8 :address_type82uint8 :domainname_length, :onlyif => lambda { address_type == ADDRESS_TYPE_DOMAINNAME }83array :address_array, :type => :uint8, :initial_length => lambda { address_length }84uint16 :port85end8687class RequestPacket < Packet88end8990class ResponsePacket < Packet91end9293class UdpPacket < BinData::Record94include Address95endian :big96hide :reserved, :domainname_length9798uint16 :reserved99uint8 :frag100uint8 :address_type101uint8 :domainname_length, :onlyif => lambda { address_type == ADDRESS_TYPE_DOMAINNAME }102array :address_array, :type => :uint8, :initial_length => lambda { address_length }103uint16 :port104end105end106end107end108end109110111