Module: Rex::Proto::Proxy::Socks5::Address

Included in:
Packet, UdpPacket
Defined in:
lib/rex/proto/proxy/socks5/packet.rb

Overview

Mixin for socks5 packets to include an address field.

Constant Summary collapse

ADDRESS_TYPE_IPV4 =
1
ADDRESS_TYPE_DOMAINNAME =
3
ADDRESS_TYPE_IPV6 =
4

Instance Method Summary collapse

Instance Method Details

#addressObject


21
22
23
24
25
26
27
# File 'lib/rex/proto/proxy/socks5/packet.rb', line 21

def address
  addr = address_array.to_ary.pack('C*')
  if address_type == ADDRESS_TYPE_IPV4 || address_type == ADDRESS_TYPE_IPV6
    addr = Rex::Socket.addr_ntoa(addr)
  end
  addr
end

#address=(value) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rex/proto/proxy/socks5/packet.rb', line 29

def address=(value)
  if Rex::Socket.is_ipv4?(value)
    address_type.assign(ADDRESS_TYPE_IPV4)
    domainname_length.assign(0)
    value = Rex::Socket.addr_aton(value)
  elsif Rex::Socket.is_ipv6?(value)
    address_type.assign(ADDRESS_TYPE_IPV6)
    domainname_length.assign(0)
    value = Rex::Socket.addr_aton(value)
  else
    address_type.assign(ADDRESS_TYPE_DOMAINNAME)
    domainname_length.assign(value.length)
  end
  address_array.assign(value.unpack('C*'))
end

#address_lengthObject


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rex/proto/proxy/socks5/packet.rb', line 45

def address_length
  case address_type
    when ADDRESS_TYPE_IPV4
      4
    when ADDRESS_TYPE_DOMAINNAME
      domainname_length
    when ADDRESS_TYPE_IPV6
      16
    else
      0
  end
end