Skip to content

Instantly share code, notes, and snippets.

@ariankordi
Created May 16, 2022 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariankordi/3d7aff0dc02e91a40cdbf388566dea12 to your computer and use it in GitHub Desktop.
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
<?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