Skip to content
Access control Write-up Advanced

Hacking websites with PHP Deserialization + LFI + PHP

A PHP application exposed its own source code through .phps files reachable via a local file inclusion, revealing an authentication check that deserialised a user-supplied object. An attacker could craft a serialised object of an existing class to make the admin check pass and reach the flag route.

medium.com

Published on medium.com

Using PHP(S) files -> source files instead of PHP to bypass WAF to access source code. From there a deserialization vulnerability can be abused.

Alimuhammadsecured, 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 bypass the admin check and reach the flag route; the text does not claim remote code execution was achieved.

What the attacker needed

A local file inclusion flaw; .phps source files publicly reachable; ability to set a cookie

The fix

The application should not deserialise user-supplied data for authorisation decisions, and .phps source files should not be publicly reachable.

How it was found

  1. Notice an admin.phps file that is not meant to be spidered and does not exist when visited directly
  2. Use the local file inclusion to read index.phps, which points to further PHP source files
  3. Read authentication.php and the permission object code to see the deserialisation
  4. Build a serialised object of the access_log class and base64-encode it
  5. Place the encoded object in a cookie using a cookie editor
  6. Request the flag route so the deserialised object is used

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.

Some PHP servers will show the source code of a file ending in .phps instead of running it, so anyone who can read that file learns how the site works. Here a file-reading flaw let the author open those source files and see that the site trusted data sent by the browser, which it turned back into a program object. By sending a hand-made object of a class the site already had, the author could make the 'are you an admin' check pass.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.