public void Calculate_AddressSOCK(byte AType) { switch (AType) { // Version IP 4 case 0x01: RemoteHost = Tools.calcInetAddress(DST_Addr); RemotePort = Tools.calcPort(DST_Port); break; // Version IP DOMAIN NAME case 0x03: if (DST_Addr[0] <= 0) { Logs.Println( Logger.ERROR, "SOCKS 5 - calcInetAddress() : BAD IP in command - size : " + DST_Addr[0], true); return; } String sIA = ""; for (int i = 1; i <= DST_Addr[0]; i++) { sIA += (char) DST_Addr[i]; } RemoteHost = sIA; RemotePort = Tools.calcPort(DST_Port); break; } }
public void GetClientCommand() throws Exception { // +----+-----+-------+------+----------+----------+ // |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT | // +----+-----+-------+------+----------+----------+ // | 1 | 1 | X'00' | 1 | Variable | 2 | // +----+-----+-------+------+----------+----------+ int Addr_Len; SOCKS_Version = GetByte(); Command = GetByte(); RSV = GetByte(); ATYP = GetByte(); // Address Addr_Len = ADDR_Size[ATYP]; DST_Addr[0] = GetByte(); // Shift Out " " 0x0e if (ATYP == 0x03) { Addr_Len = DST_Addr[0] + 1; // | len | [0]SO | 192 .... | } for (int i = 1; i < Addr_Len; i++) { DST_Addr[i] = GetByte(); } // Port DST_Port[0] = GetByte(); DST_Port[1] = GetByte(); // --------------------- if (SOCKS_Version != SOCKS5_Version) { Logs.Println( Logger.ERROR, "SOCKS 5 - Incorrect SOCKS Version of Command: " + SOCKS_Version, true); Refuse_Command((byte) 0xFF); throw new Exception("Incorrect SOCKS Version of Command: " + SOCKS_Version); } if ((Command < SC_CONNECT) || (Command > SC_UDP)) { Logs.Println( Logger.ERROR, "SOCKS 5 - GetClientCommand() - Unsupported Command : \"" + commName(Command) + "\"", true); Refuse_Command((byte) 0x07); throw new Exception("SOCKS 5 - Unsupported Command: \"" + Command + "\""); } if (ATYP == 0x04) { Logs.Println( Logger.ERROR, "SOCKS 5 - GetClientCommand() - Unsupported Address Type - IP v6", true); Refuse_Command((byte) 0x08); throw new Exception("Unsupported Address Type - IP v6"); } if ((ATYP >= 0x04) || (ATYP <= 0)) { Logs.Println( Logger.ERROR, "SOCKS 5 - GetClientCommand() - Unsupported Address Type: " + ATYP, true); Refuse_Command((byte) 0x08); throw new Exception("SOCKS 5 - Unsupported Address Type: " + ATYP); } if (!Calculate_Address()) { // Gets the IP Address Refuse_Command((byte) 0x04); // Host Not Exists... throw new Exception("SOCKS 5 - Unknown Host/IP address '" + RemoteHost.toString() + "'"); } Logs.Println( Logger.INFO, "SOCKS 5 - Accepted SOCKS5 Command: \"" + commName(Command) + "\"", true); }