public function authenticate(Client $client) { $login_string = pack('CC', self::VER, mb_strlen($this->username, 'ASCII')); $login_string .= $this->username; $login_string .= pack('C', mb_strlen($this->password, 'ASCII')); $login_string .= $this->password; $client->send($login_string); $response = unpack('Cver/Cstatus', $client->recv()); if (!isset($response['ver'], $response['status'])) { throw new Exception('PlainAuth: unable to parse response'); } if ($response['ver'] !== self::VER) { throw new Exception(sprintf('PlainAuth: version mismatch (server: %d / client: %d)', $response['ver'], self::VER)); } if ($response['status'] !== self::STATUS_SUCCESS) { throw new Exception('PlainAuth: unsuccessful login'); } return true; }
<?php // debug error_reporting(E_ALL); ini_set('display_errors', true); require 'src/Weheartwebsites/autoload.php'; use Weheartwebsites\SOCKS5\Client as SOCKS5Client; use Weheartwebsites\SOCKS5\Methods\None as AuthNone; $socks_client = new SOCKS5Client('127.0.0.1'); $socks_client->addMethod(new AuthNone()); //$socks_client->setTunnelDNS(true); $request = ['GET / HTTP/1.1', 'Host: curlmyip.com', 'Connection: close']; try { $socks_client->connect(); $socks_client->connectTo('curlmyip.com', 80); var_dump(fwrite($socks_client->socket, implode("\r\n", $request) . "\r\n\r\n")); $head = $body = $buffer = null; $is_header = true; // I know this is shitty, but just for a quick demonstration.... while (true) { $buffer = fgets($socks_client->socket); if ($buffer === false) { usleep(200000); continue; } if ($is_header) { $head .= $buffer; if (substr($head, -4) == "\r\n\r\n") { $is_header = false; // get rest bytes $head = rtrim(str_replace("\r\n", "\n", $head));