Skip to content

Instantly share code, notes, and snippets.

@KennFatt
Forked from dktapps/run.php
Created December 29, 2017 11:31
Show Gist options
  • Save KennFatt/344008b5d9d76eca964967dba696f27a to your computer and use it in GitHub Desktop.
Save KennFatt/344008b5d9d76eca964967dba696f27a to your computer and use it in GitHub Desktop.
A basic UDP proxy used to bypass client-side Xbox Live authentication in MCPE 1.2.
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
$bindAddr = "0.0.0.0";
$bindPort = 19132;
echo "Enter server address: ";
$serverAddress = gethostbyname(trim(fgets(STDIN)));
echo "Enter server port: ";
$serverPort = (int) trim(fgets(STDIN));
if($serverPort !== 19132){
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;
}
echo "Opening socket... ";
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if(!socket_bind($sock, $bindAddr, $bindPort)){
echo "[!] Can't bind to $bindAddr on port $bindPort, is something already using that port?" . PHP_EOL;
exit(1);
}
socket_set_option($sock, SOL_SOCKET, SO_SNDBUF, 1024 * 1024 * 8);
socket_set_option($sock, SOL_SOCKET, SO_RCVBUF, 1024 * 1024 * 8);
$clientAddr = $clientPort = null;
while(true){
echo "Waiting for client ping..." . PHP_EOL;
$len = socket_recvfrom($sock, $buffer, 65535, 0, $recvAddr, $recvPort);
if($buffer{0} === "\x01"){ //ID_UNCONNECTED_PING
$pingAddr = $recvAddr;
$pingPort = $recvPort;
echo "Got ping from $recvAddr on port $recvPort, pinging server" . PHP_EOL;
socket_sendto($sock, $buffer, strlen($buffer), 0, $serverAddress, $serverPort);
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, ["sec" => 5, "usec" => 0]);
$len = socket_recvfrom($sock, $buffer, 65535, 0, $recvAddr, $recvPort);
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, ["sec" => 0, "usec" => 0]);
if($buffer{0} === "\x1c" and $recvAddr === $serverAddress and $recvPort === $serverPort){ //ID_UNCONNECTED_PONG
echo "Got ping response from server, sending to client" . PHP_EOL;
socket_sendto($sock, $buffer, strlen($buffer), 0, $pingAddr, $pingPort);
}
}elseif($buffer{0} === "\x05"){ //OpenConnectionRequest1
$clientAddr = $recvAddr;
$clientPort = $recvPort;
echo "Got connection from $recvAddr on port $recvPort!" . PHP_EOL;
break;
}
}
if($clientAddr === null or $clientPort === null){
die("WTF! no client address!!!!");
}
echo "Packets from $clientAddr on port $clientPort address are now being relayed to $serverAddress on port $serverPort" . PHP_EOL;
echo "Press CTRL+C to stop the proxy." . PHP_EOL;
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, ["sec" => 10, "usec" => 0]);
while(true){
$status = @socket_recvfrom($sock, $buffer, 65535, 0, $source, $port);
if($status !== false){
//echo "Got packet from $source $port: " . bin2hex($buffer) . PHP_EOL;
if($source === $serverAddress and $port === $serverPort){
//echo "Got packet from server: " . bin2hex($buffer) . PHP_EOL;
socket_sendto($sock, $buffer, strlen($buffer), 0, $clientAddr, $clientPort);
}elseif($source === $clientAddr and $port === $clientPort){
//echo "Got packet from client: " . bin2hex($buffer) . PHP_EOL;
socket_sendto($sock, $buffer, strlen($buffer), 0, $serverAddress, $serverPort);
}else{
//echo "Ignored packet from $source $port" . PHP_EOL;
continue;
}
}elseif(socket_last_error($sock) === SOCKET_ETIMEDOUT){
echo "No communications received from server or client within 10 seconds. Exiting." . PHP_EOL;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment