public Receive ( byte data, int offset, int count ) : int | ||
data | byte | |
offset | int | |
count | int | |
Résultat | int |
public static SocksEncryption RequestSpecialMode(List<AuthTypes> auth, Client client) { //select mode, do key exchange if encryption, or start compression. if (auth.Contains(AuthTypes.SocksBoth)) { //tell client that we chose socksboth. client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.SocksBoth }); //wait for public key. SocksEncryption ph = new SocksEncryption(); ph.GenerateKeys(); //wait for public key. byte[] buffer = new byte[4096]; int keysize = client.Receive(buffer, 0, buffer.Length); //store key in our encryption class. ph.SetKey(buffer, 0, keysize); //send key. client.Send(ph.GetPublicKey()); //now we give them our key. client.Send(ph.ShareEncryptionKey()); //send more. int enckeysize = client.Receive(buffer, 0, buffer.Length); //decrypt with our public key. byte[] newkey = new byte[enckeysize]; Buffer.BlockCopy(buffer, 0, newkey, 0, enckeysize); ph.SetEncKey(ph.key.Decrypt(newkey, false)); ph.SetType(AuthTypes.SocksBoth); //ready up our client. return ph; } else if (auth.Contains(AuthTypes.SocksEncrypt)) { //tell client that we chose socksboth. client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.SocksEncrypt }); //wait for public key. SocksEncryption ph = new SocksEncryption(); ph.GenerateKeys(); //wait for public key. byte[] buffer = new byte[4096]; int keysize = client.Receive(buffer, 0, buffer.Length); //store key in our encryption class. ph.SetKey(buffer, 0, keysize); ph.SetType(AuthTypes.SocksBoth); //ready up our client. return ph; } else if (auth.Contains(AuthTypes.SocksCompress)) { //start compression. client.Send(new byte[] { (byte)HeaderTypes.Socks5, (byte)AuthTypes.SocksCompress }); SocksEncryption ph = new SocksEncryption(); ph.SetType(AuthTypes.SocksCompress); //ready } else if (auth.Contains(AuthTypes.Login)) { SocksEncryption ph = new SocksEncryption(); ph.SetType(AuthTypes.Login); return ph; } return null; }
public static byte[] Receive(Client client) { byte[] buffer = new byte[2048]; int received = client.Receive(buffer, 0, buffer.Length); if (received != -1) { return buffer; } else return null; }
public static int Receive(Client client, out byte[] buffer) { buffer = new byte[65535]; return client.Receive(buffer, 0, buffer.Length); }
public static socks5.Socks.SocksError SendRequest(Client cli, SocksEncryption enc, string ipOrDomain, int port) { AddressType type; IPAddress ipAddress; if (!IPAddress.TryParse(ipOrDomain, out ipAddress)) //it's a domain. :D (hopefully). type = AddressType.Domain; else type = AddressType.IP; SocksRequest sr = new SocksRequest(StreamTypes.Stream, type, ipOrDomain, port); //send data. byte[] p = sr.GetData(false); p[1] = 0x01; //process data. cli.Send(enc.ProcessOutputData(p, 0, p.Length)); byte[] buffer = new byte[512]; //process input data. int recv = cli.Receive(buffer, 0, buffer.Length); if(recv == -1) { return SocksError.Failure; } byte[] buff = enc.ProcessInputData(buffer, 0, recv); return (SocksError)buff[1]; }
public static int SendLogin(Client cli, string Username, string Password) { byte[] x = new byte[Username.Length + Password.Length + 3]; int total = 0; x[total++] = 0x01; x[total++] = Convert.ToByte(Username.Length); Buffer.BlockCopy(Encoding.ASCII.GetBytes(Username), 0, x, 2, Username.Length); total += Username.Length; x[total++] = Convert.ToByte(Password.Length); Buffer.BlockCopy(Encoding.ASCII.GetBytes(Password), 0, x, total, Password.Length); //send request. cli.Send(x); byte[] buffer = new byte[512]; cli.Receive(buffer, 0, buffer.Length); if (buffer[1] == 0x00) { return 1; } else if (buffer[1] == 0xFF) { return 0; } return 0; }
public static AuthTypes Greet(Client client, IList<AuthTypes> supportedAuthTypes = null) { if (supportedAuthTypes == null) supportedAuthTypes = new[] { AuthTypes.None, AuthTypes.Login, AuthTypes.SocksEncrypt }; // https://www.ietf.org/rfc/rfc1928.txt [Page 3] var bytes = new byte[supportedAuthTypes.Count + 2]; bytes[0] = 0x05; // protocol version - socks5 bytes[1] = (byte)supportedAuthTypes.Count; for (var i = 0; i < supportedAuthTypes.Count; i++) { bytes[i + 2] = (byte)supportedAuthTypes[i]; } client.Send(bytes); byte[] buffer = new byte[512]; int received = client.Receive(buffer, 0, buffer.Length); if(received > 0) { //check for server version. if (buffer[0] == 0x05) { return (AuthTypes)buffer[1]; } } return 0; }
public static AuthTypes Greet(Client client) { client.Send(new byte[] { 0x05, Convert.ToByte(3), (byte)AuthTypes.None, (byte)AuthTypes.Login, (byte)AuthTypes.SocksEncrypt });//(byte)AuthTypes.SocksBoth });//(byte)AuthTypes.SocksCompress byte[] buffer = new byte[512]; int received = client.Receive(buffer, 0, buffer.Length); if(received > 0) { //check for server version. if (buffer[0] == 0x05) { return (AuthTypes)buffer[1]; } } return 0; }