SECURITY

Multifaceted Tests : Bypassing Field Length Restrictions & Attempting Cross-Site Tracing Interactively

12/26/2011 5:39:15 PM

1. Bypassing Field Length Restrictions (XSS)

1.1. Problem

In the target application, you may find an input field that could be vulnerable to stored XSS, but the server truncates the input to a number of characters that seems insufficient to carry out a meaningful XSS attack. This restriction can be bypassed by using JavaScript comment delimiters appropriately.

1.2. Solution

The strings in Example 1 combine to be a cross-site scripting attack if they are all concatenated together. Although none of them is an attack in its own right, they are all pieces of a standard, basic XSS attack string.

Example 1. Using JavaScript comments to bypass field length restrictions
<script>/*
*/alert(/*
*/"XSS")/*
*/</script>

Also, try inserting the sequence in reverse order.

This will work in several scenarios. It will work when there are multiple length-restricted fields that are concatenated together with some punctuation or HTML tags in between. It will also work when multiple instances of the same input field are displayed on the same page. The author has seen several examples in real applications where a list of status codes, for example, are displayed on a page. The status codes are provided by an end user and are not checked at all. The status codes are displayed in a table defined in HTML like that shown in Example 2.

Example 2. Sample application output where status code length is restricted by server
...
<tr><td>statusCode1
</td></tr>
<tr><td>
statusCode2
</td></tr>
...

Example 3 shows the resulting script from Example 2.

Example 3. Sample HTML output after using JavaScript comments appropriately
<tr><td><script>
/*</td></tr><tr><td>*/
alert(
/*</td></tr><tr><td>*/
"XSS")
/*</td></tr><tr><td>*/
</script></td></tr>

In most browsers, including Internet Explorer 7 and Mozilla Firefox 3.0, this is equivalent: <script>alert("XSS")<script>.

As with other similar XSS tests, the application is vulnerable if you see an alert box pop up as a result of injecting your input.

1.3. Discussion

In scenarios where the server restricts the length of an input field but fails to perform proper input validation or output encoding, sequences such as example 12-9 can be used to inject JavaScript into the page. The cases where this attack would work include those where the inputs from the attacker are all displayed on a single page (in a table, for example). Anything between the /* and */ delimiters is treated as a comment, and thus, any HTML code that the site inserts between the attacker’s inputs is commented out.

We will not discuss in depth the exact locations where comments are allowed in JavaScript, because the answer is implementation-dependent. Internet Explorer 7, for example, allows comments in many more locations than Mozilla Firefox 3.0. Some experimentation may be required to get the attack to work.

2. Attempting Cross-Site Tracing Interactively

2.1. Problem

One protection against XSS attacks implemented by some browsers is the HttpOnly attribute in cookies. If a cookie has this attribute set, the browser will not let any JavaScript code access the cookie. If the target web server supports the TRACEHttpOnly attribute set as a protection against cookie theft, it is essential that you test for this potential vulnerability. operation, then an attacker can still steal the cookie. Therefore, if your application generates cookies with the

2.2. Solution

At the command line, type: telnet host port where host and port are the hostname and the TCP port number of the web server being tested. Then, type the code shown in Example 4.

Example 4. Testing for XST using telnet
TRACE / HTTP/1.1
Host:host:port
X-Header: This is a test

Ensure that you press Enter twice after entering these lines. If the server responds with something such as shown in Example 5, then cross-site tracing is possible on the target web server.

Example 5. Sample response when server is vulnerable to XST
HTTP/1.1 200 OK
Date: Sun, 27 Jul 2008 03:49:19 GMT
Server: Apache/2.2.8 (Win32)
Transfer-Encoding: chunked
Content-Type: message/http

44
TRACE / HTTP/1.1
Host:host:port
X-Header: This is a test


0

If, on the other hand, the server responds with something like what is shown in Example 6, then it is not vulnerable to XST.

Example 6. Sample response when server is not vulnerable to XST
HTTP/1.1 405 Method Not Allowed
Date: Sun, 27 Jul 2008 03:54:48 GMT
Server: Apache/2.2.8 (Win32)
Allow:
Content-Length: 223
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method TRACE is not allowed for the URL /.</p>
</body></html>

2.3. Discussion

Cross-site tracing is a technique that can be used to bypass HttpOnly protection in cookies. The TRACE HTTP method is useful for debugging purposes, but is typically left on by default in many web servers. A TRACE request to a web server simply echoes back the request to the caller. When the caller (browser) has a cookie for the target site, it sends the cookie along with the request. The cookie is then echoed back by the web server in the response.

Suppose an attacker cannot execute the attack  on a site vulnerable to XSS because the HttpOnly attribute is set on the cookie. The attacker can instead generate a script  where he can replace the GET in the XmlHttpRequest.open() function call with TRACE. Then, he can parse the cookie out of the server’s response. Of course, this requires the site to be vulnerable to cross-site scripting as well as to cross-site tracing. The TRACE method being left enabled is not necessarily a vulnerability in itself; the attacker needs to be able to insert JavaScript code into a vulnerable page to be able to make requests to the target server from the victim’s browser and read the responses.

NOTE

This test should be executed in your operational environment or on staging servers that replicate the production environment’s configuration. This is a configuration issue that needs to be addressed during deployment, so testing servers in the development or QA environments will not provide accurate results for the production environment.


Other  
  •  Multifaceted Tests : Making HTTP Requests Using XSS & Attempting DOM-Based XSS Interactively
  •  Multifaceted Tests : Stealing Cookies Using XSS & Creating Overlays Using XSS
  •  IIS 7.0 : Securing Configuration - Controlling Configuration Delegation
  •  IIS 7.0 : Securing Configuration - Securing Sensitive Configuration
  •  IIS 7.0 : Securing Configuration - Restricting Access to Configuration
  •  Web Security Testing : Changing Sessions to Evade Restrictions & Impersonating Another User
  •  Web Security Testing : Manipulating Sessions - Analyzing Session Randomness with WebScarab
  •  Web Security Testing : Manipulating Sessions - Analyzing Session Identifiers with Burp
  •  Programming .NET Security : Extending the .NET Framework (part 2) - Defining the Key Exchange Deformatter
  •  Programming .NET Security : Extending the .NET Framework (part 1) - Defining the Key Exchange Formatter
  •  Programming .NET Security : Programming Cryptographic Keys (part 3) - Key Exchange Formatting
  •  Programming .NET Security : Programming Cryptographic Keys (part 2) - Using Key Persistence
  •  Programming .NET Security : Programming Cryptographic Keys (part 1) - Creating Keys
  •  Deploying a Windows Server 2008 R2 Network Policy Server
  •  Understanding Network Access Protection (NAP) in Windows Server 2008 R2
  •  Programming .NET Security : Cryptographic Keys Explained
  •  Windows Server 2008 : Transport-Level Security - Using IPSec Encryption with Windows Server 2008 R2
  •  Windows Server 2008 : Transport-Level Security - Active Directory Rights Management Services
  •  Understanding Active Directory Certificate Services (AD CS) in Windows Server 2008 R2
  •  Deploying a Public Key Infrastructure with Windows Server 2008 R2
  •  
    Top 10
    SQL Azure : Database-Migration Strategies
    Windows Phone 7 Development : Push Notifications - Implementing Raw Notifications
    Clustered Indexes in SQL Server 2008
    Programming Microsoft SQL Server 2005: Using Data Mining Extensions (part 1) - Data Mining Modeling Using DMX
    Excel Programmer : Record and Read Code
    Windows Server 2008 : Domain Name System and IPv6 - Secure DNS with DNSSEC
    Defensive Database Programming with SQL Server : TRY...CATCH Gotchas (part 1) - Re-throwing errors
    iPad SDK : Popovers - The Font Name Popover (part 1)
    Getting the Most Out of the Microsoft Outlook Client : Using Outlook 2007 (part 3) - Using Group Schedules
    Design and Deploy High Availability for Exchange 2007 : Create Bookmark Create Note or Tag Implement Standby Continuous Replication (SCR)
    Most View
    Identifying the Technical Goals and Objectives to Implement Windows Server 2008 R2
    Managing Stored Passwords in Vista
    Windows Server 2008 : DHCP/WINS/Domain Controllers - Enhancing DHCP Reliability
    Algorithms for Compiler Design: THE ARRAY REFERENCE
    Designing a Windows Server 2008 R2 Active Directory : Understanding the Federated Forests Design Model
    Windows Vista : Performing Local PC Administration (part 2) - Performing common workstation administration tasks
    Windows Azure and ASP.NET : Creating a Windows Azure Project
    Enumerate Drives
    Optimizing an Exchange Server 2010 Environment - Properly Sizing Exchange Server 2010
    Windows Phone 7 : Working with Controls and Themes - Adding Transition Effects
    Installing Exchange Server 2010 in an Exchange Server 2003 environment (part 2) - Installing the first Exchange Server 2010 server & Mailbox Server
    Programming the Mobile Web : Content Delivery (part 3)
    Algorithms for Compiler Design: PROPERTIES OF REGULAR SETS
    Sharepoint 2007: Create a New Document
    Windows Mobile Security - Permissions and User Controls
    Building Your First Windows Phone 7 Application (part 4) - Customizing Your First Windows Phone Application
    Exchange Server 2007: Manage Recipients - Create Distribution Groups and Dynamic Distribution Groups
    Using Shapes in XAML
    Introducing Windows Presentation Foundation and XAML : Investigating the WPF Assemblies
    Windows Phone 7 Development : Using a WebBrowser Control to Display Web Content