Skip to content
RCE Write-up Intermediate

RCE via LFI Log Poisoning - The Death Potion

A local file inclusion endpoint allowed reading of the FTP server's log file, and because the log recorded attacker-supplied usernames, a PHP payload placed in a failed FTP login was executed when the log was included. This gave the attacker remote code execution on the web server.

Jerry Shah Follow

Published on shahjerry33.medium.com

Hello everyone, I would like to share one of my recent findings on a Vulnerability Disclosure Program. It is related to how I escalated to Remote Code Execution using Local File Inclusionwith Log Poisoning.

Jerry Shah (Jerry), on shahjerry33.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

This write-up describes a finding made on a Vulnerability Disclosure Program: a Local File Inclusion (LFI) that was escalated to Remote Code Execution (RCE) through log poisoning. The report does not name the target or the program, and it does not describe the application's normal function beyond the vulnerable endpoint that takes a file path as input.

The author opens with short definitions that frame the rest of the article:

  • Remote Code Execution allows an attacker to access a system, read or delete its contents, and make changes.
  • Local File Inclusion is used to trick a web application into exposing or running files on the web server. It can lead to information disclosure, RCE or XSS. It occurs when an application uses the path to a file as input and treats that input as trusted, so a local file may be used in the include statement.
  • Log files are computer-generated data files containing information about usage patterns, activities and operations within an operating system, application, server or other device.
  • vsftpd.log traces malicious activity facilitated by the FTP service and must be configured so that all commands sent to the FTP server are logged using the verbose vsftpd log format. The default file is /var/log/vsftpd.log, and it keeps track of login activity and failed login attempts on the FTP server.
  • auth.log contains system authorisation information, including user logins and the authentication mechanisms used.
  • Log poisoning is a common technique for gaining a reverse shell from an LFI: the attacker injects malicious input into a server log.

Setup

The report does not describe any accounts, roles or credentials. The tools and observations it does mention are:

  1. An endpoint on the target that was vulnerable to LFI.
  2. nmap, used to enumerate open ports.
  3. Wappalyzer, used to fingerprint the technologies in use, which showed the application was running PHP 7 along with some other technologies.
  4. An FTP service on the target, reachable on port 21.

Finding it

The author discovered an endpoint where Local File Inclusion was present.

Local File Inclusion From the original on shahjerry33.medium.com

With the inclusion in hand, the next question was which files could actually be read. The first attempts were aimed at sensitive system files:

  1. Accessing /etc/shadow returned no result.
  2. Accessing /var/log/auth.log also returned no result.
auth.log From the original on shahjerry33.medium.com

A port scan followed to see what services were exposed.

Nmap Scan From the original on shahjerry33.medium.com

Ports 21, 22 and 80 were open. With SSH available, the author considered poisoning the SSH login log, but since /var/log/auth.log was not accessible through the web endpoint, that route was ruled out and RCE appeared impossible at that point.

The turning point was realising that FTP logs are written to a different file, /var/log/vsftpd.log, rather than to auth.log. Accessing /var/log/vsftpd.log through the endpoint succeeded and its contents were visible on the web, which made poisoning the FTP log the next step.

Exploitation

Step 1: Confirm the LFI

The endpoint was confirmed to include local files, which established the primitive used for everything that followed.

Step 2: Try sensitive files

Requests for /etc/shadow and /var/log/auth.log produced no output, so neither file was readable through the inclusion.

Step 3: Enumerate services

An nmap scan showed ports 21, 22 and 80 open.

Step 4: Find a readable log

Because the application was identified as PHP 7, a PHP payload was the right shape for the poisoned log entry. The readable log turned out to be /var/log/vsftpd.log, which the endpoint displayed successfully.

Step 5: Poison the FTP log

The author made fake login attempts against the target's FTP server, using a PHP payload as the username so that it would be written into vsftpd.log.

Text
<?php system($_GET['commandInjection']); ?>

The payload is a PHP snippet that calls system() on the commandInjection GET parameter.

FTP attempt From the original on shahjerry33.medium.com

Step 6: Trigger execution

The endpoint was then accessed with the poisoned log file and the command parameter set to ifconfig:

Text
/var/log/vsftpd.log&commandInjection=ifconfig

Including the log file with the command parameter set to ifconfig achieved Remote Code Execution.

Remote Code Execution From the original on shahjerry33.medium.com

Root cause

The application passed user-controlled input into a file include without restricting which files could be reached, so local files such as /var/log/vsftpd.log could be read. Because the server runs PHP, any PHP code present in an included file is executed rather than displayed. The FTP service logged the fake login attempts into a file that the inclusion could reach, which turned a read primitive into code execution.

Impact

An attacker who can reach the vulnerable endpoint and the FTP service can run commands on the web server. In this case the author demonstrated command execution with ifconfig.

Fix

Based on the finding, the include should not accept arbitrary paths: validate input against a strict allowlist, avoid passing user input directly into include statements, and ensure log files are not reachable through the inclusion. Restricting the FTP service's exposure would also remove the injection channel used here.

Variants to test

  1. Other readable logs. Try /var/log/vsftpd.log, mail logs, web server access logs and application logs through the inclusion. A positive result is the log contents rendering in the response.
  2. Other injection channels. If FTP is closed, try poisoning SSH authentication logs, web server access logs via the User-Agent header, or mail logs. A positive result is the payload appearing in a log file that the endpoint can include.
  3. PHP execution confirmation. After poisoning, request the log through the endpoint with a harmless command parameter. A positive result is the command output appearing in the response.
  4. Technology fingerprinting first. Use Wappalyzer or similar to confirm the server-side language before choosing a payload; a PHP payload only executes on a PHP-backed include.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

What happened, in plain words

A security researcher found a way to make a website run commands on its own server, starting from a simple feature that lets you choose which file the page shows. This is called a Local File Inclusion (LFI) and it was turned into Remote Code Execution (RCE) by planting a small piece of code in a log file that the website could be tricked into reading. The report does not name the target or the program, and it does not describe what the application normally does beyond the vulnerable endpoint that takes a file path as input.

The author begins with short definitions that frame the rest of the article:

  • Remote Code Execution allows an attacker to access a system, read or delete its contents, and make changes.
  • Local File Inclusion is used to trick a web application into exposing or running files on the web server. It can lead to information disclosure, RCE or XSS. It occurs when an application uses the path to a file as input and treats that input as trusted, so a local file may be used in the include statement.
  • Log files are computer-generated data files containing information about usage patterns, activities and operations within an operating system, application, server or other device.
  • vsftpd.log traces malicious activity facilitated by the FTP service and must be configured so that all commands sent to the FTP server are logged using the verbose vsftpd log format. The default file is /var/log/vsftpd.log, and it keeps track of login activity and failed login attempts on the FTP server.
  • auth.log contains system authorisation information, including user logins and the authentication mechanisms used.
  • Log poisoning is a common technique for gaining a reverse shell from an LFI: the attacker injects malicious input into a server log.

Setup

The report does not describe any accounts, roles or credentials. The tools and observations it does mention are:

  1. An endpoint on the target that was vulnerable to LFI.
  2. nmap, used to enumerate open ports.
  3. Wappalyzer, used to fingerprint the technologies in use, which showed the application was running PHP 7 along with some other technologies.
  4. An FTP service on the target, reachable on port 21.

Finding it

The author discovered an endpoint where Local File Inclusion was present.

Local File Inclusion From the original on shahjerry33.medium.com

With the inclusion in hand, the next question was which files could actually be read. The first attempts were aimed at sensitive system files:

  1. Accessing /etc/shadow returned no result.
  2. Accessing /var/log/auth.log also returned no result.
auth.log From the original on shahjerry33.medium.com

A port scan followed to see what services were exposed.

Nmap Scan From the original on shahjerry33.medium.com

Ports 21, 22 and 80 were open. With SSH available, the author considered poisoning the SSH login log, but since /var/log/auth.log was not accessible through the web endpoint, that route was ruled out and RCE appeared impossible at that point.

The turning point was realising that FTP logs are written to a different file, /var/log/vsftpd.log, rather than to auth.log. Accessing /var/log/vsftpd.log through the endpoint succeeded and its contents were visible on the web, which made poisoning the FTP log the next step.

Exploitation

Step 1: Confirm the LFI

The endpoint was confirmed to include local files, which established the primitive used for everything that followed.

Step 2: Try sensitive files

Requests for /etc/shadow and /var/log/auth.log produced no output, so neither file was readable through the inclusion.

Step 3: Enumerate services

An nmap scan showed ports 21, 22 and 80 open.

Step 4: Find a readable log

Because the application was identified as PHP 7, a PHP payload was the right shape for the poisoned log entry. The readable log turned out to be /var/log/vsftpd.log, which the endpoint displayed successfully.

Step 5: Poison the FTP log

The author made fake login attempts against the target's FTP server, using a PHP payload as the username so that it would be written into vsftpd.log.

Text
<?php system($_GET['commandInjection']); ?>

The payload is a PHP snippet that calls system() on the commandInjection GET parameter.

FTP attempt From the original on shahjerry33.medium.com

Step 6: Trigger execution

The endpoint was then accessed with the poisoned log file and the command parameter set to ifconfig:

Text
/var/log/vsftpd.log&commandInjection=ifconfig

Including the log file with the command parameter set to ifconfig achieved Remote Code Execution.

Remote Code Execution From the original on shahjerry33.medium.com

Root cause

The application passed user-controlled input into a file include without restricting which files could be reached, so local files such as /var/log/vsftpd.log could be read. Because the server runs PHP, any PHP code present in an included file is executed rather than displayed. The FTP service logged the fake login attempts into a file that the inclusion could reach, which turned a read primitive into code execution.

Impact

An attacker who can reach the vulnerable endpoint and the FTP service can run commands on the web server. In this case the author demonstrated command execution with ifconfig.

Fix

Based on the finding, the include should not accept arbitrary paths: validate input against a strict allowlist, avoid passing user input directly into include statements, and ensure log files are not reachable through the inclusion. Restricting the FTP service's exposure would also remove the injection channel used here.

Variants to test

  1. Other readable logs. Try /var/log/vsftpd.log, mail logs, web server access logs and application logs through the inclusion. A positive result is the log contents rendering in the response.
  2. Other injection channels. If FTP is closed, try poisoning SSH authentication logs, web server access logs via the User-Agent header, or mail logs. A positive result is the payload appearing in a log file that the endpoint can include.
  3. PHP execution confirmation. After poisoning, request the log through the endpoint with a harmless command parameter. A positive result is the command output appearing in the response.
  4. Technology fingerprinting first. Use Wappalyzer or similar to confirm the server-side language before choosing a payload; a PHP payload only executes on a PHP-backed include.

Glossary

  • Remote Code Execution (RCE): a vulnerability that lets an attacker run their own commands on a server, potentially reading, changing or deleting data.
  • Local File Inclusion (LFI): a vulnerability where a web application is tricked into including or showing files that are already on the server, often because it uses user input as a file path without proper checks.
  • Log file: a file automatically created by a computer system to record events, activities or errors.
  • vsftpd.log: the default log file for the vsftpd FTP server, which records FTP commands and login attempts.
  • auth.log: a system log file that records authentication events such as logins.
  • Log poisoning: a technique where an attacker injects malicious code into a log file, hoping that the application will later include and execute that code.
  • nmap: a tool used to discover open ports and services on a network.
  • Wappalyzer: a browser extension or tool that identifies technologies used by a website, such as programming languages and frameworks.
  • PHP: a programming language commonly used for web servers; code written in PHP is executed on the server.
  • FTP: File Transfer Protocol, a standard network protocol used to transfer files between a client and a server.
  • SSH: Secure Shell, a protocol for secure remote login and other network services.
  • Port: a numbered communication endpoint on a server; different services listen on different ports (e.g. 21 for FTP, 22 for SSH, 80 for HTTP).
  • GET parameter: a way to pass data to a web application by adding it to the URL after a question mark, e.g. ?name=value.
  • Payload: the part of an attack that carries the malicious code or data.
  • Reverse shell: a connection initiated from the victim server back to the attacker, giving the attacker command-line access.
  • Allowlist: a list of explicitly permitted items; anything not on the list is denied.
  • User-Agent header: an HTTP header that identifies the client software making the request; it can be controlled by the attacker and may be logged.
  • ifconfig: a command-line utility to display or configure network interfaces; its output can confirm command execution.

More by Jerry Shah

View all

26 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.