janlele91
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Portswigger Web Cache Poisoning 🥶 <style>body {text-align: justify}</style> Hi, dưới đây là writeup của 13/13 bài lab về lỗ hổng [Web Cache Poisoning](https://portswigger.net/web-security/web-cache-poisoning) mình đã solve trong quá trình ôn tập thi chứng chỉ của Portswigger. ### 1. Web cache poisoning with an unkeyed header ##### Description > This lab is vulnerable to web cache poisoning because it handles input from an unkeyed header in an unsafe way. An unsuspecting user regularly visits the site's home page. To solve this lab, poison the cache with a response that executes `alert(document.cookie)` in the visitor's browser. ##### Writeup Dùng Param Miner scan thì thấy [X-Forwarded-Host](https://stackoverflow.com/questions/19084340/real-life-usage-of-the-x-forwarded-host-header) bị unkeyed bởi cache. ![](https://i.imgur.com/Df8G3Qs.png) ![](https://i.imgur.com/me5WHaB.png) Ngoài ra value của header X-Forwarded-Host được thêm vào `src` của tag script. ![](https://i.imgur.com/LosnaK1.png) Dựa vào đó, gửi request với X-Forwarded-Host có giá trị như sau: `abc.com"></script><script>alert(document.cookie);</script>` ![](https://i.imgur.com/Hwa4t0s.png) Gửi đến khi `X-Cache: hit`. ![](https://i.imgur.com/Zjcihbk.png) Show response thấy alert thành công. ![](https://i.imgur.com/IfIkUMW.png) Khi victim truy cập trang chủ cũng sẽ bị alert do nhận response từ cache. Ta solve thành công challenge. ![](https://i.imgur.com/nnJ3dt3.png) ### 2. Web cache poisoning with an unkeyed cookie ##### Description > This lab is vulnerable to web cache poisoning because cookies aren't included in the cache key. An unsuspecting user regularly visits the site's home page. To solve this lab, poison the cache with a response that executes `alert(1)` in the visitor's browser ##### Writeup Ứng dụng này không include cookie vào cache keys. Trong đó có cookie `fehost` được chèn trực tiếp giá trị vào script. ![](https://i.imgur.com/YnU3bEu.png) Thực hiện gửi request với cookie `fehost=abc` kèm theo cache buster bằng `?abc=1`, ta thấy chuỗi `abc` đã được thêm vào script. ![](https://i.imgur.com/ghtVrP8.png) Gửi thêm đến khi `X-Cache: hit`. ![](https://i.imgur.com/uWkAZbs.png) Lúc này khi query đến `/?abc=1` mà không chứa cookie `fehost` thì mình vẫn nhận được cached response giống với response ở trên. Bây giờ, xóa cache buster và gửi request với `fehost=abc"-alert(1)-"abc` để inject XSS. ![](https://i.imgur.com/MhB3wug.png) Gửi thêm đến khi `X-Cache: hit`. ![](https://i.imgur.com/02nS16Q.png) Show response thử thì ta thấy alert thành công. ![](https://i.imgur.com/W6gaeRR.png) Lúc này victim truy cập trang chủ và nhận được cached response chứa XSS payload &rarr; ta solve được challenge. ![](https://i.imgur.com/wm8KADR.png) ### 3. Web cache poisoning with multiple headers ##### Description > This lab contains a web cache poisoning vulnerability that is only exploitable when you use multiple headers to craft a malicious request. A user visits the home page roughly once a minute. To solve this lab, poison the cache with a response that executes `alert(document.cookie)` in the visitor's browser. ##### Writeup Sử dụng Param Miner ta thấy cache unkey header `X-Forwared-Scheme`. ![](https://i.imgur.com/TmHRMa9.png) Sử dụng cache buster `?abcd=1` và test thử với `X-Forwared-Scheme: https` thì thấy vẫn nhận response bình thường. ![](https://i.imgur.com/rLSNmaZ.png) Tuy nhiên khi gửi `X-Forwared-Scheme` khác `https` thì sẽ được trả về 302 và redirect về `https`. ![](https://i.imgur.com/6UbO6pw.png) Tận dụng thêm 1 unkeyed header `X-Forwarded-Host` kết hợp với `X-Forwared-Scheme` khác `https`, ta có thể redirect user về đường dẫn `https://<X-Forwarded-Host>/?abcd=1`. ![](https://i.imgur.com/3dts6Kz.png) Như vậy ta chỉ cần tạo exploit server chứa đoạn script XSS về truyền địa chỉ vào `X-Forwarded-Host`, ta sẽ trigger được XSS. ![](https://i.imgur.com/5zqYtz9.png) Tuy nhiên exploit server không cho phép thiết lập như vậy tại `/`. Ta phải tìm endpoint khác. Để ý rằng khi load trang chủ ứng dụng thì sẽ có request đến `/resources/js/tracking.js`. Đường dẫn này cũng được cached (dựa vào `X-Cache`). ![](https://i.imgur.com/eARaPO6.png) Do đó ta sẽ tạo exploit server với đường dẫn tương tự nhưng chứa XSS payload. ![](https://i.imgur.com/PspKYBu.png) Thực hiện các bước chèn: - X-Forwarded-Host: `<EXPLOIT-SERVER>` - X-Forwarded-Scheme: khác HTTPS và gửi request đến `/resources/js/tracking.js`, ta redirect được user về exploit-server chứa XSS payload. Gửi request đến khi được cached. ![](https://i.imgur.com/oOqDSZl.png) Do các header trên không được keyed nên victim truy cập trang chủ &rarr; load đường dẫn trên &rarr; được nhận cached response &rarr; bị XSS. ![](https://i.imgur.com/Tc3tMEf.png) Như vậy ta solve được challenge. ![](https://i.imgur.com/FcxnQej.png) ### 4. Targeted web cache poisoning using an unknown header ##### Description > This lab is vulnerable to web cache poisoning. A victim user will view any comments that you post. To solve this lab, you need to poison the cache with a response that executes `alert(document.cookie)` in the visitor's browser. However, you also need to make sure that the response is served to the specific subset of users to which the intended victim belongs. ##### Writeup Param Miner chỉ ra cache của ứng dụng ignore `X-Host` header. ![](https://i.imgur.com/owrQD9X.png) Ngoài ra, giá trị của `X-Host` được chèn vào `src` của tag script. ![](https://i.imgur.com/Yp8AeKi.png) Như vậy ta đã xác định được unkeyed header và ta có thể chèn XSS payload ở đó. ![](https://i.imgur.com/7U5ZjEX.png) Ứng dụng còn cho biết `User-Agent` là 1 cache key nhờ vào header `Vary` tại response. Bây giờ ta chỉ cần đi tìm `User-Agent` của nạn nhân để thực hiện web cache poisoning với chỉ user này thôi. ![](https://i.imgur.com/8r3wUkW.png) Ta thấy các bài post có chức năng comment với comment có thể là HTML code. ![](https://i.imgur.com/MDNjk2t.png) ![](https://i.imgur.com/dmC8wCl.png) Bây giờ ta chỉ cần chèn payload sau để khi victim xem comment thì sẽ request đến exploit-server: `<img src="https://<EXPLOIT-SERVER>">`. Sau khi comment và đợi 1 chút, check log của exploit server ta thấy request từ victim chứa `User-Agent`. ![](https://i.imgur.com/36opmi4.png) Lấy `User-Agent` đó kèm theo `X-Host` là XSS payload, ta đã có thể poison cache thành công với victim đã xác định. Nhớ là phải gửi đến khi `X-Cache: hit`. ![](https://i.imgur.com/uZ0AmsN.png) Như vậy ta solve được challenge. ![](https://i.imgur.com/rLadk5A.png) ### 5. Web cache poisoning via an unkeyed query string ##### Description > This lab is vulnerable to web cache poisoning because the query string is unkeyed. A user regularly visits this site's home page using Chrome. To solve the lab, poison the home page with a response that executes `alert(1)` in the victim's browser. ##### Writeup Gửi request đến `/` với query string `abc=1` thì thấy cả URL chứa query string được gán vào `href` của link canonical &rarr; có thể XSS. Ngoài ra, khi ta thay đổi query string thì `X-Cache: hit` chứng tỏ query string không thuộc cache keys. ![](https://i.imgur.com/acNHYs5.png) Khi đó ta sẽ không thể dùng cache buster trên param. Thử nghiệm ta thấy sử dụng cache buster tại header Origin thành công khi server trả về `X-Cache: miss` &rarr; Origin là 1 cache key. Gửi thêm với param `abc=1` cho đến khi chứng tỏ mình nhận được response từ cache (`X-Cache: hit`). ![](https://i.imgur.com/24hbMB0.png) Lúc này truy cập `/` với cùng cache buster ta thấy param `abc=1` vẫn tồn tại trong link canonical. ![](https://i.imgur.com/HyXVgV6.png) Tương tự các bước trên ta thử param là XSS payload như dưới. Gửi với cache buster cho đến khi `X-Cache: hit`. ![](https://i.imgur.com/Pq7yZ4c.png) Truy cập `/` với cùng cache buster ta thấy payload XSS vẫn được load thành công. &rarr; Ta đã poison cache thành công. ![](https://i.imgur.com/I5vuUbS.png) Bây giờ chỉ việc gửi XSS payload qua query string tương tự ở trên cho đến khi `X-Cache: hit`. ![](https://i.imgur.com/U8VBNY3.png) Đợi victim truy cập `/` và ta solve được challenge. ![](https://i.imgur.com/zx0CULY.png) ### 6. Web cache poisoning via an unkeyed query parameter ##### Description > This lab is vulnerable to web cache poisoning because it excludes a certain parameter from the cache key. A user regularly visits this site's home page using Chrome. > > To solve the lab, poison the cache with a response that executes `alert(1)` in the victim's browser. **Chú ý:** UTM params thông thường bị ignore bởi cache. ##### Writeup Tương tự bài trên, ta dùng cache buster tại Origin header. Thử gửi request với các param `abcd=2` và `utm_content=1` cho đến khi `X-Cache:hit`. Để ý ta có thể XSS tại canonical link. ![](https://i.imgur.com/bxZLk9L.png) Xóa param `utm_content=1` đi và gửi lại request với cùng cache buster ta thấy nhận được response giống trên &rarr; cache key không chứa param `utm_content`. ![](https://i.imgur.com/A5mS2zA.png) Bắt đầu tấn công XSS bằng cách gửi request đến `/` với param `utm_content=<XSS payload>` (nhớ xóa cache buster) cho đến khi `X-Cache:hit`. ![](https://i.imgur.com/LCoYTmi.png) Xóa param `utm_content=<XSS payload>` đi và send lại request ta thấy XSS payload vẫn được load thành công. ![](https://i.imgur.com/FT85J9m.png) Victim chắc chắn bị dính XSS khi truy cập cache version của trang chủ &rarr; ta solve được challenge. ![](https://i.imgur.com/RHKyEX5.png) ### 7. Parameter cloaking ##### Description > This lab is vulnerable to web cache poisoning because it excludes a certain parameter from the cache key. There is also inconsistent parameter parsing between the cache and the back-end. A user regularly visits this site's home page using Chrome. > > To solve the lab, use the parameter cloaking technique to poison the cache with a response that executes alert(1) in the victim's browser. ##### Writeup Mỗi khi load trang chủ thì một hàm `setCountryCookie()` được thực thi từ file `/js/geolocate.js` bằng tham số `callback`. ![](https://i.imgur.com/jwEDXW5.png) Sử dụng cache buster tại Origin header. Gửi request đến khi `X-Cache: Hit`. ![](https://i.imgur.com/CLveNB7.png) Sử dụng cùng cache buster, ta thấy UTM params bị unkeyed bởi cache. ![](https://i.imgur.com/wTvm9Zq.png) Sử dụng kĩ thuật parameter cloaking với tham số callback với payload sau: ``` /js/geolocate.js?callback=setCountryCookie&utm_content=1;callback=alert(1) ``` Gửi lần đầu ta thấy, hàm `alert(1)` đã được gọi &rarr; Server chấp nhận tham số `callback=alert(1)` cuối cùng chứ không phải `callback=setCountryCookie`. ![](https://i.imgur.com/qy8mGc7.png) Gửi đến khi `X-Cache: Hit`. ![](https://i.imgur.com/ysLd61b.png) Đối với cache, khi query cùng cache buster với mỗi param `callback=setCountryCookie` thì được trả về cache version của request trên chứa `alert(1)` &rarr; nó ignore luôn `utm_content=1;callback=alert(1)` vì nó coi đây chỉ là 1 tham số `utm_content`. ![](https://i.imgur.com/lvbmskx.png) Bây giờ xóa cache buster và sử dụng parameter cloaking payload ở trên. ![](https://i.imgur.com/dV2PERc.png) Load lại đường dẫn `/js/geolocate.js?callback=setCountryCookie` ta thấy alert(1) được gọi. ![](https://i.imgur.com/RxJYZg2.png) Victim sẽ bị dính `alert(1)` khi load trang chủ &rarr; ta solve được challenge. ![](https://i.imgur.com/Lvj6mg4.png) ### 8. Web cache poisoning via a fat GET request ##### Description > This lab is vulnerable to web cache poisoning. It accepts GET requests that have a body, but does not include the body in the cache key. A user regularly visits this site's home page using Chrome. > > To solve the lab, poison the cache with a response that executes `alert(1)` in the victim's browser. ##### Writeup Tương tự bài trên ta sẽ nhắm đến tham số `callback` tại `/js/geolocate.js`. Gửi param `callback=alert(1)` dưới body với method GET và cache buster tại Origin header thì thấy hàm `alert(1)` đã được gọi. &rarr; ứng dụng chấp nhận GET requests có chứa body. (Gửi cho đến khi `X-Cache: hit`) ![](https://i.imgur.com/9b0QKhv.png) Xóa body và gửi request với cùng cache buster ta thấy hàm `alert(1)` vẫn được gọi &rarr; poison thành công. ![](https://i.imgur.com/ypkJEfC.png) Xóa cache buster và gửi request với body `callback=alert(1)` cho đến khi `X-Cache: hit` để poison cache. ![](https://i.imgur.com/jwZxmsW.png) Khi đó victim sẽ bị dính `alert(1)` khi load trang chủ &rarr; ta solve được challenge. ![](https://i.imgur.com/Jx0NrNU.png) ### 9. URL normalization ##### Description > This lab contains an XSS vulnerability that is not directly exploitable due to browser URL-encoding. > > To solve the lab, take advantage of the cache's normalization process to exploit this vulnerability. Find the XSS vulnerability and inject a payload that will execute alert(1) in the victim's browser. Then, deliver the malicious URL to the victim. ##### Writeup Khi truy cập 1 đường dẫn không tồn tại, trang web reflect lại đường dẫn đó ra output &rarr; nhìn có vẻ reflected XSS. ![](https://i.imgur.com/R5NsqGo.png) Escape tag `<p>` và thêm XSS payload vào đường dẫn như hình dưới, ta thấy alert(1) đã được thực thi. ![](https://i.imgur.com/64Jlsyn.png) ![](https://i.imgur.com/GD6IhWP.png) Tuy nhiên có 1 điều, khi mình truy cập đường dẫn này trên URL thì bị fail do browser đã url-encode payload trên rồi mới gửi server. Do đó, mình cần kết hợp lỗi của cache trong việc nomarlize URL để có thể khiến nạn nhân truy cập đường dẫn trên URL mà vẫn bị dính XSS. ![](https://i.imgur.com/49xXz43.png) Cách làm như sau: - Gửi lại request tấn công giống lúc nãy cho đến khi `X-Cache:hit`, tức là response đã được cached chứa unencoded XSS payload. ![](https://i.imgur.com/BJGVTXp.png) - Lập tức truy cập lại đường dẫn trên URL, ta XSS thành công. ![](https://i.imgur.com/ZuFaJx5.png) Giải thích: - Khi attacker gửi XSS payload qua Repeater thì không bị URL-encoded bởi proxy &rarr; server xử lí bình thường và lưu vào cache. - Khi nạn nhân truy cập malicious URL trên browser, browser sẽ URL-encode nó, nhưng khi qua bước URL normalization của cache, cache hiểu là cùng cache keys &rarr; trả về response giống như response chứa unencoded payload của attacker &rarr; bị XSS. Như vậy, ta solve được challenge. ![](https://i.imgur.com/KC4nvhw.png) ### 10. Cache key injection ##### Description > This lab contains multiple independent vulnerabilities, including cache key injection. A user regularly visits this site's home page using Chrome. > > To solve the lab, combine the vulnerabilities to execute `alert(1)` in the victim's browser. Note that you will need to make use of the `Pragma: x-get-cache-key` header in order to solve this lab. ##### Writeup Khi truy cập trang chủ, ứng dụng redirect user từ `/login?lang=en` về `/login/?lang=en`. Để ý, `/login?lang=en` sẽ có cache. Như vậy, để nạn nhân bị tấn công, ta cần gửi request sao cho match với cache key `/login?lang=en`. ![](https://i.imgur.com/OFUxb2t.png) Mặt khác, `utm-content` bị ignore bởi cache nên ta có thể dùng param này để bắt đầu poison. Sau khi redirect, trang web import 1 file js tại `/js/localize.js?lang=en&cors=0` &rarr; tham số `lang` ở đây được lấy từ URL. Request này cũng có cache hỗ trợ. ![](https://i.imgur.com/ZSCKvZp.png) Lúc này mình nảy ra ý tưởng rằng: mình sẽ cố gắng poison cache tại `/js/localize.js?lang=en&cors=0` rồi quay lại poison cache `/login?lang=en` sao cho ứng dụng load response `/js/localize.js?lang=en&cors=0` sau khi đã bị poisoned. - Poison cache tại `/js/localize.js?lang=en&cors=0`: `utm_content` cũng bị ignore bởi cache trong khi Origin là 1 cache key. ![](https://i.imgur.com/XwcxQOg.png) Thay đổi `cors=1` thì thấy mình có thể header injection khi server trả về `Access-Control-Allow-Origin` chứa giá trị chính là giá trị mình truyền ở header Origin. ![](https://i.imgur.com/stF1rpP.png) Gửi request như sau để header injection thông header `Origin` trả về `alert(1)` với `Content-Length: 8`. Lý do để tham số `x=1` mình sẽ giải thích sau. Chú ý, đây chính là bước poison nên cần gửi cho đến khi `X-Cache: hit`. ![](https://i.imgur.com/WnhMOCc.png) Sau khi đọc `X-Cache-Key`, mình có thể request lại như sau để có cùng cache key mà không can thiệp vào Origin. Mục đích của việc này là để victim truy cập vào. ![](https://i.imgur.com/cDqAz0c.png) Lúc này để ý, `x=1` được dùng để tránh khiến `cors=1$$origin...` &rarr; không thể header injection. - Poison cache tại `/login?lang=en`: Tại `/login?lang=en`, ta thực hiện truyền tham số như dưới vf gửi request đến khi `X-Cache: hit`. Khi đó ta đạt được 2 mục đích: - Cache sẽ ignore `utm_content` và chỉ chứa cache key là `/login?lang=en` &rarr; match với request nạn nhân truy cập ![](https://i.imgur.com/Boe8wfd.png) - Trang chủ sẽ import file js `/js/localize.js` với đường dẫn như sau: ![](https://i.imgur.com/vbr9Eje.png) Như đã phân tích ở trên, đường dẫn này match cache key với request poison nên nó sẽ trả về `alert(1)`. Chú ý ở đây dùng `%23 (#)` ở cuối để "cắt" `&cors=0`. Bây giờ nạn nhân truy cập trang chủ sẽ bị dính `alert(1)`. ![](https://i.imgur.com/J1vVgiP.png) ![](https://i.imgur.com/GOtewad.png) ### 11. Internal cache poisoning ##### Description > This lab is vulnerable to web cache poisoning. It uses multiple layers of caching. A user regularly visits this site's home page using Chrome. > > To solve the lab, poison the internal cache so that the home page executes `alert(document.cookie)` in the victim's browser. ##### Writeup Dùng Param Miner thấy X-Forwarded-Host được hỗ trợ bởi ứng dụng. ![](https://i.imgur.com/Cwg3K8r.png) Gửi request với `X-Forwarded-Host: abc` kèm theo dynamic cache buster (dùng Param Miner), ta thấy link canonical và địa chỉ load `analytics.js` đều trỏ về `//abc`, trong khi địa chỉ load `geolocate.js` vẫn giữ nguyên như ban đầu. ![](https://i.imgur.com/gJfjqNJ.png) Tuy nhiên, gửi thêm vài lần thì thấy địa chỉ load `geolocate.js` cũng đã trỏ về `//abc`. &rarr; fragment này được cache bởi internal cache; và query string bị unkeyed bởi internal cache do ta vẫn hit cache mặc dù cache buster tại query string thay đổi. ![](https://i.imgur.com/OlFo9cp.png) Xóa `X-Forwarded-Host: abc` và gửi lại request, ta thấy địa chỉ load `geolocate.js` vẫn trỏ về `//abc` còn 2 cái kia thì không &rarr; `X-Forwarded-Host` unkeyed bởi internal cache nhưng là keyed đối với external cache. ![](https://i.imgur.com/FztarvW.png) Bây giờ chỉ việc tạo file `/js/geolocate.js` chứa `alert(document.cookie)`. ![](https://i.imgur.com/hTT6CxG.png) Nhét exploit-server domain vào `X-Forwarded-Host` và gửi cho đến khi hostname load file `/js/geolocate.js` trở thành exploit-server. ![](https://i.imgur.com/ZY3QpLh.png) Xóa `X-Forwarded-Host`, ta thấy hostname load file `/js/geolocate.js` vẫn là exploit-server. ![](https://i.imgur.com/8lHABzt.png) Lúc này nạn nhân truy cập trang chủ sẽ load `/js/geolocate.js` của exploit-server và bị alert &rarr; Ta solve thành công. ![](https://i.imgur.com/0Lp0KFZ.png) ### 12. Web cache poisoning to exploit a DOM vulnerability via a cache with strict cacheability criteria ##### Description > This lab contains a DOM-based vulnerability that can be exploited as part of a web cache poisoning attack. A user visits the home page roughly once a minute. Note that the cache used by this lab has stricter criteria for deciding which responses are cacheable, so you will need to study the cache behavior closely. > > To solve the lab, poison the cache with a response that executes `alert(document.cookie)` in the visitor's browser. ##### Writeup Ứng dụng support `X-Forwarded-Host`. ![](https://i.imgur.com/8Y7s1FX.png) và giá trị của nó được gán vào `data.host`. ![](https://i.imgur.com/IGmvQck.png) Sau đó, hàm `initGeoLocate()` được gọi với tham số `//data.host/resources/json/geolocate.json` attacker có thể control được. ![](https://i.imgur.com/lQQIyE2.png) Hàm `initGeoLocate()` bị dính DOM-XSS khi sau khi lấy lấy response về từ jsonUrl, nó thực hiện parse JSON và lấy `j.country` đưa vào sink innerHTML để render. ![](https://i.imgur.com/lXmfE6C.png) &rarr; Tạo exploit-server với đường dẫn `/resources/json/geolocate.json` chứa nội dung: ```json { "country": "<img src=1 onerror=alert(document.cookie) />" } ``` Nhớ thêm `Access-Control-Allow-Origin: *` để support CORS. ![](https://i.imgur.com/QF5w9vz.png) Bây giờ chỉ việc poison cache với header `X-Forwarded-Host: <Exploit-server>`. Chú ý, cache chỉ cache với các request có cookie vì khi không có cookie, server trả về set-cookie &rarr; nếu cache thì có thể các user có thể nhận được cache response &rarr; chung cookie. ![](https://i.imgur.com/YOaBUy5.png) Gửi request cho đến khi cache hit. Victim truy cập trang chủ sẽ bị dính DOM-XSS. Ta solve được challenge. ![](https://i.imgur.com/pLaXxIK.png) --- ## Notes Web cache poisoning is an advanced technique whereby an attacker exploits the behavior of a web server and cache so that a harmful HTTP response is served to other users. ***Cache keys***: is used to identify equivalent requests to serve cache - This would contain the request line and `Host` header - **Ignore "unkeyed"** components which are **not** included in cache keys. Generally speaking, constructing a *basic web cache poisoning attack* involves the following steps: - Identify and evaluate **unkeyed** inputs - Elicit a harmful response from the back-end server - Get the response cached **Detect:** - Cache design flaw: ignore unkeyed - Cache key flaw: - Excluding the query string - Filtering out specific query parameters - Normalizing input in keyed components **Countermeasures:** - Do not use cache - Don't accept fat GET requests - Rewrite the request when excluding sth from cache keys - Patch client-side vulns even if it's unexploitable. ###### tags: `portswigger`, `web-cache-poisoning`, `advanced`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully