Introduction
In web application security, discovering hidden files and directories is a critical step in the reconnaissance phase. Many applications store sensitive configuration, version control, or environment variables in files prefixed with a dot (e.g., .env, .git, .htaccess). These files are often hidden by default in file browsers and web servers, making them less obvious targets. However, if misconfigured, they can be directly accessible via a web server, leading to severe information disclosure vulnerabilities.
Gobuster is a powerful directory and file brute-forcing tool that can be used to uncover these hidden assets. By providing a targeted wordlist containing common dot-prefixed filenames, you can significantly increase your chances of finding valuable information that might otherwise be missed.
This lab will guide you through the process of using Gobuster to specifically target and discover these hidden dot-prefixed files. You will learn how to prepare a suitable wordlist, execute a Gobuster scan, and interpret the results to identify potential security risks.
Understand the Significance of Dot-Prefixed Files (e.g., .env, .git)
In this step, we will understand why dot-prefixed files are important in the context of web security. Files like .env, .git, .htaccess, .bashrc, or .ssh are commonly used in Linux and web development environments to store configuration, version control data, or sensitive credentials.
.envfiles: These files store environment variables, often including database credentials, API keys, and other sensitive application settings. If exposed, they can grant an attacker full access to backend systems..gitdirectories: If a.gitdirectory is exposed on a web server, it can allow an attacker to download the entire source code repository, including commit history, sensitive files that were once part of the repository, and internal comments..htaccessfiles: Used by Apache web servers to configure directory-level settings, including authentication, authorization, and URL rewriting. Misconfigurations or exposure can lead to bypasses or information disclosure.
While these files are typically hidden by default in file explorers and are often intended to be inaccessible via web servers, misconfigurations can inadvertently expose them. Discovering them during reconnaissance can provide critical insights into the target application's infrastructure and potential vulnerabilities.
We have set up a simple web server in the background for this lab, serving content from /tmp/web_root. This directory contains a hidden .env file and a .hidden_config file, which we will attempt to discover.
Create or Find a Wordlist Containing Dot-Prefixed Filenames
In this step, we will prepare a wordlist specifically designed to find dot-prefixed files. While many general-purpose wordlists exist (like those in SecLists), creating a targeted one can be more efficient for this specific task.
We will create a simple wordlist named dotfiles.txt in your ~/project directory. This wordlist will contain common dot-prefixed filenames that we want Gobuster to check for.
First, navigate to your project directory:
cd ~/project
Now, create the dotfiles.txt file using nano and add some common dot-prefixed filenames.
nano dotfiles.txt
Inside nano, add the following lines:
.env
.git
.htaccess
.bashrc
.profile
.ssh
.hidden_config
Press Ctrl+S to save the file and Ctrl+X to exit nano.
You can verify the content of the wordlist using cat:
cat dotfiles.txt
You should see the list of dot-prefixed filenames you just added.
.env
.git
.htaccess
.bashrc
.profile
.ssh
.hidden_config
This wordlist will be used by Gobuster to brute-force for the existence of these specific files on the target web server.
Run a gobuster dir Scan with this Specific Wordlist
In this step, we will execute a gobuster dir scan using the dotfiles.txt wordlist we created. We will target the dummy web server running on http://127.0.0.1:8000.
The basic syntax for gobuster dir is:
gobuster dir -u <target_url> -w <wordlist_path>
Here, -u specifies the target URL, and -w specifies the path to the wordlist.
Execute the following command in your terminal:
gobuster dir -u http://127.0.0.1:8000 -w ~/project/dotfiles.txt
Let's break down the command:
gobuster dir: Specifies that we want to perform a directory/file brute-forcing scan.-u http://127.0.0.1:8000: Sets the target URL to our local dummy web server.-w ~/project/dotfiles.txt: Tells Gobuster to use our customdotfiles.txtwordlist.
After running the command, Gobuster will start iterating through the wordlist and making requests to the target server. You should see output similar to this, indicating the discovered files:
===============================================================
Gobuster vX.X.X.X-XXXXX Linux/amd64
===============================================================
[+] Url: http://127.0.0.1:8000
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /home/labex/project/dotfiles.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/X.X.X
[+] Timeout: 10s
===============================================================
2024/01/01 12:00:00 Starting gobuster in directory enumeration mode
===============================================================
/.env (Status: 200) [Size: 20]
/.hidden_config (Status: 200) [Size: 27]
===============================================================
2024/01/01 12:00:00 Finished
===============================================================
As you can see, Gobuster successfully identified .env and .hidden_config files, both returning a 200 OK status, indicating they are accessible.
Use the --no-error Flag to Hide Connection Errors
In this step, we will learn about the --no-error flag in Gobuster. When performing scans, especially against unstable targets or when dealing with network issues, Gobuster might output a lot of connection error messages. These errors can clutter the output and make it harder to spot legitimate findings.
The --no-error flag tells Gobuster to suppress these connection-related error messages, providing a cleaner output focused on successful discoveries.
Let's re-run the Gobuster scan, this time including the --no-error flag. While our current local server is stable, this flag is very useful in real-world scenarios.
gobuster dir -u http://127.0.0.1:8000 -w ~/project/dotfiles.txt --no-error
You will notice that the output is similar to the previous step, as there were no connection errors to suppress in our stable local environment. However, in a real-world scenario with many requests and potential network issues, this flag would significantly reduce noise.
The primary purpose of this flag is to improve readability of the scan results by filtering out irrelevant error messages, allowing you to focus on the actual findings (e.g., 200 OK responses).
Analyze the Results for Sensitive File Disclosures
In this final step, we will analyze the results obtained from the Gobuster scan and understand the implications of discovering such files.
From the output of our previous Gobuster scan, we found:
/.env(Status: 200) [Size: 20]/.hidden_config(Status: 200) [Size: 27]
A 200 OK status code indicates that the file was found and is accessible via the web server. This is a critical finding.
To demonstrate the impact, let's try to access the .env file directly using curl:
curl http://127.0.0.1:8000/.env
You should see the content of the .env file:
DB_PASSWORD=supersecret
This clearly shows that sensitive information (a database password in this case) has been exposed. In a real-world scenario, an attacker could use this information to gain unauthorized access to databases or other backend systems.
Similarly, you can try to access the .hidden_config file:
curl http://127.0.0.1:8000/.hidden_config
Output:
This is another hidden file.
While this specific file might not contain highly sensitive data, its discovery indicates a potential misconfiguration where files intended to be hidden are publicly accessible. This could lead to further enumeration and discovery of more critical assets.
Key Takeaways:
- Always check for dot-prefixed files during web reconnaissance.
- The presence of such files with a
200 OKstatus is a strong indicator of information disclosure. - Developers and system administrators should ensure that sensitive files are never directly accessible via a web server, typically by configuring server rules (e.g., Nginx
locationblocks, ApacheDirectorydirectives) or placing them outside the web root.
This exercise highlights the importance of thorough reconnaissance and the power of tools like Gobuster in uncovering hidden vulnerabilities.
Summary
In this lab, you have successfully learned how to use Gobuster to discover hidden files and directories prefixed with a dot. You started by understanding the significance of such files, which often contain sensitive information like environment variables or version control data.
You then created a targeted wordlist containing common dot-prefixed filenames and used it to perform a gobuster dir scan against a dummy web server. You observed how Gobuster effectively identified accessible hidden files like .env and .hidden_config. Furthermore, you learned about the --no-error flag to clean up scan output by suppressing connection errors.
Finally, you analyzed the results, demonstrating how direct access to a .env file can lead to the disclosure of critical credentials. This lab emphasized the importance of including dot-file enumeration in your reconnaissance methodology to uncover potential information disclosure vulnerabilities in web applications.
By mastering this technique, you are better equipped to identify and report security risks that might otherwise go unnoticed.
