Identifying Web Cache Poisoning and Web Cache Deception: How Tenable Web App Scanning Can Help
2024-3-18 21:0:0 Author: www.tenable.com(查看原文) 阅读量:9 收藏

Web cache poisoning and web cache deception are two related but distinct types of attacks that can have serious consequences for web applications and their users. Learn how these flaws arise, why some common attack paths are so challenging to mitigate and how Tenable Web App Scanning can help.

Web cache poisoning and web cache deception are attack types that impact modern web applications. These attack vectors take advantage of web caches, which are web server components used to improve performance and reduce server load, and which can be manipulated by attackers to tamper with web applications.

Although they both involve web cache abuse, the two vulnerabilities are quite different. Web cache poisoning enables an attacker to introduce malicious content into the cache, which can then be served up to legitimate users. This can lead to injection attacks, the distribution of fraudulent content and even breaches of users privacy. On the other hand, web cache deception exploits a weakness in the way applications interpret cache settings, allowing attackers to manipulate requests and responses, so that they can perform unauthorized actions or leak sensitive information.

Although these vulnerabilities have not always been ranked in risk lists such as the OWASP Top 10 Web Application Security Risks, their importance is growing as web applications increasingly rely on caching to optimize performance. Careful configuration and constant monitoring of web caches are therefore essential to mitigate these risks.

What are web cache poisoning and web cache deception?

Let’s clearly understand the role of a cache: to temporarily store frequently-used or calculated data so that it can be accessed faster, enhancing the user experience. Caching improves system performance and overall efficiency, particularly by reducing server load and optimizing network traffic.

It is also important to understand that the server relies on a key-entry caching system when deciding whether to cache a page. In a key-entry caching system, data is stored in the cache in association with a unique key. When a request is received, the cache system uses the corresponding key to check whether the associated data is already present in the cache. This system is commonly used with, for example, a language cookie to serve cache data according to the user's language preferences.

What are web cache poisoning and web cache deception?

Web cache poisoning occurs when an attacker is able to inject malicious data into a web cache, causing the cache to serve the malicious data to other users who request the same resource. This can lead to a variety of attacks, including cross-site scripting (XSS), cross-site request forgery (CSRF) and data exfiltration. 

Cached copies of frequently accessed resources can be located on the server or on a separate caching server. 

What are web cache poisoning and web cache deception

Web cache deception occurs when an attacker tricks a web cache into serving stale or incorrect data to a user. This can be achieved through a variety of means, including manipulating cache headers, exploiting cache-timing vulnerabilities, or using other techniques to force the cache to serve out-of-date data. 

When a user requests a resource, the cache may serve sensitive, obsolete or incorrect data instead of the latest version, which can lead to a variety of attacks, including data exfiltration, denial of service or unauthorized access.

What are web cache poisoning and web cache deception?2

Detecting web cache poisoning and web cache deception

Web cache poisoning and web cache deception can be difficult to detect, as the malicious data is often served from a legitimate cache. However, some signs may indicate a cache attack, including unexpected behavior or content on a webpage, unexpected redirects or unexpected errors. Additionally, checking responses and using cache-busting techniques can help detect potential cache attacks. Cache-busting techniques involve adding unique query strings or headers to requests to prevent the cache from serving stale data. 

Below we’ve included screenshots from sample attacks we conducted in our test labs.

The first thing to check is that the server is trying to cache the resource. Response headers are an excellent source of information for this. For example:

  • The “Age” header indicates the time in seconds that the resource has been stored in a proxy cache.
  • The “Cache-Control” header contains directives for controlling caching.
  • The “Pragma” header can return information about the cache server.
  • Some caching servers can even add specific headers, such as Varnish.

Detecting web cache poisoning and web cache deception

Exploiting web cache vulnerabilities

To exploit a web cache poisoning vulnerability, once a web application that uses caching has been identified, the attacker can craft a malicious request that includes the desired payload and manipulate the cache control headers to ensure that the malicious data is cached.

In the example below, the user's “User-Agent” is reflected in the page and the page is cached. Although the case seems basic, it has been possible to identify several sites replicating this case.

We add a cache buster, which avoids poisoning all users.
We add a cache buster, which avoids poisoning all users.
The previous cached value is still displayed despite the change of User-Agent.
The previous cached value is still displayed despite the change of User-Agent.
Since caching has been validated, we can now poison all users with a real payload.
Since caching has been validated, we can now poison all users with a real payload.
All users visiting the site will also receive the payload.
All users visiting the site will also receive the payload.

However, injecting a payload is not the only possible vector for this vulnerability. Other possibilities include :

  • A denial-of-service attack through headers like “x-forwarded-scheme”: Using this header generally returns a 302 error to the current page in https. If the response is cached, this causes an infinite loop making the page inaccessible.
  • Using an illegal header such as “\”, which means that the server will respond to a 400 error page. If this page is cached, it will be inaccessible to other users.
By injecting an invalid Header, the server responds with a ‘400 Bad Request’.
By injecting an invalid Header, the server responds with a ‘400 Bad Request’.

However, caching and behavior depend on the service used. For example, by default Akamai caches for 10 seconds the error responses with HTTP codes 204, 305, 404, 405, and 501. This does not preclude that an attacker uses a script to automate to enforce caching every 10 seconds.

There are many cases and variants of web-cache poisoning DoS attacks. A site dedicated to several of these cases even exists.

To exploit web cache deception, the most common technique is to exploit the main purpose of a cache server: to distribute static resources.

To determine whether a resource should be cached or not, some services such as Cloudflare rely solely on the URL extension. If the resource is a JavaScript (JS) or Cascading Style Sheets (CSS) file, for example, it will automatically be cached.

The whole idea of the exploitation is to add an extension such as .js or .css to a URL to force caching of the page. This attack is more interesting when it allows access to sensitive information such as a user's personal data or authentication secrets.

An attacker tries to access a private resource, but without success. The attacker is then redirected to the login page
An attacker tries to access a private resource, but without success. The attacker is then redirected to the login page.
The attacker sends a URL to the victim
The attacker sends a URL to the victim containing '/.js' at the end. This URL bypasses the routing rules in place and displays the contents of '/profile' of the victim. As the URL end with '.js', it is automatically cached.
The attacker can reuse the same URL to access the cached resource (without being authenticated).
The attacker can reuse the same URL to access the cached resource (without being authenticated).

Prevention and mitigation recommendations

Web cache poisoning

  • Validating all user input can help prevent attackers from injecting malicious data into web caches. Input validation should include checking for unexpected characters, sizes and formats.
  • The “Vary” header can be used to allow the server to specify which parts of the HTTP request should be taken into account by the cache.
  • Using secure caching mechanisms can help ensure that data stored in caches is not tampered with or modified. Secure caching mechanisms can include using cryptographic signatures or hashes to verify the integrity of cached data.

Web cache deception

  • Revalidate caching rules to avoid caching sensitive URLs.
  • Don't rely solely on the extension for caching, but also on the resource's “Content-Type”.
  • Some services offer dedicated remediation. CloudFlare, for example, offers Cache Deception Armor.

Use Tenable Web App Scanning to detect web cache poisoning and web cache deception flaws

Tenable Web App Scanning can identify web cache poisoning and web cache deception vulnerabilities through the classic scan andAPI scan feature, including the following dedicated plugins:

  • Plugin 113580 to detect generic web cache deception
  • Plugin 113338 to detect generic web cache poisoning
  • Plugin 114006 to detect DoS web cache poisoning

Use Tenable Web App Scanning to detect web cache poisoningUse Tenable Web App Scanning to detect web cache deception

To get more information, visit the Tenable Web App Scanning page.

Joshua Martinelle

Joshua Martinelle

Joshua joined Tenable in 2021 as a Research Engineer on the Web Application Scanning content team. Prior to joining Tenable, Joshua worked as a pentester and also as a system and network administrator, with a special interest in Linux and open source software.

Interests outside of work: Joshua enjoys spending time with his friends, watching movies and enjoying the simple moments. He indulges his passion for offensive security by doing ethical hacking in his spare time.


文章来源: https://www.tenable.com/blog/identifying-web-cache-poisoning-and-web-cache-deception-how-tenable-web-app-scanning-can-help
如有侵权请联系:admin#unsafe.sh