This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Difference between revisions of "Test RIA cross domain policy (OTG-CONFIG-008)"

From OWASP
Jump to: navigation, search
Line 14: Line 14:
  
 
Master policy files are located at the domain's root. A client may be instructed to load a different policy file, however, it will always check the master policy file first to ensure that the master policy file permits the requested policy file.
 
Master policy files are located at the domain's root. A client may be instructed to load a different policy file, however, it will always check the master policy file first to ensure that the master policy file permits the requested policy file.
=== What is CORS===
 
CORS is HTML5's way of enabling web applications to perform cross-domain requests.
 
 
  
 
==== Crossdomain.xml vs. Clientaccesspolicy.xml ====
 
==== Crossdomain.xml vs. Clientaccesspolicy.xml ====
Line 39: Line 36:
 
</cross-domain-policy>
 
</cross-domain-policy>
 
</pre>
 
</pre>
 +
=== What is CORS===
 +
CORS is HTML5's way of enabling web applications to perform cross-domain requests. CORS works by appending an "Origin" header to the HTTP request, then the server responds with a "Access-Control-Allow-Origin" header stating which website can issue cross domain requests. The server may answer with the Access-Control-Allow-Origin header set to * to indicate that it is a public resource.
  
 
+
=== How can cross domain policies can be abused ===
 
+
* Overly permissive cross-domain policies
=== How can RIA policy files be abused ===
 
* Overly permissive RIA policy files
 
 
* Generating server responses that may be treated as cross-domain policy files
 
* Generating server responses that may be treated as cross-domain policy files
 
* Using file upload functionality to upload files that may be treated as cross-domain policy files.
 
* Using file upload functionality to upload files that may be treated as cross-domain policy files.
 +
* Being able to set custom response headers to indicate cross domain access. (Access-Control-Allow-Origin: *)
  
=== Impact of abusing crossdomain.xml policy files ===
+
=== Impact of abusing cross-domain access ===
* Cross-domain access to site
 
 
* Defeat CSRF protections
 
* Defeat CSRF protections
 
* Read data restricted or otherwise protected by cross-origin policies.
 
* Read data restricted or otherwise protected by cross-origin policies.
Line 62: Line 59:
 
  <allow-access-from domain="*" />  
 
  <allow-access-from domain="*" />  
 
</cross-domain-policy></pre>
 
</cross-domain-policy></pre>
<br>
+
 
 
'''Result Expected:'''<br>
 
'''Result Expected:'''<br>
 
A list of policy files found. <br>
 
A list of policy files found. <br>
 
A weak settings in the policies.<br>
 
A weak settings in the policies.<br>
 +
 +
'''Testing for CORS policy weakness:''' <br>
 +
Issue an OPTIONS request to the server with the following headers set:<br>
 +
* Origin: Origin can be any URL other than the website you are testing on or null.
 +
* Access-Control-Request-Method: This can be GET, POST, PUT, DELETE, etc. You should try with different values.
 +
* Access-Control-Request-Headers: This can be almost any request header. You should try to with sensitive headers. (This is optional)
 +
<br>
 +
A request will then look like this:
 +
 +
<pre>
 +
OPTIONS /resources/target HTTP/1.1
 +
Host: example.com
 +
Connection: keep-alive
 +
Access-Control-Request-Method: POST
 +
Origin: http://owasp.org
 +
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5
 +
Access-Control-Request-Headers: x-extraheader, content-type
 +
Accept: */*
 +
Referer: http://example.com/page.html
 +
Accept-Encoding: gzip,deflate,sdch
 +
Accept-Language: en-US,en;q=0.8,es;q=0.6
 +
</pre>
 +
 +
A successful response would look like this: <br>
 +
<pre>
 +
HTTP/1.1 200 OK
 +
Date: Thu, 13 Mar 2014 10:18:45 GMT
 +
Server: Apache
 +
Access-Control-Allow-Origin: http://example.com
 +
Access-Control-Allow-Methods: POST, GET, OPTIONS
 +
Access-Control-Allow-Headers: X-EXTRAHEADER, CONTENT-TYPE
 +
Access-Control-Max-Age: 1728000
 +
Vary: Accept-Encoding
 +
Content-Encoding: gzip
 +
Content-Length: 20
 +
Keep-Alive: timeout=2, max=100
 +
Connection: Keep-Alive
 +
Content-Type: text/plain
 +
</pre>
 +
 +
You should carefully inspect the "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", "Access-Control-Allow-Credentials", "Access-Control-Allow-Headers", "Access-Control-Allow-Expose-Headers", and any other header that starts with "Access-Control-Allow-". The value of each of this headers should be set to the most restrictive setting. For example a specific domain for "Access-Control-Allow-Origin".
 
== References ==
 
== References ==
 
'''Whitepapers'''<br>
 
'''Whitepapers'''<br>
Line 76: Line 114:
 
* Stefan Esser: "Poking new holes with Flash Crossdomain Policy Files" http://www.hardened-php.net/library/poking_new_holes_with_flash_crossdomain_policy_files.html
 
* Stefan Esser: "Poking new holes with Flash Crossdomain Policy Files" http://www.hardened-php.net/library/poking_new_holes_with_flash_crossdomain_policy_files.html
 
* Jeremiah Grossman: "Crossdomain.xml Invites Cross-site Mayhem" http://jeremiahgrossman.blogspot.com/2008/05/crossdomainxml-invites-cross-site.html
 
* Jeremiah Grossman: "Crossdomain.xml Invites Cross-site Mayhem" http://jeremiahgrossman.blogspot.com/2008/05/crossdomainxml-invites-cross-site.html
* http://code.google.com/p/doctype-mirror/wiki/ArticleFlashSecurity
+
* Google Doctype: "Introduction to Flash security " - http://code.google.com/p/doctype-mirror/wiki/ArticleFlashSecurity
 
* http://www.html5rocks.com/en/tutorials/cors/
 
* http://www.html5rocks.com/en/tutorials/cors/
* http://omarrr.com/cors-html5-approach-to-crossdomain-policies/
+
* Krzysztof Kotowicz: "How to upload arbitrary file contents cross-domain"- http://blog.kotowicz.net/2011/04/how-to-upload-arbitrary-file-contents.html
* http://www.w3.org/TR/cors/
+
* W3C: "Cross-Origin Resource Sharing" - http://www.w3.org/TR/cors/
 
<br>
 
<br>
 
'''Tools'''<br>
 
'''Tools'''<br>
 
* Nikto
 
* Nikto
 +
* OWASP Zed Attack Proxy Project

Revision as of 11:06, 13 March 2014

This article is part of the new OWASP Testing Guide v4.
Back to the OWASP Testing Guide v4 ToC: https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents Back to the OWASP Testing Guide Project: https://www.owasp.org/index.php/OWASP_Testing_Project


Brief Summary

Rich Internet Applications (RIA) have adopted Adobe's crossdomain.xml policy files in order to allow for controlled cross domain access to data and service consumption using technologies such as Oracle Java, Silverlight, and Adobe Flash. Therefore, a domain can grant remote access to its services from a different domain. However, often the policy files that describe the access restrictions are poorly configured. Poor configuration of the policy files enables Cross-site Request Forgery attacks, and may allow third parties to access sensitive data meant for the user.

HTML5 also incorporates a new way of performing cross domain requests: Cross Origin Resource Sharing (CORS). These can also be improperly configured and enable an attacker to perform similar attacks.

Description of the Issue

What are cross-domain policy files

A cross-domain policy file specifies the permissions that a web client such as Java, Adobe Flash, Adobe Reader, etc. to access data across different domains. For Silverlight, Microsoft adopted a subset of the Adobe's crossdomain.xml, and additionally created it's own cross-domain policy file: clientaccesspolicy.xml.

Whenever a web client detects that a resource has to be requested from other domain, it will first look for a policy file in the target domain in order to determine if performing cross-domain requests, including headers, and socket-based connections are allowed.

Master policy files are located at the domain's root. A client may be instructed to load a different policy file, however, it will always check the master policy file first to ensure that the master policy file permits the requested policy file.

Crossdomain.xml vs. Clientaccesspolicy.xml

Most RIA applications support crossdomain.xml. However in the case of Silverlight, it will only work if the crossdomain.xml specifies that access is allowed from any domain. For more granular control with Silverlight, clientaccesspolicy.xml must be used.

Policy files grant several types of permissions:

  • Accepted policy files (Master policy files can disable or restrict specific policy files)
  • Sockets permissions
  • Header permissions
  • HTTP/HTTPS access permissions
  • Allowing access based on cryptographic credentials

An example of an overly permissive policy file:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
   <site-control permitted-cross-domain-policies="all"/>
   <allow-access-from domain="*" secure="false"/>
   <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>

What is CORS

CORS is HTML5's way of enabling web applications to perform cross-domain requests. CORS works by appending an "Origin" header to the HTTP request, then the server responds with a "Access-Control-Allow-Origin" header stating which website can issue cross domain requests. The server may answer with the Access-Control-Allow-Origin header set to * to indicate that it is a public resource.

How can cross domain policies can be abused

  • Overly permissive cross-domain policies
  • Generating server responses that may be treated as cross-domain policy files
  • Using file upload functionality to upload files that may be treated as cross-domain policy files.
  • Being able to set custom response headers to indicate cross domain access. (Access-Control-Allow-Origin: *)

Impact of abusing cross-domain access

  • Defeat CSRF protections
  • Read data restricted or otherwise protected by cross-origin policies.

Black Box testing and example

Testing for RIA policy files weakness:
In order to test for RIA policy file weakness you should try to retrieve the policy files crossdomain.xml and clientaccesspolicy.xml from the application's root, and from every folder found.

For example, if the application's URL is http://www.owasp.org, you should try to download the files http://www.owasp.org/crossdomain.xml and http://www.owasp.org/clientaccesspolicy.xml.

After retrieving all the policy files, the permissions allowed should be be checked under the least privilege principle. Requests should only come from the domains, ports, or protocols that are necessary. Overly permissive policies should be avoided. Policies with "*" in them should be closely examined.

Example:

<cross-domain-policy> 
 <allow-access-from domain="*" /> 
</cross-domain-policy>

Result Expected:
A list of policy files found.
A weak settings in the policies.

Testing for CORS policy weakness:
Issue an OPTIONS request to the server with the following headers set:

  • Origin: Origin can be any URL other than the website you are testing on or null.
  • Access-Control-Request-Method: This can be GET, POST, PUT, DELETE, etc. You should try with different values.
  • Access-Control-Request-Headers: This can be almost any request header. You should try to with sensitive headers. (This is optional)


A request will then look like this:

OPTIONS /resources/target HTTP/1.1
Host: example.com
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://owasp.org
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.9 Safari/536.5
Access-Control-Request-Headers: x-extraheader, content-type
Accept: */*
Referer: http://example.com/page.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,es;q=0.6

A successful response would look like this:

HTTP/1.1 200 OK
Date: Thu, 13 Mar 2014 10:18:45 GMT
Server: Apache
Access-Control-Allow-Origin: http://example.com
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-EXTRAHEADER, CONTENT-TYPE
Access-Control-Max-Age: 1728000
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: text/plain

You should carefully inspect the "Access-Control-Allow-Origin", "Access-Control-Allow-Methods", "Access-Control-Allow-Credentials", "Access-Control-Allow-Headers", "Access-Control-Allow-Expose-Headers", and any other header that starts with "Access-Control-Allow-". The value of each of this headers should be set to the most restrictive setting. For example a specific domain for "Access-Control-Allow-Origin".

References

Whitepapers


Tools

  • Nikto
  • OWASP Zed Attack Proxy Project