Last active
October 2, 2021 16:52
-
-
Save RBotfield/f3efbed632d3b8307b07c133c64f6173 to your computer and use it in GitHub Desktop.
Intercept requests by their REQUEST_URI w/ passthru
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $interceptUris = [ | |
| 'rtm/status', | |
| 'rtm/Loggedin', | |
| 'AppAuthorization/GetAuthorization', | |
| 'AppAuthorization/GetLicenseData', | |
| 'AppAuthorization/MultitoolData' | |
| ]; | |
| foreach ($interceptUris as $uri) { | |
| $shouldIntercept = stripos($_SERVER['REQUEST_URI'], $uri) !== false; | |
| if ($shouldIntercept) { | |
| return; | |
| } | |
| } | |
| $dnsRequest = file_get_contents("https://dns.google/resolve?type=1&name=" . urlencode($_SERVER['HTTP_HOST'])); | |
| $originalDnsRecord = json_decode($dnsRequest); | |
| if (!$dnsRequest || $originalDnsRecord->Status !== 0) { | |
| throw new Exception("Invalid DNS Response"); | |
| } | |
| $ch = curl_init("https://" . $originalDnsRecord->Answer[0]->data . $_SERVER['REQUEST_URI']); // init curl resource | |
| curl_setopt_array($ch, [ | |
| CURLOPT_HTTPHEADER => ["Host: " . $_SERVER['HTTP_HOST']], | |
| CURLOPT_TIMEOUT => 60, | |
| CURLOPT_SSL_VERIFYHOST => false, | |
| CURLOPT_SSL_VERIFYPEER => false, | |
| CURLOPT_FOLLOWLOCATION => true, | |
| CURLOPT_RETURNTRANSFER => false, | |
| CURLOPT_HEADERFUNCTION => "headerCallback", | |
| CURLOPT_WRITEFUNCTION => "writeCallback", | |
| ]); | |
| curl_exec($ch); | |
| curl_close($ch); | |
| function headerCallback($ch, $header) | |
| { | |
| header($header); | |
| return strlen($header); | |
| } | |
| function writeCallback($ch, $string) | |
| { | |
| echo ($string); | |
| return strlen($string); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment