public SocksTunnel(SocksClient p, SocksRequest req, int packetSize) { RemoteClient = new TcpClient(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), _packetSize); Client = p; Req = req; _packetSize = packetSize; }
public static List <AuthTypes> RequestAuth(SocksClient client) { var buff = Receive(client.Client); if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5) { return(new List <AuthTypes>()); } var methods = Convert.ToInt32(buff[1]); var types = new List <AuthTypes>(); for (var i = 2; i < methods + 2; i++) { switch ((AuthTypes)buff[i]) { case AuthTypes.Login: types.Add(AuthTypes.Login); break; case AuthTypes.None: types.Add(AuthTypes.None); break; } } return(types); }
private void OnClientConnected(object sender, NewConnectionEventArgs e) { var client = new SocksClient(new TcpClient(e.Socket, PacketSize)); client.OnClientDisconnected += OnClientDisconnected; client.OnClientAuthenticating += OnClientAuthenticating; Clients.Add(client); client.Authentication = Authentication; client.Begin(PacketSize, Timeout); }
public static SocksRequest RequestTunnel(SocksClient client) { var buff = Receive(client.Client); if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5) { return(null); } switch ((StreamTypes)buff[1]) { case StreamTypes.Stream: var fwd = 4; var address = string.Empty; switch ((AddressType)buff[3]) { case AddressType.IP: for (var i = 4; i < 8; i++) { address += Convert.ToInt32(buff[i]).ToString() + (i != 7 ? "." : ""); } fwd += 4; break; case AddressType.Domain: var domainlen = Convert.ToInt32(buff[4]); address += Encoding.ASCII.GetString(buff, 5, domainlen); fwd += domainlen + 1; break; case AddressType.IPv6: //can't handle IPV6 traffic just yet. return(null); } var po = new byte[2]; Array.Copy(buff, fwd, po, 0, 2); var x = BitConverter.ToInt16(po, 0); var port = Convert.ToInt32(IPAddress.NetworkToHostOrder(x)); port = (port < 1 ? port + 65536 : port); return(new SocksRequest(StreamTypes.Stream, (AddressType)buff[3], address, port)); default: //not supported. return(null); } }
public static User RequestLogin(SocksClient client) { client.Client.Send(new[] { (byte)HeaderTypes.Socks5, (byte)HeaderTypes.Authentication }); var buff = Receive(client.Client); if (buff == null || buff[0] != 0x01) { return(null); } var numusername = Convert.ToInt32(buff[1]); var numpassword = Convert.ToInt32(buff[(numusername + 2)]); var username = Encoding.ASCII.GetString(buff, 2, numusername); var password = Encoding.ASCII.GetString(buff, numusername + 3, numpassword); return(new User(username, password, (IPEndPoint)client.Client.Sock.RemoteEndPoint)); }