将字符串传递给php,然后将其传递回Powershell

时间:2017-10-12 07:41:26

标签: php powershell variables

我有一个Powershell变量,它是一个随机生成的密码,然后我想将其传递给PHP脚本。在我的PHP脚本中处理生成的密码(哈希),然后我需要将其传递回Powershell。

怎么做? 编辑12.10.2017: 这是实际守则。 他们是一个在Powershell得到所有人的方式我不能编程,而我的英语很糟糕。 最多的代码是复制和粘贴所以:DD我不明白所有:(

return shell_exec($unsanitized);
}

function PowerShellFile($File)
{
$unsanitized = sprintf('powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -File "%s"', $File);

return shell_exec($unsanitized);
}


define("PBKDF2_HASH_ALGORITHM", "sha256");
define("PBKDF2_ITERATIONS", 1000);
define("PBKDF2_SALT_BYTE_SIZE", 24);
define("PBKDF2_HASH_BYTE_SIZE", 24);
define("HASH_SECTIONS", 4);
define("HASH_ALGORITHM_INDEX", 0);
define("HASH_ITERATION_INDEX", 1);
define("HASH_SALT_INDEX", 2);
define("HASH_PBKDF2_INDEX", 3);
define("USE_OPENSSL_RANDOM", false);
function pbkdf2_create_hash($password)
{
    // format: algorithm:iterations:salt:hash
    $salt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTE_SIZE, MCRYPT_DEV_URANDOM));
    return PBKDF2_HASH_ALGORITHM . ":" . PBKDF2_ITERATIONS . ":" .  $salt . ":" .
    base64_encode(pbkdf2_apply(
        PBKDF2_HASH_ALGORITHM,
        $password,
        $salt,
        PBKDF2_ITERATIONS,
        PBKDF2_HASH_BYTE_SIZE,
        true
    ));
}
    function pbkdf2_apply($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
    $algorithm = strtolower($algorithm);
    if(!in_array($algorithm, hash_algos(), true))
    die('PBKDF2 ERROR: Invalid hash algorithm.');
    if($count <= 0 || $key_length <= 0)
    die('PBKDF2 ERROR: Invalid parameters.');
    $hash_length = strlen(hash($algorithm, "", true));
    $block_count = ceil($key_length / $hash_length);
    $output = "";
    for ($i = 1; $i <= $block_count; $i++) {

        $last = $salt . pack("N", $i);

        $last = $xorsum = hash_hmac($algorithm, $last, $password, true);

        for ($j = 1; $j < $count; $j++) {
            $xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
        }
    $output .= $xorsum;
    }
    if($raw_output)
        return substr($output, 0, $key_length);
    else
        return bin2hex(substr($output, 0, $key_length));
}

(array)$userr = file("test.txt");
foreach($userr AS $user)
{





 echo "\n";


/**********************************************************************/



$password =PowerShellCommand("C:\Users\Pydio\Desktop\zufall.ps1");

$hash = pbkdf2_create_hash($password);
echo $hash;

}

0 个答案:

没有答案