FaresMorcy
  • Whoami
  • Footprinting Labs
    • Lab - Easy
    • Lab - Medium
    • Lab - Hard
  • Shells & Payloads
    • The Live Engagement
  • Password Attacks
    • Lab - Easy
    • Lab - Medium
    • Lab - Hard
  • SOC Hackthebox Notes & Labs
    • Security Monitoring & SIEM Fundamentals Module
    • Windows Event Logs & Finding Evil Module
    • Introduction to Threat Hunting & Hunting With Elastic Module
    • Understanding Log Sources & Investigating with Splunk Module
      • Introduction To Splunk & SPL
      • Using Splunk Applications
      • Intrusion Detection With Splunk (Real-world Scenario)
      • Detecting Attacker Behavior With Splunk Based On TTPs
      • Detecting Attacker Behavior With Splunk Based On Analytics
      • Skills Assessment
    • Windows Attacks & Defense
      • Kerberoasting
      • AS-REProasting
      • GPP Passwords
      • GPO Permissions/GPO Files
      • Credentials in Shares
      • Credentials in Object Properties
      • DCSync
      • Golden Ticket
      • Kerberos Constrained Delegation
      • Print Spooler & NTLM Relaying
      • Coercing Attacks & Unconstrained Delegation
      • Object ACLs
      • PKI - ESC1
      • Skills Assessment
    • Intro to Network Traffic Analysis Module
    • YARA & Sigma for SOC Analysts Module
      • Developing YARA Rules
      • Hunting Evil with YARA (Windows Edition)
      • Hunting Evil with YARA (Linux Edition)
      • Sigma and Sigma Rules
      • Developing Sigma Rules
      • Hunting Evil with Sigma (Chainsaw Edition)
      • Hunting Evil with Sigma (Splunk Edition)
      • Skills Assessment
  • TryHackme SOC 1
    • TShark
      • TShark: The Basics
      • TShark: CLI Wireshark Features
      • TShark Challenge I: Teamwork
      • TShark Challenge II: Directory
    • Tempest
    • Boogeyman 1
    • Boogeyman 2
    • Boogeyman 3
  • TryHackme SOC 2
    • Advanced Splunk
      • Splunk: Exploring SPL
      • Splunk: Setting up a SOC Lab
      • Splunk: Dashboards and Reports
      • Splunk: Data Manipulation
      • Fixit
    • Advanced ELK
      • Slingshot
    • Threat Hunting
      • Threat Hunting: Foothold
      • Threat Hunting: Pivoting
      • Threat Hunting: Endgame
  • TryHackme Rooms
    • Investigating Windows
    • Splunk 2
    • Windows Network Analysis
  • Powershell Scripting Fundamentals
  • SANS SEC504 & Labs
    • Book one
      • Live Examination
      • Network Investigations
      • Memory Investigations
      • Malware Investigations
      • Accelerating IR with Generative AI
      • Bootcamp: Linux Olympics
      • Bootcamp: Powershell Olympics
    • Book Two
      • Hacker Tools and Techniques Introduction
      • Target Discovery and Enumeration
      • Discovery and Scanning with Nmap
      • Cloud Spotlight: Cloud Scanning
      • SMB Security
      • Defense Spotlight: Hayabusa and Sigma Rules
    • Book Three
      • Password Attacks
      • Cloud Spotlight: Microsoft 365 Password Attacks
      • Understanding Password Hashes
      • Password Cracking
      • Cloud Spotlight: Insecure Storage
      • Multipurpose Netcat
    • Book Four
      • Metasploit Framework
      • Drive-By Attacks
      • Command Injection
      • Cross-Site Scripting
      • SQL Injection
      • Cloud Spotlight: SSRF and IMDS
    • Book Five
      • Endpoint Security Bypass
      • Pivoting and Lateral Movement
      • Hijacking Attacks
      • Establishing Persistence
      • Defense Spotlight: RITA
      • Cloud Spotlight: Cloud Post-Exploitation
  • SANS SEC511 & Labs
    • Resources
      • Primers
      • References
      • Tools
        • Network
        • Elastic Stack
      • Printable Versions
    • Book One
      • Part One
      • Part Two
      • Part Three
    • Book Two
      • Part One
      • Part Two
      • Part Three
      • Part Four
    • Book Three
      • Part One
      • Part Two
      • Part Three
      • Part Four
    • Book Four
      • Part One
      • Part Two
      • Part Three Lab
      • Part Four Lab
    • Book Five
      • Part One Lab
      • Part Two Lab
      • Part Three Lab
  • CyberDefenders
    • XXE Infiltration Lab
    • T1594 Lab
    • RetailBreach Lab
    • DanaBot Lab
    • OpenWire Lab
    • BlueSky Ransomware Lab
    • Openfire Lab
    • Boss Of The SOC v1 Lab
    • GoldenSpray Lab
    • REvil Lab
    • ShadowRoast Lab
    • SolarDisruption Lab
    • Kerberoasted Lab
    • T1197 Lab
    • Amadey Lab
    • Malware Traffic Analysis 1 Lab
    • Insider Lab
    • Volatility Traces Lab
    • FalconEye Lab
    • GitTheGate Lab
    • Trident Lab
    • NerisBot Lab
  • Practical Windows Forensics
    • Data Collection
    • Examination
    • Disk Analysis Introduction
    • User Behavior
    • Overview of disk structures, partitions and file systems
    • Finding Evidence of Deleted Files with USN Journal Analysis
    • Analyzing Evidence of Program Execution
    • Finding Evidence of Persistence Mechanisms
    • Uncover Malicious Activity with Windows Event Log Analysis
    • Windows Memory Forensic Analysis
  • Hackthebox Rooms
    • Campfire-1
    • Compromised
    • Brutus
    • Trent
    • CrownJewel-1
  • WEInnovate Training
    • Weinnovate - Active Directory Task One
    • Build ELK Lab
      • Configure Elasticsearch and Kibana setup in ubuntu
      • Configure Fluent-Bit to send logs to ELK
      • Set up Winlogbeat & Filebeat for log collection
      • Send Logs from Winlogbeat through Logstash to ELK
      • Enable Windows Audit Policy & Winlogbeat
      • Elasticsearch API and Ingestion Pipeline
    • SOAR
      • Send Alerts To Email & Telegram Bot
      • Integrate Tines with ELK
    • SOC Practical Assessment
    • Lumma C2
    • Network Analysis
  • Build ELK Lab
    • Configure Elasticsearch and Kibana setup in ubuntu
    • Configure Fluent-Bit to send logs to ELK
    • Set up Winlogbeat & Filebeat for log collection
    • Send Logs from Winlogbeat through Logstash to ELK
    • Enable Windows Audit Policy & Winlogbeat
    • Elasticsearch API and Ingestion Pipeline
  • Build Home Lab - SOC Automation
    • Install & configure Sysmon for deep Windows event logging
    • Set up Wazuh & TheHive for threat detection & case management
    • Execute Mimikatz & create detection rules in Wazuh
    • Automate everything with Shuffle
    • Response to SSH Attack Using Shuffle, Wazuh, and TheHive
  • Home Lab (Attack & Defense Scenarios)
    • Pass-the-Hash Attack & Defense
    • Scheduled Task Attack & Defense
    • Kerberoasting Attack & Defense
    • Kerberos Constrained Delegation
    • Password Spraying Attack & Defense
    • Golden Ticket Attack & Defense
    • AS-REProasting Attack & Defense
    • DCSync Attack & Defense
  • Home Lab (FIN7 (Carbanak Group) – Point of Sale (POS) Attack on Hospitality Chains)
  • Home Lab (Lumma Stealer)
Powered by GitBook
On this page
  • Encryption and TLS Inspection
  • Enterprise Responses to Outbound HTTPS Encryption
  • HTTPS: Transmission Security for HTTP
  • HTTPS: TLS Handshake
  • HTTP/2
  • QUIC - HTTP/3
  • QUIC: It's Not Just for Web Traffic
  • TLS Interception and Inspection
  • Active (a.k.a. In-Band) TLS Interception
  • Passive (a.k.a. Out-of-Band) TLS Decryption
  • Passive TLS Inspection (with RSA Private Key)
  • Wireshark's TLS RSA Private Key Decryption
  • Passive TLS Inspection (Client Browser Pre-Master Secret)
  • Perfect Forward Secrecy (PFS)
  • TLS 1.3 and PFS
  • Workarounds for Passively Decrypting TLS 1.3
  • Passively Decrypted TLS 1.3 Traffic to https://paypal.com
  • Decrypting HTTPS with Interception/Inspection
  • Never Decrypt All the Things
  • Lab 2.2 - Decrypting TLS with Wireshark
  1. SANS SEC511 & Labs
  2. Book Two

Part Two

PreviousPart OneNextPart Three

Last updated 6 months ago

Encryption and TLS Inspection

The chart shows how quickly the internet is becoming more encrypted, based on Firefox page loads. The data comes from Firefox Telemetry, and the chart is hosted by Let's Encrypt.

The chart highlights the need to consider how outbound HTTPS encryption affects security monitoring. Also, HTTPS is faster than HTTP, and encryption continues to grow.

Enterprise Responses to Outbound HTTPS Encryption

The key is to think about the security risks and decide what works best for your organization. Also, your approach might change over time as things are quickly evolving. Some organizations now accept more monitoring as a necessary part of security, even if they didn't before.

HTTPS: Transmission Security for HTTP

Since HTTP uses untrusted networks, securing its transmission is important. Encryption helps keep the communication private since HTTP is cleartext.

TLS 1.0 is built on SSL 3.0, the last version made by Netscape. The name changed, but TLS is just a new label for SSL since IETF took over. TLS 1.2 is the most used version now, despite being over ten years old and having some security issues. TLS 1.3 is a big update, but it will take time for servers, clients, and apps to support it.

HTTPS: TLS Handshake

Here are more complete details of the TLS handshake process:

  • The client starts the handshake by sending a "hello" message to the server. This message lists the TLS version and cipher suites it supports, along with random bytes called "client random."

  • The "server hello" message is the server's response to the client hello. It includes the server's SSL certificate, the chosen cipher suite, and a random string of bytes created by the server.

  • Authentication: The client checks the server's SSL certificate with the certificate authority to ensure the server is legitimate and that the client is communicating with the real domain owner.

  • The client sends a random byte string called the "premaster secret." This secret is encrypted with the server's public key, and only the server's private key can decrypt it. The client gets the public key from the server's SSL certificate.

  • Private key used: The server decrypts the premaster secret.

  • Session keys created: Both the client and server use the client random, server random, and premaster secret to generate session keys that match.

  • Client is ready: The client sends a "finished" message that is encrypted with a session key

  • Server ready: The server sends a "finished" message encrypted with a session key. The handshake is done, and communication continues with the session keys.

HTTP/2

HTTP/2, defined in RFC 7540, aims to improve the performance of HTTP, which is widely used. Enhancing HTTP's speed could greatly affect its usage. HTTP/1.1 was created in 1999, before the rise of major video streaming and social media platforms like Facebook, founded in 2004.

HTTP/2 improves performance by changing how HTTP works. This mainly affects browsers, web servers, and the infrastructure in between, not web applications or their development. There are major changes with HTTP/2.

Even though a browser can send many HTTP requests, it must receive and process responses one at a time. You may have noticed this when a webpage takes a long time to load; sometimes one big image loads first, then all the other images suddenly appear because that large file was slowing things down. Over the years, various tricks have been used to fix this, but HTTP/2 simplifies things. It lets all HTTP traffic go through one TCP connection, allowing requests and responses to be sent and received at the same time.

HTTP headers will be compressed using HPACK to improve performance by reducing the size of repeated headers sent in plain text. HPACK was created for HTTP/2, but not all HTTP/2 data is encrypted by default. Many people wrongly think HTTP/2 automatically means HTTPS everywhere. Although there were talks about requiring encryption for HTTP/2, it’s not a part of the standard.

QUIC - HTTP/3

QUIC is essentially HTTP/2 over UDP using TLS 1.3:

It is a new transport that lowers latency compared to TCP. It works like TCP, TLS, and HTTP/2 but uses UDP instead. Changing TCP is hard because it’s part of the operating system and network devices, but QUIC, built on UDP, doesn't have those limits.

QUIC is often overlooked by many organizations and penetration testers. Here’s a Wireshark screenshot showing the author connecting to images.google.com through Chrome using QUIC.

QUIC: It's Not Just for Web Traffic

QUIC is a protocol that replaces TCP with a faster and more efficient UDP method while keeping TCP's reliability. It's always encrypted and uses TLS 1.3 for security. QUIC is already used in Windows 10 with the Edge browser and other apps. With SMB over QUIC, it can replace TCP/IP, providing secure SMB communication, even if SMB encryption isn't turned on, and it uses port 443. Admins can enable this feature by setting up a Windows Server on the network edge, installing a trusted certificate, and turning on the QUIC option, or by using it with Azure Files.

We have two design imperatives for SMB over QUIC:

Secure: Stop hackers from spying or pretending to be someone else and protect sensitive file data and user credentials. All SMB communication, including capabilities, authentication, and messages, happens within the QUIC layer, similar to IPSEC or VPN tunnels, covering NTLM challenges too.

Simple: Users won't have to change their experience with SMB over QUIC from what they're used to in the office, as retraining is costly. Therefore, we won't add new UI options or command-line arguments. Their Windows 10 machines will still try TCP and RDMA first as usual, then briefly switch to QUIC. This way, they'll use faster local connections like RDMA or TCP when possible, and switch to QUIC when traveling or if required by an admin, all without the user noticing any difference.

TLS Interception and Inspection

Microsoft has a good explanation of the TLS handshake and the pre-master secret:

  • The client sends a "Hello" message to the server with a random value and a list of supported encryption methods.

  • The server replies with a "Server hello" message and its random value.

  • The server sends its certificate to the client to verify its identity and might ask for the client's certificate too. Then, the server sends a "Server hello done" message.

  • If the server asks for a certificate, the client sends it.

  • The client makes a random Pre-Master Secret, encrypts it with the server's public key, and sends it to the server.

  • The server gets the Pre-Master Secret. Both the server and client create the Master Secret and session keys from it.

  • The client tells the server it's ready to use new keys for encryption by sending a "Change cipher spec" message and a "Client finished" message.

  • The server gets a "Change cipher spec" message and switches to symmetric encryption with the session keys. Then, it sends a "Server finished" message to the client.

  • The client and server can now share data securely. All messages sent between them are encrypted with a session key.

Active (a.k.a. In-Band) TLS Interception

Web application penetration testers are very familiar with TLS interception/proxying. That's how interception proxies such as ZAP and Burp Suite are able to inspect (and manipulate) HTTPS traffic.

Here is an example of ZAP's (https://www.zaproxy.org/) Root CA certificate:

Passive (a.k.a. Out-of-Band) TLS Decryption

Wireshark can decrypt TLS traffic if you give it the right secrets. There are two ways to do this:

  • Key log file using per-session secrets.

  • Decryption using an RSA private key.

A key log file allows decryption even when Diffie-Hellman is used, unlike the RSA private key, which only works in some cases. This file is created by apps like Firefox, Chrome, and curl when the SSLKEYLOGFILE environment variable is set. Their libraries (NSS, OpenSSL, or BoringSSL) save session secrets to the file, which can be used in Wireshark for decryption.

Passive TLS Inspection (with RSA Private Key)

The IDS uses the web server's private key to decode traffic, but this only works for servers the organization controls, not third-party sites like banks. Wireshark can also decode TLS traffic with the server's private key.

This won't work if the web server uses Perfect Forward Secrecy (PFS), which is required by TLS 1.3. TLS 1.3 can't be inspected passively.

Wireshark's TLS RSA Private Key Decryption

Wireshark's site has new steps for setting up TLS decryption with the RSA private key.

In Wireshark 3.0 and later, go to Edit -> Preferences -> RSA Keys to add a key file or token. You may need to enter a password or configure a provider DLL/.so file for HSM keys.

The RSA key file can be either a PEM text file or a PKCS#12 binary file (.pfx or .p12).

The deprecated RSA keys list might be removed. Use the RSA keys dialog to configure keys. To change the protocol for decrypted data, right-click a TLS packet and use "Decode As." The IP address and Port fields are not used.

Passive TLS Inspection (Client Browser Pre-Master Secret)

The IDS gets a copy of each client’s pre-master secret. Firefox and Chrome can export this secret, but Internet Explorer and Edge do not.

Wireshark's instructions for decrypting TLS traffic via the client pre-master secret:

  • Close the browser completely (check your task manager just to be sure).

  • Set environment variable SSLKEYLOGFILE to the absolute path of a writable file.

  • Start the browser.

  • Verify that the location from step 2 is created.

  • In Wireshark, go to Preferences -> Protocols -> TLS, and change the (Pre)-Master-Secret log filename preference to the path from step 2.

  • Start the Wireshark capture.

  • Open a website

  • Check that the decrypted data is visible. For example, using the tls and (http or http2) filter.

Perfect Forward Secrecy (PFS)

If you create a symmetric session key with asymmetric encryption and the private key gets hacked, are old symmetric keys safe? If other session keys are also hacked, do the others stay safe?

Perfect Forward Secrecy ensures that past symmetric session keys stay secure, even if the private key or other session keys are compromised. Some think the term "perfect" is too strong, so "forward secrecy" is also used.

Google implemented forward secrecy in their HTTPS implementation for Gmail:

Forward secrecy means that private keys for a connection aren't stored long-term. If an attacker gets one key, they can't decrypt past connections, and even the server can't unlock old HTTPS sessions.

TLS 1.3 and PFS

Network diagnostics and troubleshooting will be greatly affected. To solve complex issues, TLS decryption of network packet traces is necessary to track transactions and find problems. The visibility from out-of-band TLS decryption can't be matched by MITM setups or endpoint diagnostics. Losing this visibility will lead to long outages as support teams have to guess when facing tough problems.

Endpoint Monitoring: This method can't replace the broad network visibility that companies will lose without RSA key exchange. Keeping a monitoring agent on every endpoint is much harder than just having a network traffic inspection tool. For monitoring employee communications, moving to endpoint monitoring creates new security issues, as the main threat comes from the person using the endpoint.

Workarounds for Passively Decrypting TLS 1.3

Sticking with TLS 1.2 might work for now, but it could be hard to maintain in the future. As network interception of encrypted traffic becomes tougher, more people will likely use host-based solutions. Since clients can access unencrypted data, applications on the client can also see that data.

Passively Decrypted TLS 1.3 Traffic to https://paypal.com

The downside of the pre-master secret:

  • Firefox and Chrome are the only major graphical browsers that support this functionality. Curl also supports this functionality

  • The decrypting device must have the key log from every supported browser

Decrypting HTTPS with Interception/Inspection

Just because you can do something doesn’t mean you should or that it's legal. Privacy laws and rules differ widely around the world. Make sure to get approval for any plans to decrypt user traffic from the right people in your organization before moving forward.

Organizations are increasingly decrypting their users' outgoing traffic. This is partly because more tools for decryption are now available. Additionally, as more internet traffic becomes encrypted, organizations need to maintain visibility, which has led to greater adoption of decryption practices.

Never Decrypt All the Things

Many are eager to decrypt everything to find threats, but take a moment to consider. There may be legal rules preventing your organization from decrypting certain traffic. Even without legal issues, your organization might have policies against decrypting specific data. Generally, traffic with employee health or financial information is treated as sensitive and is not decrypted. While organizations try to avoid decrypting this type of traffic, it can depend on the tools used. Often, site categorization rules help decide what can be decrypted, but these rules aren't foolproof.

Some traffic can't be decrypted for technical reasons, even outside of legal or policy issues. Ideally, your decryption tool should have a list of apps or sites that don't work well with decryption. If it doesn't, be ready for that problem. One reason for this issue is certificate pinning, which prevents man-in-the-middle (MITM) attacks but can also cause apps to fail during TLS decryption, which acts like an authorized MITM.

Lab 2.2 - Decrypting TLS with Wireshark

Goal: decrypt TLS 1.2 traffic sent to the Sec511 Attack Map at https://www.sec511.net:8443 (running locally at 127.0.0.1:8443), using the web server's RSA private key.

In Wireshark: let's double-click on the "Loopback: lo" adapter to begin packet capture.

Wireshark will start capturing packets.

In Firefox: let's click the bookmark shortcut for SEC511 Attack Map.

Let's click the Lock icon to view the TLS connection details, then click the ">" next to "Connection secure."

Then click "More information".

Look at the "Technical Details".

This web server uses "TLS_RSA_WITH_AES_128_CBC_SHA" encryption with TLS 1.2. We can decrypt this using Wireshark if we have the server's Private RSA key. Since this is a local web server, we can easily access that key.

The server's private key is found at /etc/ssl/private/sec511_net.key. It can only be read by the root user for security reasons, so Wireshark cannot import it directly. Let's check its permissions:

sudo ls -la /etc/ssl/private/sec511_net.key

Let's copy the key to the /labs/tls directory:

sudo cp /etc/ssl/private/sec511_net.key /labs/tls

Next, we'll change the permissions so Wireshark can read it:

sudo chmod 440 /labs/tls/sec511_net.key

Then set the file's group to 'wireshark' and check the updated permissions.

sudo chgrp wireshark /labs/tls/sec511_net.key
ls -la /labs/tls/sec511_net.key

We changed the file permissions from only being readable by the root user to being readable by the root user and users in the wireshark group. This helps keep the key safe from other accounts. While this isn't crucial for this lab, it shows a better way to handle sensitive RSA private keys.

The student account is part of the Wireshark group, so we can now see the key without using sudo.

Now let's configure Wireshark to use that RSA key. In Wireshark: let's go to Edit -> Preferences

Then let's select "RSA Keys" -> "Add New keyfile…"

Next, navigate to /labs/tls/sec511_net.key, click "Open" and "OK".

Now, let's close Firefox completely and restart it to make sure it starts a new TLS session instead of continuing an old one. Then stop the capture in Wireshark by pressing the red stop square.

To start capturing again, we'll click the green shark fin icon and select "Continue without Saving."

Now, let's repoen Firefox and Inspect the decrypted TLS 1.2 traffic.

Let's enter the following display filter:

tcp.port==8443 and http

Wireshark is now able to decrypt TLS 1.2. Check any "GET" request where the destination port is 8443, and look at the "Transport Layer Security" part in the packet details section.

Let's click on any GET, and then click "Decrypted TLS".

The plain text request is shown.

Let's see the content of country_centroids_primary.csv, we'll do this by finding the GET request in the decrypted HTTP stream. Right-click on it and select Follow -> HTTP Stream. Make sure to pick "HTTP Stream."

Let's scroll down to find the CSV download.

The screenshot above shows decrypted traffic to using the browser's pre-master secret. PayPal uses HTTP/2, which looks different from HTTP/1.1. This demonstrates how the pre-master secret can decrypt TLS traffic, even for sites using TLS 1.3.

https://paypal.com