XSS, www.facebook.com, sk parameter, CWE-79, CAPEC-86

CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Report generated by XSS.CX at Sat Mar 05 07:00:37 CST 2011.


Loading

1. Cross-site scripting (reflected)

1.1. http://www.facebook.com/fetchdog [sk parameter]

1.2. http://www.facebook.com/fetchdog [sk parameter]



1. Cross-site scripting (reflected)
There are 2 instances of this issue:

Issue background

Reflected cross-site scripting vulnerabilities arise when data is copied from a request and echoed into the application's immediate response in an unsafe way. An attacker can use the vulnerability to construct a request which, if issued by another application user, will cause JavaScript code supplied by the attacker to execute within the user's browser in the context of that user's session with the application.

The attacker-supplied code can perform a wide variety of actions, such as stealing the victim's session token or login credentials, performing arbitrary actions on the victim's behalf, and logging their keystrokes.

Users can be induced to issue the attacker's crafted request in various ways. For example, the attacker can send a victim a link containing a malicious URL in an email or instant message. They can submit the link to popular web sites that allow content authoring, for example in blog comments. And they can create an innocuous looking web site which causes anyone viewing it to make arbitrary cross-domain requests to the vulnerable application (using either the GET or the POST method).

The security impact of cross-site scripting vulnerabilities is dependent upon the nature of the vulnerable application, the kinds of data and functionality which it contains, and the other applications which belong to the same domain and organisation. If the application is used only to display non-sensitive public content, with no authentication or access control functionality, then a cross-site scripting flaw may be considered low risk. However, if the same application resides on a domain which can access cookies for other more security-critical applications, then the vulnerability could be used to attack those other applications, and so may be considered high risk. Similarly, if the organisation which owns the application is a likely target for phishing attacks, then the vulnerability could be leveraged to lend credibility to such attacks, by injecting Trojan functionality into the vulnerable application, and exploiting users' trust in the organisation in order to capture credentials for other applications which it owns. In many kinds of application, such as those providing online banking functionality, cross-site scripting should always be considered high risk.

Remediation background

In most situations where user-controllable data is copied into application responses, cross-site scripting attacks can be prevented using two layers of defenses:In cases where the application's functionality allows users to author content using a restricted subset of HTML tags and attributes (for example, blog comments which allow limited formatting and linking), it is necessary to parse the supplied HTML to validate that it does not use any dangerous syntax; this is a non-trivial task.


1.1. http://www.facebook.com/fetchdog [sk parameter]  next

Summary

Severity:   High
Confidence:   Firm
Host:   http://www.facebook.com
Path:   /fetchdog

Issue detail

The value of the sk request parameter is copied into a JavaScript string which is encapsulated in double quotation marks. The payload 7dfa9\"%3bc452bab034 was submitted in the sk parameter. This input was echoed as 7dfa9\\";c452bab034 in the application's response.

This behaviour demonstrates that it is possible to terminate the JavaScript string into which our data is being copied. An attempt was made to identify a full proof-of-concept attack for injecting arbitrary JavaScript but this was not successful. You should manually examine the application's behaviour and attempt to identify any unusual input validation or other obstacles that may be in place.

The application attempts to prevent termination of the quoted JavaScript string by placing a backslash character (\) before any quotation mark characters contained within the input. The purpose of this defense is to escape the quotation mark and prevent it from terminating the string. However, the application fails to escape any backslash characters that already appear within the input itself. This enables an attacker to supply their own backslash character before the quotation mark, which has the effect of escaping the backslash character added by the application, and so the quotation mark remains unescaped and succeeds in terminating the string. This technique is used in the attack demonstrated.

Note that a redirection occurred between the attack request and the response containing the echoed input. It is necessary to follow this redirection for the attack to succeed. When the attack is carried out via a browser, the redirection will be followed automatically.

Remediation detail

Echoing user-controllable data within a script context is inherently dangerous and can make XSS attacks difficult to prevent. If at all possible, the application should avoid echoing user data within this context. If it is unavoidable to echo user input into a quoted JavaScript string the the backslash character should be blocked, or escaped by replacing it with two backslashes.

Request

GET /fetchdog?sk=app_959369626347dfa9\"%3bc452bab034 HTTP/1.1
Host: www.facebook.com
Proxy-Connection: keep-alive
Referer: http://www.fetchdog.com/Shop
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: campaign_click_url=%2Fcampaign%2Fimpression.php%3Fcampaign_id%3D137675572948107%26partner_id%3Dbloganol.com%26placement%3Dactivity%26extra_1%3Dhttp%253A%252F%252Fwww.bloganol.com%252F2010%252F11%252Fcreate-url-shortening-service-shorty-2.html%26extra_2%3DUS; datr=VV5oTas0hG1hzk6eclVNNMGO

Response (redirected)

HTTP/1.1 200 OK
Cache-Control: private, no-cache, no-store, must-revalidate
Expires: Sat, 01 Jan 2000 00:00:00 GMT
P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"
Pragma: no-cache
Set-Cookie: lsd=OwD2D; path=/; domain=.facebook.com
Set-Cookie: noscript=1; path=/; domain=.facebook.com
Set-Cookie: reg_ext_ref=http%3A%2F%2Fwww.fetchdog.com%2FShop; path=/; domain=.facebook.com
Set-Cookie: reg_fb_gate=http%3A%2F%2Fwww.facebook.com%2Ffetchdog%3Fsk%3Dapp_959369626347dfa9%255C%2522%253Bc452bab034; path=/; domain=.facebook.com
Set-Cookie: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Ffetchdog%3Fsk%3Dapp_959369626347dfa9%255C%2522%253Bc452bab034; path=/; domain=.facebook.com
Content-Type: text/html; charset=utf-8
X-Powered-By: HPHP
X-FB-Server: 10.52.229.75
X-Cnection: close
Date: Wed, 02 Mar 2011 19:24:57 GMT
Content-Length: 31164

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schem
...[SNIP]...
ssage":false,"poke":false,"name":null,"notif_t":null,"and":null,"created":false,"aid":null,"ext_ref":null,"app_ref":null,"app_data":null,"ppid":null,"ref":null,"sid":null,"v":null,"sk":"app_959369626347dfa9\\";c452bab034","new_box_added_id":null,"story_fbid":null,"unsubscribe":false,"newfriend":false,"p":false}, {});; ;});
onloadRegister(function (){window.__UIControllerRegistry["c4d6e998931ee46c42800473"] = new UIPag
...[SNIP]...

1.2. http://www.facebook.com/fetchdog [sk parameter]  previous

Summary

Severity:   High
Confidence:   Firm
Host:   http://www.facebook.com
Path:   /fetchdog

Issue detail

The value of the sk request parameter is copied into a JavaScript string which is encapsulated in double quotation marks. The payload 74746\"%3b83568f85304 was submitted in the sk parameter. This input was echoed as 74746\\";83568f85304 in the application's response.

This behaviour demonstrates that it is possible to terminate the JavaScript string into which our data is being copied. An attempt was made to identify a full proof-of-concept attack for injecting arbitrary JavaScript but this was not successful. You should manually examine the application's behaviour and attempt to identify any unusual input validation or other obstacles that may be in place.

The application attempts to prevent termination of the quoted JavaScript string by placing a backslash character (\) before any quotation mark characters contained within the input. The purpose of this defense is to escape the quotation mark and prevent it from terminating the string. However, the application fails to escape any backslash characters that already appear within the input itself. This enables an attacker to supply their own backslash character before the quotation mark, which has the effect of escaping the backslash character added by the application, and so the quotation mark remains unescaped and succeeds in terminating the string. This technique is used in the attack demonstrated.

Remediation detail

Echoing user-controllable data within a script context is inherently dangerous and can make XSS attacks difficult to prevent. If at all possible, the application should avoid echoing user data within this context. If it is unavoidable to echo user input into a quoted JavaScript string the the backslash character should be blocked, or escaped by replacing it with two backslashes.

Request

GET /fetchdog?sk=app_95936962634774746\"%3b83568f85304 HTTP/1.1
Host: www.facebook.com
Proxy-Connection: keep-alive
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: campaign_click_url=%2Fcampaign%2Fimpression.php%3Fcampaign_id%3D137675572948107%26partner_id%3Dbloganol.com%26placement%3Dactivity%26extra_1%3Dhttp%253A%252F%252Fwww.bloganol.com%252F2010%252F11%252Fcreate-url-shortening-service-shorty-2.html%26extra_2%3DUS; datr=VV5oTas0hG1hzk6eclVNNMGO; lsd=OwD2D; noscript=1; reg_ext_ref=http%3A%2F%2Fwww.fetchdog.com%2FShop; reg_fb_gate=http%3A%2F%2Fwww.facebook.com%2Ffetchdog%3Fsk%3Dapp_959369626347dfa9%255C%2522%253Bc452bab034; reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Ffetchdog%3Fsk%3Dapp_959369626347dfa9%255C%2522%253Bc452bab034

Response

HTTP/1.1 200 OK
Cache-Control: private, no-cache, no-store, must-revalidate
Expires: Sat, 01 Jan 2000 00:00:00 GMT
P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"
Pragma: no-cache
Set-Cookie: reg_fb_ref=http%3A%2F%2Fwww.facebook.com%2Ffetchdog%3Fsk%3Dapp_95936962634774746%255C%2522%253B83568f85304; path=/; domain=.facebook.com
Content-Type: text/html; charset=utf-8
X-Powered-By: HPHP
X-FB-Server: 10.43.108.45
X-Cnection: close
Date: Thu, 03 Mar 2011 01:29:32 GMT
Content-Length: 31158

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schem
...[SNIP]...
sage":false,"poke":false,"name":null,"notif_t":null,"and":null,"created":false,"aid":null,"ext_ref":null,"app_ref":null,"app_data":null,"ppid":null,"ref":null,"sid":null,"v":null,"sk":"app_95936962634774746\\";83568f85304","new_box_added_id":null,"story_fbid":null,"unsubscribe":false,"newfriend":false,"p":false}, {});; ;});
onloadRegister(function (){window.__UIControllerRegistry["c4d6eeefc7465d1308092271"] = new UIPag
...[SNIP]...

Report generated by XSS.CX at Sat Mar 05 07:00:37 CST 2011.