a large portion of vulnerable web apps run PHP — WordPress, legacy apps, custom CMSs.
during a pentest, you'll sometimes get access to source code (via git exposure, file inclusion, or white-box testing).
you need to read PHP code and spot the dangerous patterns: where does user input go, and does it reach an unsafe function?
you don't write PHP. you audit it.
what i need to be able to do :
>read basic PHP — variables, functions, conditionals, includes
>recognize dangerous functions: system(), exec(), eval(), include(), unserialize()
>understand $_GET, $_POST, $_COOKIE as user-controlled attack surface
>understand PHP type juggling — loose == comparison leading to auth bypass
>understand PHP wrappers — php://filter, php://input (used in LFI attacks)
// what dangerous PHP code looks like
<?php
// vulnerable to local file inclusion (LFI):
$page = $_GET['page']; // user controls this
include($page . '.php'); // user controls what gets included
// attacker sends: ?page=../../../../etc/passwd%00
// server includes /etc/passwd — reads system files
// vulnerable to remote code execution:
$cmd = $_GET['cmd'];
system($cmd); // executes arbitrary OS commands
// attacker sends: ?cmd=id
// server responds: uid=33(www-data) — full command execution
?>
where to learn :
>PentesterLab — code review exercises (PHP-heavy, free tier available)
>read HTB writeups that involve source code review
>PHP manual — look up specific functions as you encounter them