News for hackers. Stuff that matters.
Re:Alert: Backdoor placed in Piwik by tomjen3 on Tuesday November 27, 2012 @09:29AM (#4837231)
Makes me wonder if you can simply disable to the 'eval' command in php and avoid all these hacks?

Is it ever used by legitimate scripts?

Re:Alert: Backdoor placed in Piwik by RobAley on Tuesday November 27, 2012 @09:41AM (#4837291)
Yes, you can disable any arbitrary internal function in PHP using disable_functions[1] directive in php.ini

[1] http://php.net/manual/en/ini.core.php#ini.disable-functions

Edit: Also, as noted below, this wouldn't prevent this or many other similar hacks as you need write access to the PHP script to put the eval in in the first place, so you could just write other code in there directly (and pull in extra scripts to execute by writing to disk etc. if necessary). Eval is typically dangerous, in its own right, when it is used by the legitimate developer who then allows unchecked code to be passed to it.

Re:Alert: Backdoor placed in Piwik by infinity on Tuesday November 27, 2012 @10:50AM (#4837421)
The problem with disable_functions is that eval is not an internal function, but a language construct. From the manual:

Only internal functions can be disabled using this directive.

It is possible to generate something like a list of all available internal functions, eval is missing here:

  $arr = get_defined_functions();
  var_dump($arr['internal']);
The Suhosin extension will let you block eval, if it is available:

http://www.hardened-php.net/suhosin/configuration.html#suhos...

Re:Alert: Backdoor placed in Piwik by RobAley on Tuesday November 27, 2012 @11:03AM (#4837509)
Apologies, you are correct, I was thinking of exec.
Re:Alert: Backdoor placed in Piwik by degenerate on Tuesday November 27, 2012 @09:51AM (#4837335)
And how to use it: http://www.cyberciti.biz/faq/linux-unix-apache-lighttpd-phpi...

Just remove anything you use. I use cURL, so I took it out.

Re:Alert: Backdoor placed in Piwik by maratd on Tuesday November 27, 2012 @09:34AM (#4837248)
> Makes me wonder if you can simply disable to the 'eval' command in php and avoid all these hacks?

I wish.

> Is it ever used by legitimate scripts?

There are edge cases, but I haven't found a need for it in almost a decade of coding. I really wish there was an option to disable it while compiling the PHP binary or using php.ini ...

Keep in mind, removing eval wouldn't have stopped this hack. It would have simply made it more obvious, since they wouldn't be able to encode/compress their injected code.

Re:Alert: Backdoor placed in Piwik by Xylakant on Tuesday November 27, 2012 @11:00AM (#4837488)
There are some legitimate uses. The pear SOAP library used it to generate access classes based on WSDL-Files - don't know if they still do that.

Anyways, disabling eval doesn't buy you much: If you really want to execute code, write it to a file and then require that file. You can plug that one by making all directories you can load code from unwriteable, but then I could just go and call create_user_func() which is eval in disguise.

Re:Alert: Backdoor placed in Piwik by nivla on Tuesday November 27, 2012 @02:28PM (#4838372)
>disabling eval doesn't buy you much: If you really want to execute code, write it to a file and then require that file.

Eval is used by most attackers to avoid detection. A one liner add to the end of a legitimate random php file along with extra padding to push it off the screen will make most users to miss it.

Creating directories and files not only requires appropriate permissions but is also more susceptible to be noticed by a user browsing through them.

Re:Alert: Backdoor placed in Piwik by Xylakant on Wednesday November 28, 2012 @05:39AM (#4841873)
Do you really think anybody would have noticed a "include 'common/footer.php'" at the end of the file? If you have write access to the download tarball, all is lost. Disabling eval on the deploy machine doesn't buy you anything. In general: If you can write to any file in the deployed app, every bet is off - eval or not. Disabling eval helps you in cases where the legitimate code uses eval and can be tricked into passing code snippets of your choice to the call.
Re:Alert: Backdoor placed in Piwik by maratd on Tuesday November 27, 2012 @02:38PM (#4838447)
Re:Alert: Backdoor placed in Piwik by mcovey on Wednesday November 28, 2012 @04:59PM (#4845014)
I've used it in a template renderer to render templates from files or strings. You can use eval('?>'.$string). There may be a better method, I never bothered looking after that worked.
Re:Alert: Backdoor placed in Piwik by halfdan on Saturday December 01, 2012 @09:13AM (#4857646)
Re:Alert: Backdoor placed in Piwik by rplnt on Tuesday November 27, 2012 @09:34AM (#4837249)
I would worry so, yes. There was/is so many PHP (and Java for that matter) jobs available that even the worst coders get hired in the end.
Re:Alert: Backdoor placed in Piwik by rjbond3rd on Tuesday November 27, 2012 @01:22PM (#4837948)
This doesn't seem like a "PHP coding quality" issue to me -- more like a trust issue, because the site admin opened the security hole by installing a WP plugin.

That could happen in any language / framework / situation. It's rogue code that got trusted.

Re:Alert: Backdoor placed in Piwik by rplnt on Tuesday November 27, 2012 @04:36PM (#4839229)
Yes, you are right. I was responding to the use of eval in production code.
Re:Alert: Backdoor placed in Piwik by camus on Tuesday November 27, 2012 @04:36PM (#4839227)
Saying that doesnt make you a better programmer, nor smart.