Part Three Lab

The main purpose of DoH is to enhance privacy and security by encrypting DNS queries, preventing third parties from easily observing or tampering with the DNS requests made by a user.

How DNS over HTTP Works

  1. Traditional DNS:

    • In traditional DNS, queries are typically sent in plaintext over UDP or TCP using port 53. These requests can be intercepted and monitored by attackers or even by the ISP (Internet Service Provider).

  2. DNS over HTTPS:

    • With DoH, DNS queries and responses are wrapped inside HTTPS requests, which makes it harder for external observers (such as ISPs or hackers) to see what websites or services a user is trying to access.

    • The DNS query is sent over an encrypted HTTPS connection, making it secure and private.

Lab 5.3 - DNS over HTTPS (DoH)

Objectives:

  • Acquire hands-on experience with DNS over HTTPS (DoH)

  • Configure Firefox to directly use the Security511 cloud-based DoH server at https://dns.sec511.com/dns-query

  • Sniff encrypted DoH traffic with Wireshark

  • Export the pre-master secret from Firefox and import into Wireshark

  • Analyze decrypted DoH

A Note on the Pre-Master Secret:

As covered in 511.2, TLS traffic can be decrypted using either the web server's RSA private key (as demonstrated in the 511.2 exercise) or the browser's pre-master secret (as we'll do in this lab).

A quick overview of the pre-master secret (from slide 511.2, "HTTPS: TLS Handshake"):

The TLS handshake process works as follows:

  1. Client Hello: The client starts the handshake by sending a "hello" message to the server. This includes the supported TLS version, cipher suites, and a random byte string ("client random").

  2. Server Hello: The server responds with its own "hello" message, which contains its SSL certificate, chosen cipher suite, and a random byte string ("server random").

  3. Authentication: The client verifies the server's SSL certificate with the certificate authority, confirming the server's identity.

  4. Premaster Secret: The client sends a randomly generated "premaster secret" encrypted with the server's public key (from its SSL certificate). Only the server can decrypt it with its private key.

  5. Session Key Generation: Both the client and server generate session keys using the client random, server random, and premaster secret. Both parties should arrive at the same session key.

  6. Client Finished: The client sends a "finished" message encrypted with the session key.

  7. Server Finished: The server responds with its own "finished" message encrypted with the session key.

  8. Secure Encryption: The handshake is complete, and communication continues using the session keys for encrypted data exchange.

The browser's pre-master secret can be exported to decrypt all TLS traffic, including TLS 1.3. However, the server's RSA private key cannot decrypt TLS 1.3 because of Perfect Forward Secrecy (PFS).

Challenges:

  • Configure Firefox to use this DoH server: https://dns.sec511.com/dns-query

  • Use Wireshark to verify Firefox is resolving DNS names via DoH

  • Inspect DoH traffic with Wireshark

  • View the Server Name Indication (SNI) of https://dns.sec511.com

  • Import the key log (which includes the pre-master secret) into Wireshark

  • Decrypt and analyze DoH traffic From Firefox in Wireshark

Let's start by clicking the menu icon in Firefox in the upper-right corner, then select "Settings."

Then, we'll scroll down to the "Network Settings" section at the bottom and click on "Settings."

Let's scroll to the bottom of the page and enable "DNS over HTTPS." Then, select "Custom" and choose Security511's cloud-based server by entering: https://dns.sec511.com/dns-query

Let's open Wireshark and double-click on the "eth0" interface to start capturing network traffic.

Now let's close Firefox completely to ensure all TLS connections with https://dns.sec511.com are terminated. Then, reopen Firefox and open a new tab and surf to: https://www.sans.org/

Next, Let's open a terminal and run the following command to find the IP address of "dns.sec511.com":

dig dns.sec511.com

Let's filter by this IP Address in Wireshark.

tcp.port == 443 && ip.addr == 3.140.31.159

The data shows "dns.sec511.com," which is the Server Name Indication (SNI). In Wireshark, this is referred to as "tls.handshake.extensions_server_name."

Let's use the following Wireshark display filter to view only these packets:

tcp.port == 443 && ip.addr == 3.140.31.159 && tls.handshake.extensions_server_name
  • TLSv1.3 Record Layer: Handshake Protocol: Client Hello

  • Handshake Protocol: Client Hello

  • Extension: server_name (len=19)

  • Server Name Indication extension

The Server Name Indication (SNI) is "dns.sec511.com," which serves as the server's virtual host name.

The requested DNS records, including www.sans.org, are encrypted. Our next step is to decrypt the DoH (DNS over HTTPS) traffic using Firefox's pre-master secret. As mentioned earlier, the Firefox key log file can be used to decrypt all TLS traffic originating from the browser.

In Wireshark, let's navigate to Edit and select Preferences.

Next, scroll down to the "TLS" section under Protocols. At the bottom, locate the "(Pre)-Master-Secret log filename" field. Click "Browse," navigate to /home/student/keylog.log, and click "OK."

Now, let's stop the current capture by clicking the red "stop" icon. Then, to restart the capture, click the green shark fin icon and select "Continue without Saving."

Now, let's close Firefox again to initiate a new TLS session with https://dns.sec511.com upon reopening, then restart the browser.

After restarting, visit https://www.sans.org.

Let's filter by the same filter in Wireshark again.

tcp.port == 443 && ip.addr == 3.140.31.159

As we scroll down, the decrypted "DoH" packets become visible.

Now, let's use the following display filter to view only decrypted TLS traffic sent to or from IP address 3.140.31.159:

tcp.port == 443 && ip.addr == 3.140.31.159 && http

Let's use the following display filter to view the DNS response for "www.sans.org":

tcp.port == 443 and ip.addr==3.140.31.159 and http and dns.resp.name=="www.sans.org"

The next display filter will show decrypted HTTP traffic that is not related to the IP address 3.140.31.159 (non-DoH decrypted TLS traffic).

tcp.port == 443 && not ip.addr == 3.140.31.159 && http 

Wireshark treats HTTP and HTTP/2 as separate protocols. This display filter will show both.

tcp.port == 443 && not ip.addr == 3.140.31.159 && (http or http2)

Finally, let's reconfigure Firefox to use its original DNS settings as described at the start of this lab.

Last updated