SECURITY ENGINEERING · PART 2 · NETWORKING FOR SECURITY · ATTACKS · 27 OF 229

SSL Stripping, Downgrade Attacks and HSTS

TLS is strong, so attackers go around it: SSL stripping keeps the victim on plain HTTP, downgrade attacks push a connection to an old weak version, fake or mis-issued certificates impersonate the site, and bad configuration undoes the rest. The fixes: HSTS and preload, modern TLS versions only, certificate validation, and testing your own servers.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Stripping, downgrade, fake certificates, validation switched off
  • HSTS and preload
  • modern versions only
  • test your config

Notes

SSL stripping

The classic detour is SSL stripping. When you type a bare site name, the browser may try plain HTTP first, and the site answers with a redirect to HTTPS. An attacker in the middle swallows that redirect. They hold an encrypted connection to the real site and a plain one to you, relaying everything and reading all of it. There is no certificate warning, because no certificate is involved on your side. Only a missing padlock.

How stripping works
  • you type shop.example: the browser tries http:// first
  • the site would redirect to https:// the attacker in the middle swallows that redirect
  • they talk HTTPS to the site and plain HTTP to you
  • no warning: just no padlock

HSTS

The fix is HSTS, a response header that tells the browser: for the next year, never speak plain HTTP to this site. From then on the browser rewrites every request to HTTPS before it leaves the machine, so there is no first plain request to intercept. It also removes the option to click through certificate errors for that site. One header, set once at the edge, closes the stripping attack.

HTTP Strict Transport Security
Strict-Transport-Security:
  max-age=31536000;
  includeSubDomains; preload

the browser remembers: for a
year, turn every http:// into
https:// before sending, and
refuse to click through
certificate errors

Preload

HSTS has one gap. The browser must see the header once before it applies, so the very first visit is still exposed. The answer is the preload list, a list of domains built into browsers themselves, so HTTPS is forced from the first connection ever. One warning before you turn it on: with include subdomains, any forgotten internal subdomain still on plain HTTP stops working, and removal from the list is slow. Check first.

The first-visit gap
  • HSTS only works after the browser has seen the header
  • the first visit ever is still exposed
  • preload list: browsers ship with your domain built in careful: includeSubDomains breaks any subdomain still on HTTP

Downgrade attacks

The second detour is the downgrade. TLS begins with a negotiation, where both sides agree on a protocol version and a cipher. An attacker in the middle interferes so that they settle on the oldest, weakest option both still support. Several famous attacks worked exactly this way. The lesson is simple: a server is only as strong as the weakest version it still accepts. Disable the old ones, and there is nothing to downgrade to.

Downgrades
  • TLS negotiates a version and a cipher both sides support
  • an attacker interferes so they settle on an old, weak one named attacks: POODLE (SSL 3), FREAK, Logjam
  • fix: do not support the old versions at all TLS 1.3 protects the negotiation itself

Server settings

A correct server accepts TLS one point two and 1.3 and nothing older. It prefers ciphers with forward secrecy, so a stolen key cannot decrypt recorded past traffic. It redirects plain HTTP to HTTPS and sends HSTS. You do not need to design this yourself. Mozilla publishes a configuration generator with tested settings for every common web server, and using a known-good template beats hand-picking ciphers every time.

Modern TLS configuration
  • TLS 1.2 and 1.3 only off: SSL 3, TLS 1.0, TLS 1.1
  • forward-secret ciphers (ECDHE), AEAD (GCM, ChaCha20)
  • redirect port 80 to HTTPS
  • HSTS on use a known-good template (Mozilla SSL config tool)

Certificate attacks

The third detour is impersonation. TLS proves who you are talking to only if the certificate check is real. An attacker can present a self-signed certificate and hope the user clicks through. A certificate authority can be tricked into issuing one for your domain. A rogue root certificate can be installed on a device. And far too much code simply switches validation off. Defend with CAA records and by monitoring certificate transparency logs.

Impersonating the site
  • self-signed or wrong-name certificate: browser warns
  • a certificate authority tricked or hacked into issuing one a rogue root CA installed on the device
  • code that skips validation: verify=False
  • defense: CAA, certificate transparency monitoring

In code

The most common TLS weakness is not on the server. It is in application code and scripts that turn certificate validation off to make an error go away: verify equals false, curl with minus k, a trust manager that accepts everything. That connection is encrypted to whoever answers, including an attacker. The correct fix is always the certificate or the trust store. Search your codebase for these patterns; static analysis tools flag them.

Never ship this
requests.get(url, verify=False)
curl -k https://...
rejectUnauthorized: false
a TrustManager that accepts all

it "fixes" the error by
removing the protection
fix the certificate or the
trust store instead

Test yourself

All of this can be measured from the outside, on servers you own. Nmap's cipher script lists every protocol version and cipher a server accepts. A tool called testssl gives a full report with known weaknesses flagged, and public scanners grade a site from A to F. A one-line curl shows whether the HSTS header is present. Run these in your pipeline, so a config change that re-enables an old version is caught the same day.

Check your own servers
# what does the server accept?
nmap --script ssl-enum-ciphers \
  -p 443 your.site
# full report
testssl.sh your.site
# headers
curl -sI https://your.site |
  grep -i strict-transport

Common mistakes

Mistakes. No HSTS header. Old TLS versions left on for one ancient client. Certificate validation disabled in code. Internal sites with broken certificates that train every employee to click past warnings. Certificates that expire because renewal is manual. Mixed content, where an HTTPS page loads a script over HTTP. And exempting internal services from all of it, as if attackers never get inside.

Avoid these
  • no HSTS
  • TLS 1.0 and 1.1 still on
  • validation disabled in code
  • users trained to click past warnings
  • expired certificates
  • mixed content: HTTP scripts on an HTTPS page
  • internal services exempt

Say it like this

In the interview: SSL stripping is a man in the middle keeping the victim on plain HTTP by intercepting the redirect to HTTPS, while speaking HTTPS to the real site. HSTS prevents it by making the browser use HTTPS only, and preloading covers the first visit. Beyond that I allow only TLS one point two and 1.3, enforce certificate validation in all code, and scan my own configuration regularly.

In the interview
  • "A man in the middle keeps the victim on plain HTTP by eating
  • the redirect to HTTPS. HSTS
  • makes the browser use HTTPS
  • only, and preload covers the first visit. I also allow only TLS 1.2 and 1.3, enforce
  • certificate validation, and scan my own config."

Interview questions

Q1What is SSL stripping?

A man-in-the-middle attack that intercepts the initial plain HTTP request and the redirect to HTTPS, keeping the victim on HTTP while the attacker speaks HTTPS to the real site, so all traffic is readable without any certificate warning.

Q2What is HSTS and how does it work?

HTTP Strict Transport Security is a response header telling the browser to use only HTTPS for the domain for max-age seconds. The browser upgrades all requests before sending them and blocks click-through on certificate errors.

Q3What problem does HSTS preloading solve?

HSTS only applies after the browser has received the header once, so the first visit is exposed. Preloading adds the domain to a list built into browsers so HTTPS is enforced from the very first connection.

Q4What is a TLS downgrade attack?

An attacker interferes with the handshake so client and server negotiate an older protocol version or weaker cipher that can be attacked. The defense is to disable old versions entirely; TLS 1.3 also protects the negotiation against tampering.

Q5Which TLS versions should a server support today?

TLS 1.2 and TLS 1.3 only. SSL 3.0, TLS 1.0 and TLS 1.1 are deprecated and should be disabled, with forward-secret AEAD cipher suites preferred.

Q6Why is disabling certificate validation dangerous?

Without validation the client encrypts to whoever presents any certificate, so a man in the middle can impersonate the server and read everything. Options such as verify=False or curl -k remove the authentication that makes TLS meaningful.

Q7What is forward secrecy?

A property of key exchanges such as ECDHE where each session uses temporary keys, so stealing the server’s long-term private key later does not allow decryption of previously recorded traffic.

Q8How do you check a server’s TLS configuration?

With tools such as testssl.sh, nmap --script ssl-enum-ciphers or a public TLS scanner, which list accepted protocol versions and ciphers and flag known weaknesses; and by checking the Strict-Transport-Security header with curl.