Mar 09

Podcast 2×03: eines per jugar amb SOCKS5

Reading time: 1 – 2 minutes

Finalment l’última entrega de la trilogia de podcasts sobre SOCKS. Com indica el títol i podeu veure amb els links aquest parla d’eines per montar servidors SOCKS i wrappers per montar clients SOCKS5.

El podcast:

Referències:

Mar 09

Podcast 2×02: SOCKS5 Bytestreams (XEP-0065)

Reading time: 4 – 7 minutes

La segona part sobre la trilogia de SOCKS5.

El podcast:

Exemples extrets del XEP-0065:

Example 1. Initiator Sends Service Discovery Request to Target

<iq type='get'
    from='initiator@example.com/foo'
    to='target@example.org/bar'
    id='hello'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

Example 2. Target Replies to Service Discovery Request

<iq type='result'
    from='target@example.org/bar'
    to='initiator@example.com/foo'
    id='hello'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <identity
        category='proxy'
        type='bytestreams'
        name='SOCKS5 Bytestreams Service'/>
    <feature var='http://jabber.org/protocol/bytestreams'/>
  </query>
</iq>

Example 3. Initiator Sends Service Discovery Request to Server

<iq type='get'
    from='initiator@example.com/foo'
    to='example.com'
    id='server_items'>
  <query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>

Example 4. Server Replies to Service Discovery Request

<iq type='result'
    from='example.com'
    to='initiator@example.com/foo'
    id='server_items'>
  <query xmlns='http://jabber.org/protocol/disco#items'>
    <item jid='streamhostproxy.example.net' name='Bytestreams Proxy'/>
  </query>
</iq>

Example 5. Initiator Sends Service Discovery Request to Proxy

<iq type='get'
    from='initiator@example.com/foo'
    to='streamhostproxy.example.net'
    id='proxy_info'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

Example 6. Server Replies to Service Discovery Request

<iq type='result'
    from='streamhostproxy.example.net'
    to='initiator@example.com/foo'
    id='proxy_info'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <identity category='proxy'
              type='bytestreams'
              name='SOCKS5 Bytestreams Service'/>
    <feature var='http://jabber.org/protocol/bytestreams'/>
  </query>
</iq>

Example 7. Initiator Requests Network Address from Proxy

<iq type='get'
    from='initiator@example.com/foo'
    to='streamhostproxy.example.net'
    id='discover'>
  <query xmlns='http://jabber.org/protocol/bytestreams'
         sid='vxf9n471bn46'/>
</iq>

Example 8. Proxy Informs Initiator of Network Address

<iq type='result'
    from='streamhostproxy.example.net'
    to='initiator@example.com/foo'
    id='discover'>
  <query xmlns='http://jabber.org/protocol/bytestreams'>
         sid='vxf9n471bn46'>
    <streamhost
        jid='streamhostproxy.example.net'
        host='24.24.24.1'
        p
        zeroconf='_jabber.bytestreams'/>
  </query>
</iq>

Example 9. Proxy Returns Error to Initiator

<iq type='error'
    from='initiator@example.com/foo'
    to='streamhostproxy.example.net'
    id='discover'>
  <query xmlns='http://jabber.org/protocol/bytestreams'
         sid='vxf9n471bn46'/>
  <error code='403' type='auth'>
    <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>

Example 10. Proxy Returns Error to Initiator

<iq type='error'
    from='initiator@example.com/foo'
    to='streamhostproxy.example.net'
    id='discover'>
  <query xmlns='http://jabber.org/protocol/bytestreams'
         sid='vxf9n471bn46'/>
  <error code='405' type='cancel'>
    <not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>

Example 11. Initiation of Interaction

<iq type='set'
    from='initiator@example.com/foo'
    to='target@example.org/bar'
    id='initiate'>
  <query xmlns='http://jabber.org/protocol/bytestreams'
         sid='vxf9n471bn46'
         mode='tcp'>
    <streamhost
        jid='initiator@example.com/foo'
        host='192.168.4.1'
        port='5086'/>
    <streamhost
        jid='streamhostproxy.example.net'
        host='24.24.24.1'
        zeroconf='_jabber.bytestreams'/>
  </query>
</iq>

Example 12. Target Refuses Bytestream

<iq type='error'
    from='target@example.org/bar'
    to='initiator@example.com/foo'
    id='initiate'>
  <error code='406' type='auth'>
    <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>

Example 13. Target Is Unable to Connect to Any StreamHost and Wishes to End Transaction

<iq type='error'
    from='target@example.org/bar'
    to='initiator@example.com/foo'
    id='initiate'>
  <error code='404' type='cancel'>
    <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>

Example 16. Target Notifies Initiator of Connection

<iq type='result'
    from='target@example.org/bar'
    to='initiator@example.com/foo'
    id='initiate'>
  <query xmlns='http://jabber.org/protocol/bytestreams'
         sid='vxf9n471bn46'>
    <streamhost-used jid='streamhostproxy.example.net'/>
  </query>
</iq>

Example 19. Initiator Requests Activation of Bytestream

<iq type='set'
    from='initiator@example.com/foo'
    to='streamhostproxy.example.net'
    id='activate'>
  <query xmlns='http://jabber.org/protocol/bytestreams'
         sid='vxf9n471bn46'>
    <activate>target@example.org/bar</activate>
  </query>
</iq>

Example 20. Proxy Informs Initiator of Activation

<iq type='result'
    from='streamhostproxy.example.net'
    to='initiator@example.com/foo'
    id='activate'/>

Referències:

<iq type=’get’
from=’initiator@example.com/foo’
to=’target@example.org/bar’
id=’hello’>
<query xmlns=’http://jabber.org/protocol/disco#info’/>
</iq>
Mar 04

Podcast 2×01: introudcció i descripció detallada del protcol SOCKS5

Reading time: 3 – 4 minutes

Després de moltes hores de feina estudiant el protocol SOCKS he decidit publicar un podcast que expliqui el seu RFC, el podcast pretent fer una introducció des de la part meś conceptual fins endinsar-se en el fluxe de paquets, els camps de les peticions llençades arribant a explicacions de nivell de bit. Amb l’ajuda dels diagrames adjunts a aquest article, l’RFC1928 i l’explicació del podcast després hauriem d’estar capacitats per implementar un client/servidor SOCKS5.

El podcast:

Esquemes que ajuden a seguir el podcast

esquema 1: petició d’un client SOCKS5 al servidor

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

esquema 2: resposta del servidor SOCKS5 al client

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

mètodes d’autenticació

  • 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

esquema 3: el client SOCKS5 envia una comanda al servidor

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

camp: ATYP -> address type

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

esquema 4: resposta del servidor SOCKS5 a la comanda del client

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

camp: 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

esquema 5: encapsulaments per enviaments de paquets UDP

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

esquema 6: camps de l’encapsulament: UDP ASSOCIATION

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

Referències d’utilitat

  • Apunts per fer el podcast: fitxer .txt amb la llista de coses que havia de comentar al podcast és una barreja de català, castellà i anglès… però pot servir-vos per entendre el que intento explicar
  • Wikipedia: SOCKS
  • RFC’s:
    • RFC1928: SOCKS Protocol v5
    • RFC1929: Username/Password Authentication for SOCKS V5
    • RFC1961: GSS-API Authentication Method for SOCKS V5