CVE-2015-5174 - Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Severity

40%

Complexity

80%

Confidentiality

48%

Directory traversal vulnerability in RequestUtil.java in Apache Tomcat 6.x before 6.0.45, 7.x before 7.0.65, and 8.x before 8.0.27 allows remote authenticated users to bypass intended SecurityManager restrictions and list a parent directory via a /.. (slash dot dot) in a pathname used by a web application in a getResource, getResourceAsStream, or getResourcePaths call, as demonstrated by the $CATALINA_BASE/webapps directory.

Directory traversal vulnerability in RequestUtil.java in Apache Tomcat 6.x before 6.0.45, 7.x before 7.0.65, and 8.x before 8.0.27 allows remote authenticated users to bypass intended SecurityManager restrictions and list a parent directory via a /.. (slash dot dot) in a pathname used by a web application in a getResource, getResourceAsStream, or getResourcePaths call, as demonstrated by the $CATALINA_BASE/webapps directory.

CVSS 3.0 Base Score 4.3. CVSS Attack Vector: network. CVSS Attack Complexity: low. CVSS Vector: (CVSS:3.0/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N).

CVSS 2.0 Base Score 4. CVSS Attack Vector: network. CVSS Attack Complexity: low. CVSS Vector: (AV:N/AC:L/Au:S/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

First reported 9 years ago

2016-02-25 01:59:00

Last updated 6 years ago

2019-04-15 16:30:00

Affected Software

Debian Linux 7.0

7.0

Debian Linux 8.0 (Jessie)

8.0

Apache Software Foundation Tomcat 6.0.0

6.0.0

Apache Software Foundation Tomcat 6.0.0 alpha

6.0.0

Apache Software Foundation Tomcat 6.0.1

6.0.1

Apache Software Foundation Tomcat 6.0.1 alpha

6.0.1

Apache Software Foundation Tomcat 6.0.2

6.0.2

Apache Software Foundation Tomcat 6.0.2 alpha

6.0.2

Apache Software Foundation Tomcat 6.0.2 beta

6.0.2

Apache Software Foundation Tomcat 6.0.4

6.0.4

Apache Software Foundation Tomcat 6.0.4 alpha

6.0.4

Apache Software Foundation Tomcat 6.0.10

6.0.10

Apache Software Foundation Tomcat 6.0.11

6.0.11

Apache Software Foundation Tomcat 6.0.13

6.0.13

Apache Software Foundation Tomcat 6.0.14

6.0.14

Apache Software Foundation Tomcat 6.0.16

6.0.16

Apache Software Foundation Tomcat 6.0.18

6.0.18

Apache Software Foundation Tomcat 6.0.20

6.0.20

Apache Software Foundation Tomcat 6.0.24

6.0.24

Apache Software Foundation Tomcat 6.0.26

6.0.26

Apache Software Foundation Tomcat 6.0.28

6.0.28

Apache Software Foundation Tomcat 6.0.29

6.0.29

Apache Software Foundation Tomcat 6.0.30

6.0.30

Apache Software Foundation Tomcat 6.0.32

6.0.32

Apache Software Foundation Tomcat 6.0.33

6.0.33

Apache Software Foundation Tomcat 6.0.35

6.0.35

Apache Software Foundation Tomcat 6.0.36

6.0.36

Apache Software Foundation Tomcat 6.0.37

6.0.37

Apache Software Foundation Tomcat 6.0.41

6.0.41

Apache Software Foundation Tomcat 6.0.43

6.0.43

Apache Tomcat 6.0.44

6.0.44

Apache Software Foundation Tomcat 7.0.0 beta

7.0.0

Apache Software Foundation Tomcat 7.0.2 beta

7.0.2

Apache Software Foundation Tomcat 7.0.4 beta

7.0.4

Apache Tomcat 7.0.5 Beta

7.0.5

Apache Software Foundation Tomcat 7.0.6

7.0.6

Apache Software Foundation Tomcat 7.0.10

7.0.10

Apache Software Foundation Tomcat 7.0.11

7.0.11

Apache Software Foundation Tomcat 7.0.12

7.0.12

Apache Software Foundation Tomcat 7.0.14

7.0.14

Apache Software Foundation Tomcat 7.0.16

7.0.16

Apache Software Foundation Tomcat 7.0.19

7.0.19

Apache Software Foundation Tomcat 7.0.20

7.0.20

Apache Software Foundation Tomcat 7.0.21

7.0.21

Apache Software Foundation Tomcat 7.0.22

7.0.22

Apache Software Foundation Tomcat 7.0.23

7.0.23

Apache Software Foundation Tomcat 7.0.25

7.0.25

Apache Software Foundation Tomcat 7.0.26

7.0.26

Apache Software Foundation Tomcat 7.0.27

7.0.27

Apache Software Foundation Tomcat 7.0.28

7.0.28

Apache Software Foundation Tomcat 7.0.29

7.0.29

Apache Software Foundation Tomcat 7.0.30

7.0.30

Apache Software Foundation Tomcat 7.0.32

7.0.32

Apache Software Foundation Tomcat 7.0.33

7.0.33

Apache Software Foundation Tomcat 7.0.34

7.0.34

Apache Software Foundation Tomcat 7.0.35

7.0.35

Apache Software Foundation Tomcat 7.0.37

7.0.37

Apache Software Foundation Tomcat 7.0.39

7.0.39

Apache Software Foundation Tomcat 7.0.40

7.0.40

Apache Software Foundation Tomcat 7.0.41

7.0.41

Apache Software Foundation Tomcat 7.0.42

7.0.42

Apache Software Foundation Tomcat 7.0.47

7.0.47

Apache Software Foundation Tomcat 7.0.50

7.0.50

Apache Software Foundation Tomcat 7.0.52

7.0.52

Apache Software Foundation Tomcat 7.0.53

7.0.53

Apache Software Foundation Tomcat 7.0.54

7.0.54

Apache Software Foundation Tomcat 7.0.55

7.0.55

Apache Software Foundation Tomcat 7.0.56

7.0.56

Apache Software Foundation Tomcat 7.0.57

7.0.57

Apache Tomcat 7.0.59

7.0.59

Apache Tomcat 7.0.61

7.0.61

Apache Tomcat 7.0.62

7.0.62

Apache Tomcat 7.0.63

7.0.63

Apache Tomcat 7.0.64

7.0.64

Apache Software Foundation Tomcat 8.0.0 Release Candidate 1

8.0.0

Apache Software Foundation Tomcat 8.0.0 release candidate 10

8.0.0

Apache Software Foundation Tomcat 8.0.0 Release Candidate 3

8.0.0

Apache Software Foundation Tomcat 8.0.0 release candidate 5

8.0.0

Apache Software Foundation Tomcat 8.0.1

8.0.1

Apache Software Foundation Tomcat 8.0.11

8.0.11

Apache Software Foundation Tomcat 8.0.12

8.0.12

Apache Software Foundation Tomcat 8.0.14

8.0.14

Apache Software Foundation Tomcat 8.0.15

8.0.15

Apache Tomcat 8.0.17

8.0.17

Apache Tomcat 8.0.18

8.0.18

Apache Tomcat 8.0.20

8.0.20

Apache Tomcat 8.0.21

8.0.21

Apache Tomcat 8.0.22

8.0.22

Apache Tomcat 8.0.23

8.0.23

Apache Tomcat 8.0.24

8.0.24

Apache Tomcat 8.0.26

8.0.26

Canonical Ubuntu Linux 12.04 LTS

12.04

Canonical Ubuntu Linux 14.04 LTS (Long-Term Support)

14.04

Canonical Ubuntu Linux 15.10

15.10

Canonical Ubuntu Linux 16.04 LTS (Long-Term Support)

16.04

References

SUSE-SU-2016:0769

SUSE-SU-2016:0822

SUSE-SU-2016:0839

openSUSE-SU-2016:0865

HPSBUX03561

http://packetstormsecurity.com/files/135883/Apache-Tomcat-Limited-Directory-Traversal.html

RHSA-2016:1435

RHSA-2016:2045

RHSA-2016:2599

20160222 [SECURITY] CVE-2015-5174 Apache Tomcat Limited Directory Traversal

http://svn.apache.org/viewvc?view=revision&revision=1696281

http://svn.apache.org/viewvc?view=revision&revision=1696284

http://svn.apache.org/viewvc?view=revision&revision=1700897

http://svn.apache.org/viewvc?view=revision&revision=1700898

http://svn.apache.org/viewvc?view=revision&revision=1700900

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

Vendor Advisory

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

Vendor Advisory

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

Vendor Advisory

DSA-3530

DSA-3552

DSA-3609

http://www.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html

http://www.oracle.com/technetwork/topics/security/linuxbulletinoct2016-3090545.html

83329

1035070

USN-3024-1

RHSA-2016:1432

RHSA-2016:1433

RHSA-2016:1434

https://bto.bluecoat.com/security-advisory/sa118

https://h20566.www2.hpe.com/portal/site/hpsc/public/kb/docDisplay?docId=emr_na-c05054964

https://h20566.www2.hpe.com/portal/site/hpsc/public/kb/docDisplay?docId=emr_na-c05150442

https://h20566.www2.hpe.com/portal/site/hpsc/public/kb/docDisplay?docId=emr_na-c05158626

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

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

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

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

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

[tomcat-users] 20200130 Re: 7.0.59 to 7.0.99 upgrade, CVE-2015-5174 fix prevents us from accessing resources outside context

[tomcat-users] 20200131 Re: 7.0.59 to 7.0.99 upgrade, CVE-2015-5174 fix prevents us from accessing resources outside context

[tomcat-users] 20200204 Re: 7.0.59 to 7.0.99 upgrade, CVE-2015-5174 fix prevents us from accessing resources outside context

[tomcat-users] 20200203 Re: 7.0.59 to 7.0.99 upgrade, CVE-2015-5174 fix prevents us from accessing resources outside context

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

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

[tomcat-users] 20200130 7.0.59 to 7.0.99 upgrade, CVE-2015-5174 fix prevents us from accessing resources outside context

GLSA-201705-09

https://security.netapp.com/advisory/ntap-20180531-0001/

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.