Directory and File Fuzzing

Overview

Directory and file fuzzing is a technique used in web application security testing to uncover hidden directories and files which may not be directly accessible through the main user interface. These hidden resources can contain:

Importance

Methodology

Directory and file fuzzing involves:

Wordlists

Role of Wordlists

Sources

Tools & Compatibility

Key Wordlists from SecLists

SecLists GitHub Repository
https://github.com/danielmiessler/SecLists

Actually Fuzzing

We'll use ffuf, a powerful and flexible fuzzing tool, to uncover hidden directories and files on our target web application.

ffuf

Here's how ffuf generally works:

  1. Wordlist: You provide ffuf with a wordlist containing potential directory or file names.
  2. URL with FUZZ keyword: You construct a URL with the FUZZ keyword as a placeholder where the wordlist entries will be inserted.
  3. Requestsffuf iterates through the wordlist, replacing the FUZZ keyword in the URL with each entry and sending HTTP requests to the target web server.
  4. Response Analysisffuf analyzes the server's responses (status codes, content length, etc.) and filters the results based on your criteria.

For example, if you want to fuzz for directories, you might use a URL like this:

http://localhost/FUZZ

Directory Fuzzing

The first step is to perform directory fuzzing, which helps us discover hidden directories on the web server. For example

m4cc18@htb[/htb]$ ffuf -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://IP:PORT/FUZZ

Output:

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://IP:PORT/FUZZ
 :: Wordlist         : FUZZ: /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-399
________________________________________________

[...]

w2ksvrus                [Status: 301, Size: 0, Words: 1, Lines: 1, Duration: 0ms]
:: Progress: [220559/220559] :: Job [1/1] :: 100000 req/sec :: Duration: [0:00:03] :: Errors: 0 ::

File Fuzzing

While directory fuzzing focuses on finding folders, file fuzzing dives deeper into discovering specific files within those directories or even in the root of the web application. Web applications use various file types to serve content and perform different functions. Some common file extensions include:

By fuzzing for these common extensions with a wordlist of common file names, we increase our chances of discovering files that might be unintentionally exposed or misconfigured, potentially leading to information disclosure or other vulnerabilities.

For example, if the website uses PHP, discovering a backup file like config.php.bak could reveal sensitive information such as database credentials or API keys. Similarly, finding an old or unused script like test.php might expose vulnerabilities that attackers could exploit.

Here is how you can utilize ffuf and a wordlist of common file names to search for hidden files with specific extensions:

m4cc18@htb[/htb]$ ffuf -w /usr/share/seclists/Discovery/Web-Content/common.txt -u http://IP:PORT/w2ksvrus/FUZZ.html -e .php,.html,.txt,.bak,.js -v 

Output:


        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://IP:PORT/w2ksvrus/FUZZ.html
 :: Wordlist         : FUZZ: /usr/share/seclists/Discovery/Web-Content/common.txt
 :: Extensions       : .php .html .txt .bak .js 
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________

[Status: 200, Size: 111, Words: 2, Lines: 2, Duration: 0ms]
| URL | http://IP:PORT/w2ksvrus/dblclk.html
    * FUZZ: dblclk

[Status: 200, Size: 112, Words: 6, Lines: 2, Duration: 0ms]
| URL | http://IP:PORT/w2ksvrus/index.html
    * FUZZ: index

:: Progress: [28362/28362] :: Job [1/1] :: 0 req/sec :: Duration: [0:00:00] :: Errors: 0 ::

The ffuf output shows that it discovered two files within the /w2ksvrus directory:


Exercise

TARGET: 94.237.122.57:59531

Challenge 1

Within the "webfuzzing_hidden_path" path on the target system (ie http://IP:PORT/webfuzzing_hidden_path/), fuzz for folders and then files to find the flag.

1. Directory fuzzing

First perform directory fuzzing using ffuf under the "webfuzzing_hidden_path":

┌──(macc㉿kaliLab)-[~]
└─$ ffuf -w ~/SecLists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt -u http://94.237.122.57:59531/webfuzzing_hidden_path/FUZZ

Output:

...
flag                    [Status: 301, Size: 0, Words: 1, Lines: 1, Duration: 76ms]
...

2. File fuzzing

Secondly, perform file fuzzing using ffuf under the directory we just discovered during our previous directory fuzz:

┌──(macc㉿kaliLab)-[~]
└─$ ffuf -w ~/SecLists/Discovery/Web-Content/common.txt -u http://94.237.122.57:59531/webfuzzing_hidden_path/flag/FUZZ.html -e .php,.html,.txt,.bak,.js -v

Output:

...
[Status: 200, Size: 100, Words: 2, Lines: 2, Duration: 77ms]
| URL | http://94.237.122.57:59531/webfuzzing_hidden_path/flag/flag.html
    * FUZZ: flag
...
[Status: 200, Size: 104, Words: 6, Lines: 2, Duration: 77ms]
| URL | http://94.237.122.57:59531/webfuzzing_hidden_path/flag/index.html
    * FUZZ: index
...

3. Look for the flag

Examine both the flag.html and index.html files to look for any flag-like content. For this, we can use a simple curl command.

┌──(macc㉿kaliLab)-[~]
└─$ curl http://94.237.122.57:59531/webfuzzing_hidden_path/flag/flag.html

Output:

<html><head><title>Index page</title></head><body><h1>HTB{w3b_f1l3_fuzz1ng_fl4g}</h1></body></html>

flag: HTB