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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

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

  • Build Real-Time Analytics Applications With AWS Kinesis and Amazon Redshift
  • Understanding N-Gram Language Models and Perplexity
  • The QA Paradox: To Save Artificial Intelligence, We Must Stop Blindly Trusting Data—And Start Trusting Human Judgment
  • How Developers Are Driving Supply Chain Innovation With Modern Tech

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 user avatar
Ian Muscat
·
Dec. 15, 17 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
12.1K Views

Join the DZone community and get the full member experience.

Join For Free

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, DZone MVB. 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

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: