CVE-2007-0450 - Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Severity

50%

Complexity

99%

Confidentiality

48%

Directory traversal vulnerability in Apache HTTP Server and Tomcat 5.x before 5.5.22 and 6.x before 6.0.10, when using certain proxy modules (mod_proxy, mod_rewrite, mod_jk), allows remote attackers to read arbitrary files via a .. (dot dot) sequence with combinations of (1) "/" (slash), (2) "\" (backslash), and (3) URL-encoded backslash (%5C) characters in the URL, which are valid separators in Tomcat but not in Apache.

Directory traversal vulnerability in Apache HTTP Server and Tomcat 5.x before 5.5.22 and 6.x before 6.0.10, when using certain proxy modules (mod_proxy, mod_rewrite, mod_jk), allows remote attackers to read arbitrary files via a .. (dot dot) sequence with combinations of (1) "/" (slash), (2) "\" (backslash), and (3) URL-encoded backslash (%5C) characters in the URL, which are valid separators in Tomcat but not in Apache.

CVSS 2.0 Base Score 5. CVSS Attack Vector: network. CVSS Attack Complexity: low. CVSS Vector: (AV:N/AC:L/Au:N/C:P/I:N/A:N).

Demo Examples

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

CWE-22

The following code could be for a social networking application in which each user's profile information is stored in a separate file. All files are stored in a single directory.


               
print "</ul>\n";
print "<li>$_</li>\n";

While the programmer intends to access files such as "/users/cwe/profiles/alice" or "/users/cwe/profiles/bob", there is no verification of the incoming user parameter. An attacker could provide a string such as:


               
../../../etc/passwd

The program would generate a profile pathname like this:


               
/users/cwe/profiles/../../../etc/passwd

When the file is opened, the operating system resolves the "../" during path canonicalization and actually accesses this file:


               
/etc/passwd

As a result, the attacker could read the entire text of the password file.

Notice how this code also contains an error message information leak (CWE-209) if the user parameter does not produce a file that exists: the full pathname is provided. Because of the lack of output encoding of the file that is retrieved, there might also be a cross-site scripting problem (CWE-79) if profile contains any HTML, but other code would need to be examined.

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

CWE-22

In the example below, the path to a dictionary file is read from a system property and used to initialize a File object.


               
File dictionaryFile = new File(filename);

However, the path is not validated or modified to prevent it from containing relative or absolute path sequences before creating the File object. This allows anyone who can control the system property to determine what file is used. Ideally, the path should be resolved relative to some kind of application or user home directory.

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

CWE-22

The following code takes untrusted input and uses a regular expression to filter "../" from the input. It then appends this result to the /home/user/ directory and attempts to read the file in the final resulting path.


               
ReadAndSendFile($filename);

Since the regular expression does not have the /g global match modifier, it only removes the first instance of "../" it comes across. So an input value such as:


               
../../../etc/passwd

will have the first "../" stripped, resulting in:


               
../../etc/passwd

This value is then concatenated with the /home/user/ directory:


               
/home/user/../../etc/passwd

which causes the /etc/passwd file to be retrieved once the operating system has resolved the ../ sequences in the pathname. This leads to relative path traversal (CWE-23).

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

CWE-22

The following code attempts to validate a given input path by checking it against a whitelist and once validated delete the given file. In this specific case, the path is considered valid if it starts with the string "/safe_dir/".


               
}
f.delete()

An attacker could provide an input such as this:


               
/safe_dir/../important.dat

The software assumes that the path is valid because it starts with the "/safe_path/" sequence, but the "../" sequence will cause the program to delete the important.dat file in the parent directory

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

CWE-22

The following code demonstrates the unrestricted upload of a file with a Java servlet and a path traversal vulnerability. The HTML code is the same as in the previous example with the action attribute of the form sending the upload file request to the Java servlet instead of the PHP code.


               
</form>
<input type="submit" name="submit" value="Submit"/>

When submitted the Java servlet's doPost method will receive the request, extract the name of the file from the Http request header, read the file contents from the request and output the file to the local upload directory.


               
}
{...}// the starting position of the boundary header// verify that content type is multipart form data
// output the file to the local upload directory
bw.close();
}
bw.flush();
// output successful upload response HTML page
// output unsuccessful upload response HTML page
...

This code does not check the filename that is provided in the header, so an attacker can use "../" sequences to write to files outside of the intended directory. Depending on the executing environment, the attacker may be able to specify arbitrary files to write to, leading to a wide variety of consequences, from code execution, XSS (CWE-79), or system crash.

Also, this code does not perform a check on the type of the file being uploaded. This could allow an attacker to upload any executable file or other file with malicious code (CWE-434).

Overview

Type

Apache Software Foundation

First reported 17 years ago

2007-03-16 22:19:00

Last updated 5 years ago

2019-04-15 16:29:00

Affected Software

Apache Software Foundation Apache HTTP Server

Apache Software Foundation Tomcat

References

http://community.ca.com/blogs/casecurityresponseblog/archive/2009/01/23.aspx

Broken Link

http://docs.info.apple.com/article.html?artnum=306172

Third Party Advisory

SSRT071447

Broken Link

APPLE-SA-2007-07-31

Mailing List, Third Party Advisory

[Security-announce] 20080107 VMSA-2008-0002 Low severity security update for VirtualCenter and ESX Server 3.0.2, and ESX 3.0.1

Third Party Advisory

24732

Third Party Advisory

25106

Third Party Advisory

25280

Third Party Advisory

26235

Third Party Advisory

26660

Third Party Advisory

27037

Third Party Advisory

28365

Third Party Advisory

30899

Third Party Advisory

30908

Third Party Advisory

33668

Third Party Advisory

GLSA-200705-03

Third Party Advisory

2446

Third Party Advisory

239312

Broken Link

http://support.avaya.com/elmodocs2/security/ASA-2007-206.htm

Third Party Advisory

http://support.ca.com/irj/portal/anonymous/phpsupcontent?contentID=197540

Broken Link, Third Party Advisory

http://tomcat.apache.org/security-4.html

Vendor Advisory

http://tomcat.apache.org/security-5.html

Vendor Advisory

http://tomcat.apache.org/security-6.html

Vendor Advisory

http://www.fujitsu.com/global/support/software/security/products-f/interstage-200702e.html

Third Party Advisory

MDKSA-2007:241

Third Party Advisory

SUSE-SR:2007:015

Broken Link

SUSE-SR:2007:005

Broken Link

RHSA-2007:0327

Third Party Advisory

RHSA-2007:0360

Third Party Advisory

RHSA-2008:0261

Third Party Advisory

http://www.sec-consult.com/287.html

Broken Link

http://www.sec-consult.com/fileadmin/Advisories/20070314-0-apache_tomcat_directory_traversal.txt

Broken Link

20070314 SEC Consult SA-20070314-0 :: Apache HTTP Server / Tomcat directory traversal

Third Party Advisory, VDB Entry

20080108 VMSA-2008-0002 Low severity security update for VirtualCenter and ESX Server 3.0.2, and ESX 3.0.1

Third Party Advisory, VDB Entry

20090124 CA20090123-01: Cohesion Tomcat Multiple Vulnerabilities

Third Party Advisory, VDB Entry

20090127 CA20090123-01: Cohesion Tomcat Multiple Vulnerabilities (Updated - v1.1)

Third Party Advisory, VDB Entry

22960

Third Party Advisory, VDB Entry

25159

Third Party Advisory, VDB Entry

ADV-2007-0975

Third Party Advisory

ADV-2007-2732

Third Party Advisory

ADV-2007-3087

Third Party Advisory

ADV-2007-3386

Third Party Advisory

ADV-2008-0065

Third Party Advisory

ADV-2008-1979

Third Party Advisory

ADV-2009-0233

Third Party Advisory

tomcat-proxy-directory-traversal(32988)

Third Party Advisory, VDB Entry

[tomcat-dev] 20190413 svn commit: r1857494 [18/20] - in /tomcat/site/trunk: ./ docs/ xdocs/

[tomcat-dev] 20190319 svn commit: r1855831 [21/30] - in /tomcat/site/trunk: ./ docs/ xdocs/

[tomcat-dev] 20190415 svn commit: r1857582 [20/22] - in /tomcat/site/trunk: docs/ xdocs/stylesheets/

[tomcat-dev] 20190325 svn commit: r1856174 [25/29] - in /tomcat/site/trunk: docs/ xdocs/ xdocs/stylesheets/

[tomcat-dev] 20190319 svn commit: r1855831 [26/30] - in /tomcat/site/trunk: ./ docs/ xdocs/

[tomcat-dev] 20190325 svn commit: r1856174 [19/29] - in /tomcat/site/trunk: docs/ xdocs/ xdocs/stylesheets/

[tomcat-dev] 20200213 svn commit: r1873980 [30/34] - /tomcat/site/trunk/docs/

[tomcat-dev] 20200213 svn commit: r1873980 [24/34] - /tomcat/site/trunk/docs/

[tomcat-dev] 20200203 svn commit: r1873527 [26/30] - /tomcat/site/trunk/docs/

oval:org.mitre.oval:def:10643

Third Party Advisory

Stay updated

ExploitPedia is constantly evolving. Sign up to receive a notification when we release additional functionality.

Get in touch

If you'd like to report a bug or have any suggestions for improvements then please do get in touch with us using this form. We will get back to you as soon as we can.