Gistrec

UDP proxy used to bypass client-side Xbox Live auth

Sep 11th, 2017
238
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  *
  5.  *  ____            _        _   __  __ _                  __  __ ____
  6.  * |  _ \ ___   ___| | _____| |_|  \/  (_)_ __   ___      |  \/  |  _ \
  7.  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
  8.  * |  __/ (_) | (__|   <  __/ |_| |  | | | | | |  __/_____| |  | |  __/
  9.  * |_|   \___/ \___|_|\_\___|\__|_|  |_|_|_| |_|\___|     |_|  |_|_|
  10.  *
  11.  * This program is free software: you can redistribute it and/or modify
  12.  * it under the terms of the GNU Lesser General Public License as published by
  13.  * the Free Software Foundation, either version 3 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * @author PocketMine Team
  17.  * @link http://www.pocketmine.net/
  18.  *
  19.  *
  20. */
  21.  
  22. declare(strict_types=1);
  23.  
  24. $bindAddr = "0.0.0.0";
  25. $bindPort = 19132;
  26.  
  27.  
  28. echo "Enter server address: ";
  29. $serverAddress = gethostbyname(trim(fgets(STDIN)));
  30. echo "Enter server port: ";
  31. $serverPort = (int) trim(fgets(STDIN));
  32. if($serverPort !== 19132){
  33.     echo "Warning: You may experience problems connecting to PocketMine-MP servers on ports other than 19132 if the server has port checking enabled." . PHP_EOL;
  34. }
  35.  
  36. echo "Opening socket... ";
  37. $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  38. if(!socket_bind($sock, $bindAddr, $bindPort)){
  39.     echo "[!] Can't bind to $bindAddr on port $bindPort, is something already using that port?" . PHP_EOL;
  40.     exit(1);
  41. }
  42. socket_set_option($sock, SOL_SOCKET, SO_SNDBUF, 1024 * 1024 * 8);
  43. socket_set_option($sock, SOL_SOCKET, SO_RCVBUF, 1024 * 1024 * 8);
  44.  
  45. echo "Sending ping to server on $serverAddress $serverPort... ";
  46. $ping = "\x01" . pack("NN", mt_rand(0, 0x7fffffff), mt_rand(0, 0x7fffffff)) . "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78";
  47. socket_sendto($sock, $ping, strlen($ping), 0, $serverAddress, $serverPort);
  48.  
  49. $pong = "";
  50. echo "Waiting for communication... ";
  51. while(true){
  52.     $len = socket_recvfrom($sock, $pong, 65535, 0, $addr, $port);
  53.     if($addr === $serverAddress and $port === $serverPort and $pong{0} === "\x1c"){
  54.         echo "Got ping response from server!" . PHP_EOL;
  55.         break;
  56.     }
  57. }
  58.  
  59. echo "Waiting for client ping..." . PHP_EOL;
  60. $len = socket_recvfrom($sock, $buffer, 65535, 0, $clientAddr, $clientPort);
  61. echo "Got ping from $clientAddr on port $clientPort!" . PHP_EOL;
  62. socket_sendto($sock, $pong, strlen($pong), 0, $clientAddr, $clientPort);
  63.  
  64. echo "Waiting for client connection..." . PHP_EOL;
  65. while(true){
  66.     $len = socket_recvfrom($sock, $buffer, 65535, 0, $clientAddr, $clientPort);
  67.     if($buffer{0} === "\x05"){ //OpenConnectionRequest1
  68.         echo "Got connection from $clientAddr on port $clientPort!" . PHP_EOL;
  69.         break;
  70.     }
  71.     // FIXME: We aren't relaying this connection request. Not really a problem since RakNet will resend it with the same MTU a few times, but shouldn't we relay this anyway?
  72. }
  73.  
  74. echo "Packets from this address are now being relayed to $serverAddress on port $serverPort" . PHP_EOL;
  75. echo "Press CTRL+C to stop the proxy." . PHP_EOL;
  76.  
  77. socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, ["sec" => 10, "usec" => 0]);
  78.  
  79. while(true){
  80.     $status = @socket_recvfrom($sock, $buffer, 65535, 0, $source, $port);
  81.     if($status !== false){
  82.         //echo "Got packet from $source $port: " . bin2hex($buffer) . PHP_EOL;
  83.         if($source === $serverAddress and $port === $serverPort){
  84.             //echo "Got packet from server: " . bin2hex($buffer) . PHP_EOL;
  85.             socket_sendto($sock, $buffer, strlen($buffer), 0, $clientAddr, $clientPort);
  86.         }elseif($source === $clientAddr and $port === $clientPort){
  87.             //echo "Got packet from client: " . bin2hex($buffer) . PHP_EOL;
  88.             socket_sendto($sock, $buffer, strlen($buffer), 0, $serverAddress, $serverPort);
  89.         }else{
  90.             //echo "Ignored packet from $source $port" . PHP_EOL;
  91.             continue;
  92.         }
  93.     }elseif(socket_last_error($sock) === SOCKET_ETIMEDOUT){
  94.         echo "No communications received from server or client within 10 seconds. Exiting." . PHP_EOL;
  95.         break;
  96.     }
  97. }
Comments
  • User was banned
Add Comment
Please, Sign In to add comment