DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Where Does Middleware Stand in Web Development?
  • 6 Easy Ways to Start Coding Accessibly
  • COBOL: A 1959 Idea and 2022 Technology
  • Application Modernization and 6 R's

Trending

  • One Database, Two Models: Building AI-Friendly Java Applications With MySQL JSON Duality Views
  • Taming Parameter Sniffing in SQL Server 2022 With PSP Optimization
  • Evals in CI: How to Catch Agent Regressions Before Production Does
  • Why Spark Executors Leave Cores Idle on YARN: A Packing Model for Executor Sizing

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

What Is Path Traversal?

An attack where an attacker may trick a web app into reading and divulging the contents of files outside of the root directory of the app or the web server. Scary stuff!

By 
Ian Muscat
·
Dec. 15, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
12.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Path Traversal, or, as it is otherwise known, Directory Traversal, refers to an attack through which an attacker may trick a web application into reading and subsequently divulging the contents of files outside of the root directory of the application, or the web server. Path Traversal attacks typically manipulate web application inputs by using the dot-dot-slash (../) sequences, or similar variations. ../ is a cross-platform convention to 'go up' (traverse) a directory (folder).

Typically, Path Traversal attacks are used in order to gain access to sensitive information stored within files either within other areas of a web application, as well as other parts of the filesystem which the web server can read. Since files containing sensitive information may contain secrets such as passwords, access tokens or backups, a successful Path Traversal attack may allow an attacker to take their reconnaissance further, or exploit other vulnerabilities within the web application.

Note - While Path Traversal may seem similar to Local File Inclusion (LFI) and Remote File Inclusion (RFI), Path Traversal only allows an attacker to read a file, while LFI and RFI may also allow an attacker to execute code.

The following is an example in PHP that is vulnerable to Path Traversal.

/**
* Get the filename from a GET input
* Example - http://example.com/?file=filename.php
*/
$file = $_GET['file'];

/**
* Unsafely include the file
* Example - filename.php
*/
file_get_contents('directory/' . $file);

In the above example, an attacker could make the following request to trick the application into divulging the contents of the /etc/passwd system file.

http://example.com/?file=../../../../etc/passwd

In the above example, an attacker could have used Path Traversal to obtain the contents of the /etc/passwd file, which contains a list of users on the server. Similarly, an attacker may leverage the Path Traversal vulnerability to gain access to credentials, logs, and other sensitive information that may help advance an attack.

Path Traversal is certainly not limited to accessing the /etc/passwd file. Since 'everything' in Linux-based systems is a file, an attacker can gain a wealth of information about a vulnerable application just by reading the right files on a system. The following are just a couple of examples of how Path Traversal can be used to glean information about the system the vulnerable application is running on.

/proc/version

The /proc/version file contains the version of the Linux kernel running on the system. This information can be used by an attacker to determine the operating system version and determine if any security updated could be missing.

/proc/mounts

The /proc/mounts file provides a list of file systems which are mounted and can be used by an attacker to learn where potentially interesting and sensitive files may be located.

/proc/net/arp

The /proc/net/arp file lists the system's Address Resolution Protocol (ARP) table which could provide a very easy way for an attacker to discover other internal, connected systems.

/proc/net/tcp and /proc/net/udp

The /proc/net/tcp and /proc/net/udp files can provide an attacker with a list of active connections. This information can be used to determine what ports are listening on the server, and, therefore, what services the server is likely running.

Preventing Path Traversal Vulnerabilities

The best way to eliminate Path Traversal vulnerabilities is to avoid dynamically reading files based on user input. If this is not possible, the application should maintain a whitelist of files that can be included in order to limit the attacker's control over what gets included.

operating system application

Published at DZone with permission of Ian Muscat. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Where Does Middleware Stand in Web Development?
  • 6 Easy Ways to Start Coding Accessibly
  • COBOL: A 1959 Idea and 2022 Technology
  • Application Modernization and 6 R's

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook