AI pentesting guides / By tech stack

Stack guide: PHP

PHP application penetration testing

PHP application pentesting targets a set of bug classes that are more common in PHP than elsewhere: local and remote file inclusion, object injection through unserialize(), loose comparison type juggling, and upload handlers that let a .php file land in a web-accessible directory.

Many PHP apps are older or custom, without a framework doing the defensive work. That makes them rewarding to test and means server configuration, not just application code, is in scope.

Inclusion and file handling

  • include($_GET['page'] . '.php') style code allows local file inclusion and, with php:// or data:// wrappers, sometimes code execution.
  • Upload handlers that check the MIME type the client sent, or only the last extension, let shell.php.jpg or a polyglot image through.
  • Uploads stored under the web root and executed by the PHP handler turn an upload bug into remote code execution.
  • Path traversal in download scripts exposes config.php and credentials.

PHP-specific logic bugs

  • Loose comparison (==) between a user string and a hash can treat '0e…' strings as equal numbers, bypassing password or token checks.
  • unserialize() on cookies or parameters enables PHP object injection when gadget chains exist in loaded libraries.
  • extract($_POST) or register_globals-style patterns overwrite internal variables.
  • SQL built with string concatenation through mysqli_query remains common in legacy code.

Server and runtime configuration

CVE-2024-4577 showed how the runtime itself can be the vulnerability: PHP-CGI on Windows with certain code pages allowed argument injection and unauthenticated code execution, with exploitation seen shortly after disclosure in June 2024. Fixed releases were 8.1.29, 8.2.20 and 8.3.8. Exposed phpinfo() pages, display_errors=On, readable .git directories and backup files such as config.php.bak are routine finds.

Sessions and authentication in plain PHP

Hand-rolled PHP authentication often stores the user ID in $_SESSION without regenerating the session ID at login, which allows session fixation. Password checks with md5 or sha1, missing rate limits on login forms, and 'remember me' cookies that contain the user ID in clear are all common. Testers also check that session cookies set Secure, HttpOnly and SameSite flags.

With Pentest-Swarm

Running Pentest-Swarm against a PHP app

Pentest-Swarm tests the PHP application through its HTTP interface. It does not need, and does not read, the source.

  • The owasp-top10 playbook covers injection, path traversal and file inclusion; dotdotpwn and sqlmap are in the arsenal for traversal and SQL injection.
  • Content discovery with ffuf, feroxbuster and gobuster looks for backups, dotfiles and admin scripts.
  • Deserialisation and object injection are among the vulnerability classes it tests for.
  • Findings that it can prove get evidence, CVSS and, where possible, a sandboxed Python proof of concept.

Where it falls short

Black-box testing of PHP finds what routes expose; it cannot locate an unserialize() call that is only reached by an admin batch job, or audit gadget chains in vendor code. Use a PHP static analyser such as PHPStan or Psalm with security rules, and keep the runtime patched independently of testing.

Questions

Is modern PHP still prone to these issues?

Modern frameworks remove many of them, but type juggling, unsafe uploads and unserialize() still appear in custom and legacy code.

Was CVE-2024-4577 only a Windows issue?

Yes, it depended on Windows Best-Fit character conversion with PHP running in CGI mode, often in XAMPP-style setups.

Do I need to give the tester server access?

No. A black-box test needs a reachable URL and test accounts. Server configuration review is a separate, complementary exercise.

Sources

  1. NVD: CVE-2024-4577