Skip to content
SecureKhan
Go back

TLS/SSL Handshake Explained: How HTTPS Works and How to Attack It

TLS/SSL Handshake Explained

TL;DR: TLS encrypts communication between client and server. Understanding the handshake helps you identify weak configurations, test certificate validation, and exploit cryptographic vulnerabilities.


Table of Contents

Open Table of Contents

Quick Reference

TLS/SSL Versions

VersionStatusSecurity
SSL 2.0Deprecated (1995)Broken - Never use
SSL 3.0Deprecated (1996)Broken (POODLE)
TLS 1.0Deprecated (1999)Weak (BEAST)
TLS 1.1Deprecated (2006)Weak
TLS 1.2Current (2008)Secure (with good ciphers)
TLS 1.3Current (2018)Most secure

Essential Commands

CommandPurposeExample
openssl s_clientTest TLS connectionopenssl s_client -connect host:443
nmap --script ssl*Scan for SSL issuesnmap --script ssl-enum-ciphers target
testssl.shComprehensive testingtestssl.sh target.com
sslscanQuick cipher scansslscan target.com
sslyzePython SSL scannersslyze target.com

Common Ports Using TLS

PortServiceProtocol
443HTTPSHTTP over TLS
465SMTPSSMTP over TLS
636LDAPSLDAP over TLS
853DoTDNS over TLS
993IMAPSIMAP over TLS
995POP3SPOP3 over TLS
8443HTTPS-altAlternative HTTPS

Why TLS Matters for Pentesters

TLS is everywhere - and misconfigurations are common.

What TLS Protects

ProtectionHowAttack If Broken
ConfidentialityEncryptionEavesdropping
IntegrityMAC/AEADData tampering
AuthenticationCertificatesImpersonation/MITM

Real-World TLS Breaches

IncidentVulnerabilityImpact
Heartbleed (2014)OpenSSL memory leakServer memory exposure, private keys
POODLE (2014)SSL 3.0 padding oracleDecrypt HTTPS traffic
DROWN (2016)SSLv2 export ciphersDecrypt TLS sessions
DigiNotar (2011)CA compromiseFake Google certificates
Let’s Encrypt (2020)Certificate misissuance3M certs revoked

What Pentesters Test

  1. Protocol versions - Deprecated SSL/TLS versions
  2. Cipher suites - Weak or export ciphers
  3. Certificate validation - Expiry, chain, hostname
  4. Known vulnerabilities - BEAST, POODLE, Heartbleed
  5. Configuration - HSTS, certificate pinning
  6. Implementation bugs - Specific library issues

TLS vs SSL: What’s the Difference

TL;DR: SSL is the old, broken protocol. TLS is the modern replacement. People say “SSL” but usually mean TLS.

History

1995 ── SSL 2.0 ── Netscape (broken, deprecated)

1996 ── SSL 3.0 ── Netscape (POODLE, deprecated)

1999 ── TLS 1.0 ── IETF standardization (BEAST, deprecated)

2006 ── TLS 1.1 ── Minor improvements (deprecated)

2008 ── TLS 1.2 ── Major improvements (current)

2018 ── TLS 1.3 ── Complete redesign (recommended)

Why It Matters

ProtocolStill SeenRisk
SSL 2.0Legacy systemsCritical
SSL 3.0Legacy systemsCritical (POODLE)
TLS 1.0Many serversHigh (BEAST, deprecated)
TLS 1.1Some serversMedium (deprecated)
TLS 1.2Most serversSafe with good ciphers
TLS 1.3Modern serversBest security

Finding deprecated protocols = finding for your pentest report.


The TLS Handshake

TL;DR: Client and server negotiate encryption, verify certificates, and establish a secure session in a carefully orchestrated exchange.

TLS 1.2 Handshake (Full)

┌─────────┐                                              ┌─────────┐
│ Client  │                                              │ Server  │
└────┬────┘                                              └────┬────┘
     │                                                        │
     │  ──────────── 1. ClientHello ─────────────────────►   │
     │     - TLS version                                      │
     │     - Random bytes (Client Random)                     │
     │     - Session ID                                       │
     │     - Cipher suites supported                          │
     │     - Compression methods                              │
     │     - Extensions (SNI, etc.)                           │
     │                                                        │
     │  ◄──────────── 2. ServerHello ────────────────────    │
     │     - TLS version selected                             │
     │     - Random bytes (Server Random)                     │
     │     - Session ID                                       │
     │     - Cipher suite selected                            │
     │     - Compression method                               │
     │                                                        │
     │  ◄──────────── 3. Certificate ────────────────────    │
     │     - Server's certificate chain                       │
     │                                                        │
     │  ◄──────────── 4. ServerKeyExchange ──────────────    │
     │     - Key exchange parameters (DHE/ECDHE)              │
     │     - Signature                                        │
     │                                                        │
     │  ◄──────────── 5. ServerHelloDone ────────────────    │
     │                                                        │
     │  ──────────── 6. ClientKeyExchange ───────────────►   │
     │     - Pre-master secret (encrypted)                    │
     │       or DH public value                               │
     │                                                        │
     │  ──────────── 7. ChangeCipherSpec ────────────────►   │
     │     - Switching to encrypted communication             │
     │                                                        │
     │  ──────────── 8. Finished ────────────────────────►   │
     │     - Encrypted verification                           │
     │                                                        │
     │  ◄──────────── 9. ChangeCipherSpec ───────────────    │
     │                                                        │
     │  ◄──────────── 10. Finished ──────────────────────    │
     │                                                        │
     │  ════════════ Encrypted Application Data ══════════   │
     │                                                        │

Key Generation Process

                    Client Random (32 bytes)
                           +
                    Server Random (32 bytes)
                           +
                    Pre-Master Secret


                   ┌───────────────┐
                   │  PRF (KDF)    │  Pseudo-Random Function
                   └───────┬───────┘

           ┌───────────────┼───────────────┐
           │               │               │
           ▼               ▼               ▼
    ┌────────────┐  ┌────────────┐  ┌────────────┐
    │ Client     │  │ Server     │  │ IV for     │
    │ Write Key  │  │ Write Key  │  │ CBC mode   │
    └────────────┘  └────────────┘  └────────────┘

Vulnerabilities in Each Step

StepVulnerabilityAttack
1. ClientHelloDowngrade attackForce weak cipher/version
2. ServerHelloProtocol selectionPOODLE, DROWN
3. CertificateValidation bypassFake certificates, MITM
4. KeyExchangeWeak parametersLogjam (weak DH), FREAK
6. KeyExchangeKey extractionHeartbleed
7-10. EncryptedPadding oracleBEAST, Lucky13

TLS 1.3 Handshake

TL;DR: TLS 1.3 is faster (1 round trip), more secure (removed weak ciphers), and simpler (fewer options to misconfigure).

TLS 1.3 vs 1.2

FeatureTLS 1.2TLS 1.3
Round trips2 RTT1 RTT (0-RTT resumption)
Key exchangeRSA, DH, ECDHECDHE, DHE only
Cipher suites37+5 AEAD only
Encryption startAfter handshakeAfter ServerHello
Removed-RSA key exchange, CBC mode, RC4, SHA-1, etc.

TLS 1.3 Handshake

┌─────────┐                                              ┌─────────┐
│ Client  │                                              │ Server  │
└────┬────┘                                              └────┬────┘
     │                                                        │
     │  ──────────── ClientHello ────────────────────────►   │
     │     - Supported versions                               │
     │     - Key shares (ECDHE)                               │
     │     - Cipher suites                                    │
     │                                                        │
     │  ◄──────────── ServerHello ───────────────────────    │
     │     - Selected version                                 │
     │     - Key share                                        │
     │                                                        │
     │  ◄──────────── EncryptedExtensions ───────────────    │
     │  ◄──────────── Certificate ───────────────────────    │
     │  ◄──────────── CertificateVerify ─────────────────    │
     │  ◄──────────── Finished ──────────────────────────    │
     │                                                        │
     │  ──────────── Finished ───────────────────────────►   │
     │                                                        │
     │  ══════════════ Application Data ══════════════════   │

What TLS 1.3 Removed

RemovedWhyAttack Prevented
RSA key exchangeNo forward secrecyPassive decryption
CBC cipher modesPadding oraclesBEAST, Lucky13
RC4 cipherBrokenRC4 biases
SHA-1 for signaturesCollision attacksSignature forgery
Static DHNo forward secrecyKey compromise
CompressionCRIME attackSession hijacking
RenegotiationComplex attacksVarious

Certificates and PKI

TL;DR: Certificates prove server identity. The chain of trust goes from server cert → intermediate CA → root CA (trusted by your browser).

Certificate Chain

┌─────────────────────────────────────────────────────────────────┐
│                        Root CA Certificate                       │
│              (Self-signed, in browser/OS trust store)            │
│                      DigiCert, Let's Encrypt, etc.               │
└───────────────────────────────┬─────────────────────────────────┘
                                │ Signs

┌─────────────────────────────────────────────────────────────────┐
│                   Intermediate CA Certificate                    │
│              (Signed by Root, signs end-entity certs)            │
└───────────────────────────────┬─────────────────────────────────┘
                                │ Signs

┌─────────────────────────────────────────────────────────────────┐
│                   End-Entity Certificate                         │
│                    (Server's certificate)                        │
│              Subject: CN=www.example.com                         │
└─────────────────────────────────────────────────────────────────┘

Certificate Fields

FieldPurposeExample
SubjectWho the cert belongs toCN=www.example.com
IssuerWho signed the certCN=DigiCert SHA2 CA
ValidityNot Before/After datesJan 1 - Dec 31, 2024
Public KeyServer’s public keyRSA 2048-bit
SignatureCA’s signatureSHA256withRSA
SANAdditional hostnamesDNS:example.com, DNS:*.example.com
Key UsageAllowed operationsDigital Signature, Key Encipherment

Certificate Validation Checks

CheckFailure ImpactAttack
Chain of trustReject connectionSelf-signed cert MITM
ExpirationWarning/rejectExpired cert exploitation
Hostname matchRejectWrong certificate
Revocation (CRL/OCSP)VariesUse revoked cert
Key usageRejectMisuse certificate
View Certificate Commands
# View certificate with openssl
openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | \
    openssl x509 -noout -text

# View certificate dates
openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | \
    openssl x509 -noout -dates

# View certificate chain
openssl s_client -connect example.com:443 -servername example.com -showcerts

# Check certificate SANs
openssl s_client -connect example.com:443 2>/dev/null | \
    openssl x509 -noout -ext subjectAltName

# View certificate with curl
curl -vI https://example.com 2>&1 | grep -A6 "Server certificate"

# Check certificate expiry
echo | openssl s_client -connect example.com:443 2>/dev/null | \
    openssl x509 -noout -enddate

Cipher Suites Explained

TL;DR: A cipher suite is a combination of algorithms for key exchange, authentication, encryption, and message integrity.

Cipher Suite Naming

TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
│    │     │        │   │   │    │
│    │     │        │   │   │    └── Hash for PRF
│    │     │        │   │   └─────── Mode (GCM = AEAD)
│    │     │        │   └─────────── Key size
│    │     │        └─────────────── Encryption algorithm
│    │     └──────────────────────── Authentication (cert type)
│    └────────────────────────────── Key exchange
└─────────────────────────────────── Protocol

Cipher Suite Components

ComponentOptionsRecommendation
Key ExchangeRSA, DHE, ECDHEECDHE (forward secrecy)
AuthenticationRSA, ECDSAEither is fine
EncryptionAES, ChaCha20, 3DES, RC4AES-GCM or ChaCha20
ModeCBC, GCM, CCMGCM (AEAD)
MACSHA, SHA256, SHA384SHA256+ or AEAD

TLS 1.3 Cipher Suites (Only 5)

Cipher SuiteSecurity
TLS_AES_128_GCM_SHA256Recommended
TLS_AES_256_GCM_SHA384Recommended
TLS_CHACHA20_POLY1305_SHA256Recommended
TLS_AES_128_CCM_SHA256OK
TLS_AES_128_CCM_8_SHA256IoT only

Weak Cipher Indicators

IndicatorWhy WeakExample
NULLNo encryptionTLS_RSA_WITH_NULL_SHA
EXPORTIntentionally weakTLS_RSA_EXPORT_WITH_RC4_40_MD5
RC4Broken stream cipherTLS_RSA_WITH_RC4_128_SHA
DES / 3DESWeak block cipherTLS_RSA_WITH_3DES_EDE_CBC_SHA
MD5Broken hash*_MD5
SHA (SHA-1)Weak hash*_SHA (without number)
RSA (no DHE)No forward secrecyTLS_RSA_WITH_AES_256_CBC_SHA
ANONNo authenticationTLS_DH_anon_WITH_AES_256_CBC_SHA
Check Cipher Suite Commands
# List supported ciphers with openssl
openssl s_client -connect example.com:443 -cipher 'ALL:COMPLEMENTOFALL'

# Check specific cipher
openssl s_client -connect example.com:443 -cipher 'AES256-SHA'

# List cipher suites with nmap
nmap --script ssl-enum-ciphers -p 443 example.com

# Using sslscan
sslscan example.com

# Using testssl.sh
testssl.sh --cipher-per-proto example.com

Common TLS Vulnerabilities

1. Heartbleed (CVE-2014-0160)

OpenSSL memory leak exposing server memory, potentially including private keys.

┌─────────┐                                     ┌─────────┐
│ Client  │  Heartbeat: "Send back 64KB"       │ Server  │
│         │ ────────────────────────────────►  │         │
│         │  (But I only sent 1 byte)          │         │
│         │                                     │         │
│         │  ◄───────────────────────────────  │         │
│         │  Response: 64KB of server memory!  │         │
│         │  (May contain private keys,        │         │
│         │   passwords, session data)         │         │
└─────────┘                                     └─────────┘
AttackDetectDefend
Send malformed heartbeatMonitor for heartbeat requestsUpdate OpenSSL
Extract server memoryLog heartbeat anomaliesDisable heartbeat extension
Obtain private keysDetect large heartbeat responsesRevoke and reissue certs
Testing Commands
# Using nmap
nmap --script ssl-heartbleed -p 443 target.com

# Using testssl.sh
testssl.sh --heartbleed target.com

# Using Metasploit
use auxiliary/scanner/ssl/openssl_heartbleed
set RHOSTS target.com
run

# Manual check with openssl
echo "QUIT" | openssl s_client -connect target.com:443 2>&1 | grep "server extension"
# If "heartbeat" appears, further testing needed

2. POODLE (CVE-2014-3566)

Padding Oracle On Downgraded Legacy Encryption - attacks SSL 3.0 CBC mode.

AttackDetectDefend
Force SSL 3.0 downgradeMonitor for SSL 3.0 connectionsDisable SSL 3.0
Exploit CBC padding oracleAlert on protocol downgradesUse TLS 1.2+ only
Decrypt HTTPS cookieDetect POODLE scan patternsUse AEAD ciphers
Testing Commands
# Check for SSL 3.0 support
openssl s_client -connect target.com:443 -ssl3

# Using nmap
nmap --script ssl-poodle -p 443 target.com

# Using testssl.sh
testssl.sh --poodle target.com

# Check for TLS POODLE (CVE-2014-8730)
testssl.sh --fallback target.com

3. BEAST (CVE-2011-3389)

Browser Exploit Against SSL/TLS - attacks TLS 1.0 CBC mode.

AttackDetectDefend
Chosen plaintext in TLS 1.0Monitor for TLS 1.0 trafficDisable TLS 1.0
Decrypt session cookiesAlert on CBC cipher useUse TLS 1.2+
Requires MITM positionLog cipher negotiationsPrefer AEAD ciphers
Testing Commands
# Check TLS 1.0 support
openssl s_client -connect target.com:443 -tls1

# Using testssl.sh
testssl.sh --beast target.com

# Check cipher preference
nmap --script ssl-enum-ciphers -p 443 target.com | grep -i "cbc"

4. CRIME & BREACH

Compression-based attacks that leak encrypted data.

CRIME - TLS compression leaks session tokens BREACH - HTTP compression leaks response body secrets

AttackDetectDefend
Measure compressed sizeMonitor compression settingsDisable TLS compression
Inject known plaintextAlert on size variationsDisable HTTP compression for sensitive data
Brute force secret bytesDetect unusual request patternsRandomize secrets in responses
Testing Commands
# Check for TLS compression (CRIME)
openssl s_client -connect target.com:443 2>/dev/null | grep "Compression"
# "Compression: NONE" = Safe
# "Compression: zlib" = Vulnerable

# Using testssl.sh
testssl.sh --crime target.com

# Check HTTP compression (BREACH)
curl -H "Accept-Encoding: gzip, deflate" -I https://target.com
# If Content-Encoding: gzip appears on sensitive pages = potentially vulnerable

5. DROWN (CVE-2016-0800)

SSLv2 enables cross-protocol attack to decrypt TLS sessions.

AttackDetectDefend
Use SSLv2 to attack TLSMonitor for SSLv2 trafficDisable SSLv2 everywhere
Bleichenbacher oracleInventory all servers sharing keysDon’t share keys across servers
Decrypt recorded TLS trafficCheck certificate reuseUse unique certificates
Testing Commands
# Check for SSLv2
openssl s_client -connect target.com:443 -ssl2

# Using nmap
nmap --script sslv2-drown -p 443 target.com

# Using testssl.sh
testssl.sh --drown target.com

6. Logjam (CVE-2015-4000)

Weak Diffie-Hellman parameters allow MITM attacks.

AttackDetectDefend
Attack 512-bit export DHMonitor for DHE key sizesUse 2048-bit+ DH groups
Downgrade to export ciphersAlert on weak parametersDisable DHE_EXPORT ciphers
Precompute discrete logLog key exchange parametersPrefer ECDHE
Testing Commands
# Check DH parameters
openssl s_client -connect target.com:443 -cipher "EDH" 2>/dev/null | grep "Server Temp Key"

# Using nmap
nmap --script ssl-dh-params -p 443 target.com

# Using testssl.sh
testssl.sh --logjam target.com

7. FREAK (CVE-2015-0204)

Factoring RSA Export Keys - downgrade to 512-bit RSA.

AttackDetectDefend
Force RSA_EXPORT cipherMonitor for export ciphersDisable EXPORT ciphers
Factor weak RSA keyAlert on 512-bit RSARequire 2048-bit+ RSA
Decrypt trafficLog cipher negotiationsUpdate SSL libraries
Testing Commands
# Check for EXPORT ciphers
openssl s_client -connect target.com:443 -cipher EXPORT

# Using testssl.sh
testssl.sh --freak target.com

8. ROBOT (CVE-2017-13099)

Return Of Bleichenbacher’s Oracle Threat - RSA key exchange attack.

AttackDetectDefend
Padding oracle on RSAMonitor decryption errorsUse ECDHE key exchange
Decrypt TLS trafficAlert on timing variationsDisable RSA key exchange
Forge signaturesLog RSA operationsUpdate SSL libraries
Testing Commands
# Using testssl.sh
testssl.sh --robot target.com

# Using robot-detect tool
python robot-detect.py -h target.com -p 443

Vulnerability Summary

VulnerabilityAffectedSeverityFix
HeartbleedOpenSSL 1.0.1-1.0.1fCriticalUpdate OpenSSL
POODLESSL 3.0HighDisable SSL 3.0
BEASTTLS 1.0 + CBCMediumUse TLS 1.2+
CRIMETLS compressionMediumDisable compression
BREACHHTTP compressionMediumDisable for secrets
DROWNSSLv2HighDisable SSLv2
LogjamDHE < 1024 bitHighUse 2048+ bit DH
FREAKEXPORT ciphersHighDisable EXPORT
ROBOTRSA key exchangeHighUse ECDHE

Testing TLS Configuration

Testing Checklist

AttackDetectDefend
Protocol downgradeLog TLS version negotiationDisable old protocols
Cipher downgradeMonitor cipher selectionConfigure cipher preference
Certificate issuesMonitor cert expiryAutomate renewal
Missing HSTSCheck headersEnable HSTS with long max-age
Comprehensive Testing Commands
# === Protocol Version Testing ===

# Test each protocol version
openssl s_client -connect target.com:443 -ssl3    # Should fail
openssl s_client -connect target.com:443 -tls1    # Should fail
openssl s_client -connect target.com:443 -tls1_1  # Should fail
openssl s_client -connect target.com:443 -tls1_2  # Should work
openssl s_client -connect target.com:443 -tls1_3  # Should work

# === Cipher Suite Testing ===

# Enumerate all ciphers
nmap --script ssl-enum-ciphers -p 443 target.com

# Check for weak ciphers
openssl s_client -connect target.com:443 -cipher 'NULL:EXPORT:LOW:DES:RC4:MD5:ANON'
# Should fail if properly configured

# Check cipher preference
testssl.sh --server-preference target.com

# === Certificate Testing ===

# View full certificate details
echo | openssl s_client -connect target.com:443 2>/dev/null | \
    openssl x509 -text -noout

# Check certificate expiry
echo | openssl s_client -connect target.com:443 2>/dev/null | \
    openssl x509 -dates -noout

# Verify certificate chain
openssl s_client -connect target.com:443 -verify 5

# Check hostname match
openssl s_client -connect target.com:443 -verify_hostname target.com

# === Vulnerability Testing ===

# Comprehensive test with testssl.sh
testssl.sh target.com

# Quick vulnerability scan
testssl.sh --vulnerable target.com

# Specific checks
testssl.sh --heartbleed --poodle --beast --logjam --drown target.com

# === Header Testing ===

# Check HSTS
curl -sI https://target.com | grep -i "strict-transport"

# Check all security headers
curl -sI https://target.com | grep -iE "(strict-transport|x-frame|x-content|x-xss|content-security)"

Certificate Attacks

1. Self-Signed Certificate Acceptance

If client accepts self-signed certs, MITM is trivial.

AttackDetectDefend
Present self-signed certMonitor for self-signed alertsReject self-signed in production
MITM with custom CALog certificate warningsCertificate pinning
Strip TLS entirelyDetect HTTP downgradeHSTS preloading
Testing Commands
# Generate self-signed certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
    -subj "/CN=target.com"

# Test with mitmproxy using self-signed
mitmproxy --cert cert.pem

# Check if client accepts invalid cert
# If app doesn't error on self-signed = vulnerable

2. Certificate Pinning Bypass

Mobile apps often pin certificates. Bypassing enables MITM.

AttackDetectDefend
Frida/Objection bypassMonitor for hooking attemptsCertificate pinning
Modify APK/IPADetect app tamperingRoot/jailbreak detection
Use rooted/jailbroken deviceLog connection anomaliesBinary protections
Bypass Commands
# Using Frida with objection
objection --gadget com.target.app explore
# Then: android sslpinning disable

# Using Frida script
frida -U -f com.target.app -l ssl-unpin.js

# Using apktool + modification
apktool d app.apk
# Modify network_security_config.xml
apktool b app -o app-modified.apk

3. Hostname Verification Bypass

If client doesn’t verify hostname matches certificate.

AttackDetectDefend
Use valid cert for wrong domainMonitor for hostname mismatchesStrict hostname verification
Wildcard abuseLog certificate warningsValidate full hostname
Null byte injectionDetect unusual CNsUse modern TLS libraries

MITM and TLS Interception

TLS Interception Setup

┌─────────┐                    ┌──────────┐                    ┌─────────┐
│ Client  │ ◄─── TLS 1 ──────►│  Proxy   │◄───── TLS 2 ──────►│ Server  │
│         │   (Proxy's cert)   │  (MITM)  │   (Server's cert)  │         │
└─────────┘                    └──────────┘                    └─────────┘

Tools for TLS Interception

ToolUse CaseCommand
mitmproxyInteractive HTTP/HTTPS proxymitmproxy
Burp SuiteWeb app testingGUI-based
sslsplitTransparent MITMsslsplit -D -k key.pem -c cert.pem ssl 0.0.0.0 8443
bettercapNetwork MITMbettercap -iface eth0
MITM Setup Commands
# === mitmproxy Setup ===

# Start mitmproxy
mitmproxy

# Install CA cert on client (from http://mitm.it when connected)

# Transparent mode
mitmproxy --mode transparent

# === Burp Suite Setup ===

# 1. Start Burp
# 2. Configure browser proxy: 127.0.0.1:8080
# 3. Export CA: Proxy > Options > CA Certificate > Export
# 4. Install CA in browser/system

# === sslsplit Setup ===

# Generate CA
openssl genrsa -out ca.key 2048
openssl req -new -x509 -key ca.key -out ca.crt -days 365

# Run sslsplit
sslsplit -D -l connections.log -j /tmp/sslsplit -S /tmp/sslsplit/logs \
    -k ca.key -c ca.crt ssl 0.0.0.0 8443

# Redirect traffic (iptables)
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443

Tools for TLS Testing

Command Line Tools

ToolPurposeInstall
testssl.shComprehensive TLS testinggit clone https://github.com/drwetter/testssl.sh
sslscanQuick cipher scanapt install sslscan
sslyzePython-based scannerpip install sslyze
nmap ssl scriptsNSE scripts for TLSBuilt into nmap
opensslManual testingapt install openssl

Online Tools

ToolURLUse
SSL Labsssllabs.com/ssltestComprehensive grading
Hardenizehardenize.comSecurity posture
ImmuniWebimmuniweb.com/sslFree SSL test
Observatoryobservatory.mozilla.orgMozilla’s scanner
CryptCheckcryptcheck.frFrench scanner

Browser Extensions

ExtensionPurpose
HTTPS EverywhereForce HTTPS
Certificate PatrolDetect cert changes
CipherfoxShow connection ciphers
Tool Usage Examples
# === testssl.sh ===

# Full test
./testssl.sh target.com

# Quick check
./testssl.sh --fast target.com

# Specific checks
./testssl.sh --protocols --ciphers target.com

# JSON output
./testssl.sh --jsonfile results.json target.com

# === sslscan ===

# Basic scan
sslscan target.com

# Show certificate
sslscan --show-certificate target.com

# Check specific port
sslscan --port=8443 target.com

# === sslyze ===

# Regular scan
sslyze target.com

# All checks
sslyze --regular target.com

# JSON output
sslyze --json_out=results.json target.com

# === nmap ===

# Enumerate ciphers
nmap --script ssl-enum-ciphers -p 443 target.com

# All SSL scripts
nmap --script "ssl-*" -p 443 target.com

# Specific vulnerability
nmap --script ssl-heartbleed -p 443 target.com

Practice Labs

Beginner

ResourceFocusLink
TryHackMe - CryptographyTLS basicstryhackme.com
CryptopalsCrypto challengescryptopals.com
HackTheBox AcademyTLS fundamentalsacademy.hackthebox.com

Intermediate

ResourceFocus
PortSwigger - Web Security AcademyTLS attacks
PentesterLabCertificate issues
DVWAHTTPS testing

Advanced

ResourceFocus
Root MeCryptography challenges
HackTheBoxReal-world machines
CTF challengesVarious TLS attacks

Home Lab Setup

# Create vulnerable TLS server for testing

# 1. Generate certificates
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

# 2. Run server with weak configuration (for testing only!)
openssl s_server -accept 4433 \
    -cert server.crt -key server.key \
    -ssl3 \
    -cipher 'ALL:COMPLEMENTOFALL'

# 3. Test against it
testssl.sh localhost:4433

Glossary

TermDefinition
AEADAuthenticated Encryption with Associated Data (GCM, CCM)
CACertificate Authority - issues certificates
CBCCipher Block Chaining - encryption mode
Certificate ChainPath from end-entity cert to root CA
Cipher SuiteCombination of algorithms for TLS
CRLCertificate Revocation List
DHEDiffie-Hellman Ephemeral - key exchange
ECDHEElliptic Curve DHE - faster key exchange
Forward SecrecyPast sessions safe if key compromised
GCMGalois/Counter Mode - AEAD cipher mode
HandshakeTLS negotiation process
HSTSHTTP Strict Transport Security
OCSPOnline Certificate Status Protocol
PKIPublic Key Infrastructure
Pre-Master SecretShared secret before key derivation
SNIServer Name Indication - hostname in TLS
TLSTransport Layer Security
X.509Certificate format standard

What’s Next?

Now that you understand TLS, continue your learning path:

TopicDescriptionLink
DNS Deep DiveHow DNS works and attacksDNS Deep Dive
Encoding vs Encryption vs HashingKnow the differencesComing Soon
PKI & CertificatesDeep dive into certificate infrastructureComing Soon
Web App PentestingApply TLS knowledge to web testingWeb App Pentesting Guide

Summary

TLS/SSL security is critical for penetration testing:

  1. Handshake - Understand the negotiation process and where attacks occur
  2. Versions - Ensure only TLS 1.2+ is supported
  3. Cipher Suites - Remove weak ciphers, prefer AEAD
  4. Certificates - Validate chain, expiry, hostname, revocation
  5. Vulnerabilities - Test for Heartbleed, POODLE, BEAST, DROWN, etc.
  6. MITM - Understand interception for testing and attack scenarios

Always include TLS configuration testing in your engagements. Weak TLS is a common finding that demonstrates real security risk.


Found this guide helpful? Check out the other posts in the SecureKhan penetration testing series.


Share this post on:

Previous Post
Encoding vs Encryption vs Hashing: A Pentester's Guide
Next Post
DNS Deep Dive for Pentesters: How DNS Works and How to Attack It