PHP proc_open与John the Ripper无法正常工作

时间:2012-02-01 23:34:24

标签: php process exec

我正在尝试从PHP脚本运行John the Ripper。我想运行它,然后监视它的输出,相应地做出反应。但是,事情不能按预期工作,我得到的结果(据我的理解)是随机的。我可以想象我错过了什么。

问题是输出流不会产生任何输出。对于John来说这有些正常 - 当用户使用键盘键入字符时会产生输出。所以,我写信给我设置的stdin管道。然而,这并不会导致约翰产生输出。有什么建议吗?

代码:

<?php

$descriptorspec = array (
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "w")   // stderr is a file to write to
);

// JOHN is the full path to the john executable
$command = JOHN . " --nolog --config=" . dirname (JOHN) . "/john.conf working/hashes-job-{$_POST['id']} --pot=working/hashes-job-{$_POST['id']}.pot";// --format=raw-md5";
$process = proc_open ($command, $descriptorspec, $pipes);

if (is_resource ($process)) {
    sleep(5);
    fwrite ($pipes[0], "a\n");
    fflush ($pipes[0]);
    while (!feof ($pipes[1])) {
            // I have tried with the following uncommented as well
            // That led to the while loop exiting prematurely for some reason...
        // stream_set_blocking($pipes[1], false);
        $output = fread ($pipes[1], 4096);
        // stream_set_blocking($pipes[1], true);

        file_put_contents ('/tmp/dpcp-tool-' . time (), $output);
        fwrite ($pipes[0], 'a');
        fflush ($pipes[0]);
        file_put_contents ('/tmp/publishOutcome-' . time (), $reply);
        sleep(5);
    }

    file_put_contents('/tmp/died-' . time(), $entered);
    fclose ($pipes[0]);
    fclose ($pipes[1]);
    $return_value = proc_close ($process);
}

0 个答案:

没有答案