TL;DR
This guide shows you how to exploit a Local File Inclusion (LFI) vulnerability in the DVWA web form. We’ll use basic techniques to read sensitive files on the server.
Prerequisites
- A running instance of DVWA (Damn Vulnerable Web Application).
- Basic understanding of HTTP requests and web forms.
Steps
- Navigate to the File Inclusion Form: In DVWA, go to ‘File Inclusion’. This is where the vulnerability exists.
- Understand the Vulnerable Parameter: The form likely has a field (e.g., ‘file’) that accepts a filename as input. The application attempts to include this file directly into its response.
- Basic LFI Payload Attempt: Start with simple payloads to test if inclusion is happening at all.
/etc/passwdEnter this into the ‘file’ field and submit the form. If you see the contents of /etc/passwd displayed, the vulnerability is confirmed.
- Null Byte Injection (if needed): Some systems might terminate strings at a null byte (%00). Try adding this to your payload.
/etc/passwd%00This can bypass some basic filtering mechanisms.
- Traversal with ../: Use the ‘..’ directory traversal sequence to move up in the file system.
../../../../../../etc/passwdAdjust the number of ‘../’ sequences as needed to reach the desired file location. This attempts to navigate out of the current directory and into the root directory, then to /etc/passwd.
- Exploiting with Absolute Paths (if known): If you know the absolute path to a sensitive file, use it directly.
/var/log/apache2/access.logReplace this with the actual path of the log file on your system.
- Exploiting with /proc/self/environ: This file contains environment variables, which can reveal sensitive information like database credentials.
/proc/self/environ - URL Encoding (if needed): If special characters are causing issues, try URL encoding them. For example, ‘%2e%2e’ for ‘..’.
- Filtering Bypass Techniques: DVWA may have some basic filtering in place.
- Case Sensitivity: Try different casing (e.g., /Etc/PaSsWd).
- Whitespace: Add whitespace around the path (e.g., / etc/passwd ).
- Double Encoding: Encode characters multiple times.
- Read Important Files: Focus on reading files that commonly contain sensitive data:
/etc/passwd(User accounts)/etc/shadow(Password hashes – requires appropriate permissions, often not readable directly)/var/log/apache2/access.logor similar (Web server logs)- Configuration files for the web application (e.g., database connection strings).
Important Considerations
- Permissions: You can only read files that the web server process has permission to access.
- Error Messages: Pay attention to any error messages displayed by the application, as they may provide clues about filtering or file system structure.
- DVWA Security Level: The difficulty of exploiting this vulnerability increases with higher security levels in DVWA.

