Skip to content
RCE Write-up Intermediate

From LFI to RCE via /var/log/sshd.log

An LFI vulnerability allowed reading arbitrary files, and by injecting a PHP payload into SSH log files via failed login attempts, an attacker could achieve remote code execution.

medium.com

Published on medium.com

Disclaimer: This content is foreducational purposes only. The author isnot responsible for any use or misuseof the information provided.

Zoningxtr, on 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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker could execute arbitrary commands on the server, leading to full compromise.

What the attacker needed

LFI vulnerability present; SSH service logging to a readable file; Web server executes PHP in log files

The fix

The application should validate file paths against a whitelist, disable PHP execution in log files, and restrict file inclusion with open_basedir.

How it was found

  1. Test for LFI by requesting /etc/passwd through the page parameter.
  2. Try to read SSH log files such as auth.log, secure, or sshd.log via LFI.
  3. Inject a PHP payload as the SSH username by attempting an SSH login.
  4. Verify the payload appears in the log by reading it again via LFI.
  5. Trigger code execution by including the log file and passing a command parameter.
  6. Set up a listener and use the command execution to obtain a reverse shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A local file inclusion (LFI) bug lets an attacker make a web server read files it shouldn't, like system logs. If the attacker can write something into a log file (for example, by trying to log in with a strange username), and the server later reads that log as code, the attacker can run commands on the server. This is called log poisoning leading to remote code execution.

What is RCE?

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

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.