Questions tagged [directory-traversal]

Directory traversal is a form of HTTP exploit in which a hacker uses the software on a Web server to access data in a directory other than the server's root directory. If the attempt is successful, the hacker can view restricted files or even execute commands on the server. Directory traversal attacks are commonly performed using Web browsers. Any server in which input data from Web browsers is not validated is vulnerable to this type of attack.

Directory traversal is a form of HTTP exploit in which a hacker uses the software on a Web server to access data in a directory other than the server's root directory. If the attempt is successful, the hacker can view restricted files or even execute commands on the server. Directory traversal attacks are commonly performed using Web browsers. Any server in which input data from Web browsers is not validated is vulnerable to this type of attack.

Although some educated guesswork is involved in finding paths to restricted files on a Web server, a skilled hacker can easily carry out this type of attack on an inadequately protected server by searching through the directory tree. The risk of such attacks can be minimized by careful Web server programming, the installation of software updates and patches, filtering of input from browsers, and the use of vulnerability scanners.

Directory traversal is also known as directory climbing or backtracking.

81 questions
213
votes
9 answers

Perform an action in every sub-directory using Bash

I am working on a script that needs to perform an action in every sub-directory of a specific folder. What is the most efficient way to write that?
mikewilliamson
  • 22,411
  • 17
  • 53
  • 84
36
votes
8 answers

Preventing Directory Traversal in PHP but allowing paths

I have a base path /whatever/foo/ and $_GET['path'] should be relative to it. However how do I accomplish this (reading the directory), without allowing directory traversal? eg. /\.\.|\.\./ Will not filter properly.
Johnny
  • 1,683
  • 4
  • 19
  • 22
34
votes
1 answer

Python os.walk + follow symlinks

How do I get this piece to follow symlinks in python 2.6? def load_recursive(self, path): for subdir, dirs, files in os.walk(path): for file in files: if file.endswith('.xml'): file_path = os.path.join(subdir,…
fmalina
  • 5,443
  • 4
  • 30
  • 45
22
votes
8 answers

Copy directory using Qt

I want to copy a directory from one drive to another drive. My selected directory contains many sub directories and files. How can I implement the same using Qt?
Sijith
  • 3,122
  • 14
  • 52
  • 86
19
votes
3 answers

Verify path traversal vulnerability in web server

I want to verify that my web application does not have a path traversal vulnerability. I'm trying to use curl for that, like this: $ curl -v http://www.example.com/directory/../ I would like the HTTP request to be explicitly made to the…
Fernando Correia
  • 20,349
  • 10
  • 79
  • 113
18
votes
3 answers

Does my code prevent directory traversal?

Is the following code snippet from a Python WSGI app safe from directory traversal? It reads a file name passed as parameter and returns the named file. file_name = request.path_params["file"] file = open(file_name, "rb") mime_type =…
deamon
  • 78,414
  • 98
  • 279
  • 415
17
votes
4 answers

Is there some directory walker in Haskell?

Is there some recursive directory walker in Haskell so I could write something like listing <- walkDir "/tmp" I would not like to write my own. I can install some dependency from cabal but I want it to be cross platform (at least Linux and…
Trismegistos
  • 3,745
  • 2
  • 20
  • 38
13
votes
3 answers

Python program to traverse directories and read file information

I'm just getting started with Python but already have found it much more productive than Bash shell scripting. I'm trying to write a Python script that will traverse every directory that branches from the directory I launch the script in, and for…
dvanaria
  • 6,073
  • 21
  • 58
  • 77
11
votes
7 answers

What are all the ways to traverse directory trees?

How do you traverse a directory tree in your favorite language? What do you need to know to traverse a directory tree in different operating systems? On different filesystems? What's your favorite library/module for aiding in traversing a directory…
skiphoppy
  • 83,104
  • 64
  • 169
  • 214
11
votes
5 answers

PHP: normalize path of not existing directories to prevent directory traversals?

I would like to normalize a path from an external resource to prevent directory traversal attacks. I know about the realpath() function, but sadly this function returns only the path of existing directories. So if the directory doesn't exist (yet)…
JepZ
  • 933
  • 12
  • 24
10
votes
5 answers

How to traverse all the files in a directory; if it has subdirectories, I want to traverse files in subdirectories too

opendir(DIR,"$pwd") or die "Cannot open $pwd\n"; my @files = readdir(DIR); closedir(DIR); foreach my $file (@files) { next if ($file !~ /\.txt$/i); my $mtime = (stat($file))[9]; print $mtime; print "\n"; …
Peter
  • 2,609
  • 3
  • 22
  • 47
10
votes
5 answers

Opening many small files on NTFS is way too slow

I am writing a program that should process many small files, say thousands or even millions. I've been testing that part on 500k files, and the first step was just to iterate a directory which has around 45k directories in it (including subdirs of…
Amy
  • 1,712
  • 21
  • 35
7
votes
1 answer

Ensure a user-defined path is safe in PHP

I am implementing a simple directory listing script in PHP. I want to ensure that the passed path is safe before opening directory handles and echoing the results willy-nilly. $f = $_GET["f"]; if(! $f) { $f = "/"; } // make sure $f is safe $farr…
anonymous coward
  • 11,122
  • 11
  • 60
  • 79
5
votes
2 answers

How to loop through files and rename them in Python

I have a directory of music that has album folders as well as individual songs on each level. How can I traverse all of these files that also are encoded in different formats(mp3, wav etc)? In addition is there a way I can rename them to a format…
4
votes
6 answers

Preventing directory traversal with web-facing application - are regular expressions bullet-proof?

I am in a situation where I need to allow a user to download a file dynamically determined from the URL. Before the download begins, I need to do some authentication, so the download has to run through a script first. All files would be stored…
John B
1
2 3 4 5 6