Created
May 16, 2022 16:58
-
-
Save ariankordi/3d7aff0dc02e91a40cdbf388566dea12 to your computer and use it in GitHub Desktop.
dns over https handler in php lol LOL, connects to 1.1.1.1 by default, only tested/known to work with Apple platforms
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 | |
// target dns server to connect to | |
define('DNS_TARGET_ADDRESS', 'udp://1.1.1.1:53'); | |
// dns will usually be either a get param, a post param, or both (hence request) | |
if(!isset($_REQUEST['dns'])) { | |
// show an error | |
http_response_code(400); | |
header('Content-Type: text/plain; charset=UTF-8'); | |
// explanation | |
exit("this is a dns over https handler (in ๐น๐น php ๐น๐น) and it expects you to pass either a get or post parameter called \"dns\" that contains a standard dns request and that parameter was not found ๐!"); | |
} | |
// decode and undo any base64 url encoding i believe | |
$request = base64_decode(str_replace(array('-', '_'), array('+', '/'), $_REQUEST['dns'])); | |
// set header for dns message cause yknow, You Gotta, | |
header('Content-Type: application/dns-message'); | |
// connect to dns and do request | |
$sock = @stream_socket_client(DNS_TARGET_ADDRESS, $errno, $errstr); | |
if(!$sock) { | |
http_response_code(502); | |
header('Content-Type: text/plain'); | |
exit('errno ' . $errno . ': ' . $errstr); | |
} | |
// ya | |
fwrite($sock, $request); | |
echo fread($sock, 4096); | |
fclose($sock); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment