Podcast 2x01: introduction and detailed description of the SOCKS5 protocol

Translation of the original in Catalan. Read it in: CatalàCastellano

Part 1 of 5Podcast, season 2
  1. Podcast 2x01: introduction and detailed description of the SOCKS5 protocol
  2. Podcast 2x02: SOCKS5 Bytestreams (XEP-0065)
  3. Podcast 2x03: tools to play with SOCKS5
  4. Podcast 2x04: advanced SSH
  5. Podcast 2x06: How does Kerberos work? authentication and authorization (AA)

After many hours of work studying the SOCKS protocol I decided to publish a podcast that explains its RFC; the podcast aims to give an introduction, from the most conceptual part down into the packet flow and the fields of the requests sent, reaching bit-level explanations. With the help of the diagrams attached to this article, RFC1928 and the podcast explanation, afterwards we should be capable of implementing a SOCKS5 client/server.

El podcast:

Listen to the podcast (MP3)

Diagrams that help follow the podcast

diagram 1: request from a SOCKS5 client to the server

                   +----+----------+----------+
                   |VER | NMETHODS | METHODS  |
                   +----+----------+----------+
                   | 1  |    1     | 1 to 255 |
                   +----+----------+----------+

diagram 2: response from the SOCKS5 server to the client

                         +----+--------+
                         |VER | METHOD |
                         +----+--------+
                         | 1  |   1    |
                         +----+--------+

authentication methods

  • X'00' NO AUTHENTICATION REQUIRED
  • X'01' GSSAPI
  • X'02' USERNAME/PASSWORD
  • X'03' to X'7F' IANA ASSIGNED
  • X'80' to X'FE' RESERVED FOR PRIVATE METHODS
  • X'FF' NO ACCEPTABLE METHODS

diagram 3: the SOCKS5 client sends a command to the server

        +----+-----+-------+------+----------+----------+
        |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
        +----+-----+-------+------+----------+----------+
        | 1  |  1  | X'00' |  1   | Variable |    2     |
        +----+-----+-------+------+----------+----------+

field: ATYP -> address type

  • IP V4 address: X'01'
  • DOMAINNAME: X'03'
  • IP V6 address: X'04'

diagram 4: response from the SOCKS5 server to the client command

        +----+-----+-------+------+----------+----------+
        |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
        +----+-----+-------+------+----------+----------+
        | 1  |  1  | X'00' |  1   | Variable |    2     |
        +----+-----+-------+------+----------+----------+

field: REP -> reply

  • X'00' succeeded
  • X'01' general SOCKS server failure
  • X'02' connection not allowed by ruleset
  • X'03' Network unreachable
  • X'04' Host unreachable
  • X'05' Connection refused
  • X'06' TTL expired
  • X'07' Command not supported
  • X'08' Address type not supported
  • X'09' to X'FF' unassigned

diagram 5: encapsulation for sending UDP packets

      +-----+----+-----+------------------------+------+
      | ... | IP | UDP | SOCKS5 UDP ASSOCIATION | DATA |
      +-----+----+-----+------------------------+------+

diagram 6: fields of the encapsulation: UDP ASSOCIATION

      +----+------+------+----------+----------+----------+
      |RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
      +----+------+------+----------+----------+----------+
      | 2  |  1   |  1   | Variable |    2     | Variable |
      +----+------+------+----------+----------+----------+

Useful references

  • Notes for making the podcast: .txt file with the list of things I had to comment on the podcast, it is a mix of Catalan, Spanish and English... but it may help you understand what I am trying to explain
  • Wikipedia: SOCKS
  • RFC's:
    • RFC1928: SOCKS Protocol v5
    • RFC1929: Username/Password Authentication for SOCKS V5
    • RFC1961: GSS-API Authentication Method for SOCKS V5