Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add authentication to a socks5 proxy server?
    primarykey
    data
    text
    <p>I am trying to build a socks5 proxy server using codes I found googling and customizing them. Everything works fine so far but now I want to add authentication to the socks5.</p> <p>This is the code that handle the requests:</p> <pre><code>SOCKET socks5Handler( SOCKET Client, char* Buffer ) { SOCKS5AUTH sAuth; char *Host = NULL; SOCKET Target = INVALID_SOCKET; ulong Ip = 0; ushort Port = 0; byte Command = 0, Type = 0; int i = 0; if( sockRecv(Client, Buffer, 1) &lt; 0 ) return INVALID_SOCKET; if( sockRecv(Client, Buffer, Buffer[0]) &lt; 0 ) return INVALID_SOCKET; Buffer[0] = 0x05; Buffer[1] = 0x00; send( Client, Buffer, 2, 0 ); if( sockRecv(Client, Buffer, 4) &lt; 0 ) return INVALID_SOCKET; Command = Buffer[1]; Type = Buffer[3]; if( Type == 0x01 ) { if( sockRecv(Client, Buffer, 4) &lt; 0 ) return INVALID_SOCKET; Ip = *((ulong*)Buffer); } else if( Type == 0x03 ) { if( sockRecv(Client, Buffer, 1) &lt; 0 ) return INVALID_SOCKET; i = Buffer[0]; if( sockRecv(Client, Buffer, i) &lt; 0 ) return INVALID_SOCKET; Buffer[i] = 0; Host = Buffer; } else return INVALID_SOCKET; if( sockRecv(Client, (char*)&amp;Port, 2) &lt; 0) return INVALID_SOCKET; if( Command == 0x01 ) { if( Host ) Ip = sock_resolve( Host ); Target = sock_connect( sock_create(), Ip, htons(Port) ); if( Target == INVALID_SOCKET ) return INVALID_SOCKET; } else return INVALID_SOCKET; Buffer[0] = 0x05; Buffer[1] = 0x00; Buffer[2] = 0x00; Buffer[3] = 0x01; *((ulong* )(Buffer + 4)) = Ip; *((ushort*)(Buffer + 8)) = Port; send( Client, Buffer, 10, 0 ); return Target; } BOOL sockRecv( SOCKET Sock, char* Buffer, int Length ) { int r = 0; while( Length ) { r = recv( Sock, Buffer, Length, 0 ); if( r &lt;= 0 ) return FALSE; Buffer += r; Length -= r; } return TRUE; } </code></pre> <p>I figured out that if I add:</p> <pre><code>if(Buffer[0] != 0x02) return INVALID_SOCKET; </code></pre> <p>after the first sockRecv, I can know if auth is being sent or not (0x1 is not auth and 0x2 is auth).</p> <p><strong>Now, how could I read the username and password sent?</strong></p> <p>I tried sniffing the network but that didn't show me anything good.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload