Skip to content
RCE Write-up Intermediate

Upgrade from LFI to RCE via PHP Sessions

A local file inclusion (LFI) vulnerability in a language parameter allowed reading files on the server. The attacker found that the application stored user-supplied values in PHP session files, so by injecting PHP code as a username and then including the session file via the LFI, they achieved remote code execution.

Julien Ahrens Follow

Published on web.archive.org

I recently came across an interesting Local File Inclusion vulnerability in a private bug bounty program which I was able to upgrade to a Remote Code Execution. The interesting fact about this and what makes it different is that the underlying operating system was pretty hardened and almost all usual ways to upgrade…

Julien Ahrens, on web.archive.org

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

Root cause

The application stored unsanitised user input (the username) in PHP session files, and the LFI allowed including those files, leading to code execution.

Impact

An unauthenticated attacker could achieve remote code execution on the server.

What the attacker needed

LFI vulnerability in a parameter; PHP session files stored in a predictable location; Ability to control session data via user input

How it was found

  1. Identify a 'lang' parameter vulnerable to path traversal, allowing reading of /etc/passwd.
  2. Attempt common LFI-to-RCE techniques (wrappers, logs, /proc) but find they fail due to hardening.
  3. Notice that invalid login attempts set cookies containing user input, suggesting session files store the username.
  4. Use the LFI to read the PHP session file and confirm it contains the username.
  5. Submit a username containing PHP code, which gets stored in the session file.
  6. Include the session file via the LFI (without sending the session cookie) to execute the PHP code.

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.

Local file inclusion (LFI) lets an attacker make the server read files it shouldn't, like system files. Here, the attacker also noticed that the application saved whatever username was typed into a file on the server. By putting PHP code as the username, that code got saved, and then the LFI was used to run that file, giving the attacker control of the server.

What is RCE?

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

More by Julien Ahrens

View all

17 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.