Skip to content

Instantly share code, notes, and snippets.

@m0rb
Created October 6, 2021 20:31
Show Gist options
  • Save m0rb/255db33b24d1cde407d8ba3dda511946 to your computer and use it in GitHub Desktop.
Save m0rb/255db33b24d1cde407d8ba3dda511946 to your computer and use it in GitHub Desktop.
minimalist doh/tor query client
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Socket;
use IO::Socket::Socks;
use IO::Socket::SSL;
use Net::DNS::Packet;
use MIME::Base64 qw(encode_base64url);
sub doh_query {
my ($l,$r,$d) = @_;
$r ||= 'A'; $d ||= 'IN';
my $s = IO::Socket::INET ->new ('127.1:9050');
$s = IO::Socket::Socks->start_SOCKS ($s, ConnectAddr => 'dns.google', ConnectPort => 443);
$s = IO::Socket::SSL ->start_SSL ($s, SSL_hostname=> 'dns.google');
my $q = encode_base64url(Net::DNS::Packet->new($l,$r,$d)->data);
print $s "GET /dns-query?dns=$q HTTP/1.0\r\n\r\n";
while (<$s>) {unless ($_ =~ /(:|\<|\n)/ ) {Net::DNS::Packet->new(\$_)->print;}}
}
doh_query(@ARGV);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment