Skip to content

Instantly share code, notes, and snippets.

@dktapps
Last active February 15, 2023 04:52
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dktapps/4fa8a6df15e851f6b58d01df36bd0aa3 to your computer and use it in GitHub Desktop.
Save dktapps/4fa8a6df15e851f6b58d01df36bd0aa3 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;
}
}
@RubyTemple
Copy link

RubyTemple commented Sep 20, 2017

hi I have a problem the script part but to enter the server 19132 asks me l access to xbox live

@dktapps
Copy link
Author

dktapps commented Oct 18, 2017

This only allows you to bypass the client-forced authentication, servers can still choose to require it. If the server requires it, it can't be bypassed.

@Stevedaboss1YT
Copy link

how do i use this? do i drag it in my MP folder and run it?

@Stevedaboss1YT
Copy link

Hello?

@t0mtee
Copy link

t0mtee commented Sep 1, 2018

Yeah, how do I use this?

@MistakingManx
Copy link

I'd also like to know how to use this ^^

@nathfreder
Copy link

How to run:

git clone https://gist.github.com/4fa8a6df15e851f6b58d01df36bd0aa3.git
cd 4fa8a6df15e851f6b58d01df36bd0aa3
php run.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment