我尝试在centos上用php运行cmsmap,并使用timeout linux命令-检索输出失败
你好
我试着每天在我的网站上运行cmsmap。这是执行一个php脚本和结果是自动发送给我的邮件。问题是,我想在每页80秒后取消作业,所以我尝试使用两种不同的方法: -timeout命令:timeout 80 python3 cmsmap.py -我在这里找到了一个php进程终止脚本:https://blog.dubbelboer.com/2012/08/24/execute-with-timeout.html
我用sqlmap做了同样的事情,它工作得非常好。 奇怪的是:在运行cmsmap.py时,如果使用超时版本,会产生以下输出(即使所有输出都应该重定向到php脚本):
[i]找到(#1):/home/merlin/exploitdb/files#u shellcodes.csv
[i]要删除此邮件,请编辑“/home/merlin/exploitdb/.searchsploit\u rc”中的“files\u shellcodes.csv”(包\数组:exploitdb)
(还有更多此类警报)
是不是这就是问题所在,这就是为什么我没有收到来自cmsmap.py的任何输出
谢谢你的帮助
梅林
<?php
function exec_timeout($cmd, $timeout) {
/*------------------------------------------------------------------- USING TIMEOUT ----------------------------------------------------------------*/
/*$cmd = "timeout ".$timeout." ".$cmd;
var_dump($cmd);
exec($cmd, $output, $return_var);
return implode("\n", $output);*/
/*------------------------------------------------------------------- https://blog.dubbelboer.com/2012/08/24/execute-with-timeout.html ----------------------------------------------------------------*/
// File descriptors passed to the process.
$descriptors = array(
0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w') // stderr
);
// Start the process.
$process = proc_open('exec ' . $cmd, $descriptors, $pipes);
if (!is_resource($process)) {
throw new \Exception('Could not execute process');
}
// Set the stdout stream to non-blocking.
stream_set_blocking($pipes[1], 0);
// Set the stderr stream to non-blocking.
stream_set_blocking($pipes[2], 0);
// Turn the timeout into microseconds.
$timeout = $timeout * 1000000;
// Output buffer.
$buffer = '';
// While we have time to wait.
while ($timeout > 0) {
$start = microtime(true);
// Wait until we have output or the timer expired.
$read = array($pipes[1]);
$other = array();
stream_select($read, $other, $other, 0, $timeout);
// Get the status of the process.
// Do this before we read from the stream,
// this way we can't lose the last bit of output if the process dies between these functions.
$status = proc_get_status($process);
// Read the contents from the buffer.
// This function will always return immediately as the stream is non-blocking.
$buffer .= stream_get_contents($pipes[1]);
if (!$status['running']) {
// Break from this loop if the process exited before the timeout.
break;
}
// Subtract the number of microseconds that we waited.
$timeout -= (microtime(true) - $start) * 1000000;
}
// Check if there were any errors.
// No Errors!!!
/*$errors = stream_get_contents($pipes[2]);
if (!empty($errors)) {
throw new \Exception($errors);
}*/
// Kill the process in case the timeout expired and it's still running.
// If the process already exited this won't do anything.
proc_terminate($process, 9);
// Close all streams.
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
return $buffer;
}
?>
[i]找到(#1):/home/merlin/exploitdb/files#u shellcodes.csv [i] 要删除此邮件,请编辑“/home/merlin/exploitdb/.searchsploit\u rc”以获取“files\u shellcodes.csv”(包\数组:exploitdb)
目前没有回答
相关问题 更多 >
编程相关推荐