This project is a simple python script I wrote to help automate directory traversal attacks. I started this project while I was practicing offensive techniques with the Kioptrix: 2014 (#5) vulnhub machine.
I will be posting a full write up of Kioptrix: 2014 (#5) in the near future.
I tried to write the script in a way that I can continue to add new features in the future. Below I will go over how I used this script for the Kioptrix: 2014 vm.
To run the script I specified the url (-u) and server (-s).
Two things to note about the -u option, are that the url should be in quotations and the parameter in the url which is vulnerable to directory traversal should be specified by {}.
I chose to specify the url this way so that I could easily use the format function to place the series of “../” anywhere in the url.
After setting the options correctly, I needed to automate finding the root directory by trying access the /etc/passwd file.
I searched for the passwd file because Kioptrix is a linux machine which will always have /etc/passwd.
Above, is the main snippet of code to accomplish finding the root directory. Essentially, it is just a loop which will make a get request to the url with an increasing amount of “../” prepended to “/etc/passwd”.
After making the request, it will check for a 200 status code and for “root”, user variable, in the content. I added the check for user in content because Kioptrix was returning a 200 status code in every response.
You might notice that the treversal variable was written in a weird way and contains a {} in the string. An example instance of traversal is below (minus the url encoding):
I then format the string with etc/passwd while passing it to the GET request. This way I have the correct traversal path for the root directory stored in a variable.
The next thing I wanted to automate was finding the apache config file. The config file can have many different names or paths and I wanted to easily be able to test for each one.
I wrote a method which makes a get request for each entry in a list of possible config files. The naming convention for the list is ./{server}conflist
Since I had the root directory path stored in traversal, I could pass the variable to my function and format the string with the different config files.
Below is my current list of paths to test for apache (linux):
Please contact me if you have suggestions for the apache config list or lists for other servers.
As I continue to learn, I will update this tool to be able to automate exploitation of different linux and windows servers.