我已经尝试了很长时间来解密ASP .ASPXAUTH cookie并且使用PHP进行解密。我的原因非常重要,我必须这样做,没有其他选择。到目前为止,在PHP中我已经成功地从该cookie中读取了数据,但是在加密时似乎无法这样做。无论如何,接下来就开始吧...
首先,您需要修改服务器的Web.config文件(protection需要设置为Validation):
<authentication mode="None">
<forms name=".ASPXAUTH" protection="Validation" cookieless="UseCookies" timeout="10080" enableCrossAppRedirects="true"/>
</authentication>
然后,在同一域名下的 PHP 脚本中,您可以执行以下操作来读取数据。这是一个非常基本的示例,但可以证明:
$authCookie = $_COOKIE['_ASPXAUTH'];
echo 'ASPXAUTH: '.$authCookie.'<br />'."\n";//This outputs your plaintext hex cookie
$packed = pack("H*",$authCookie);
$packed_exp = explode("\0",$packed);//This will separate your data using NULL
$random_bytes = array_shift($packed_exp);//This will shift off the random bytes
echo print_r($packed_exp,TRUE); //This will return your cookies data without the random bytes
这个过程会分解cookie,或者至少是未加密的数据:
现在我知道如何获取这些数据后,我从Web.config中移除了'protection="validation"'字符串,并尝试使用PHP mcrypt进行解密。我已经尝试了无数种方法,但以下是一个有希望的例子(失败了)...
define('ASP_DECRYPT_KEY','0BC95D748C57F6162519C165E0C5DEB69EA1145676F453AB93DA9645B067DFB8');//This is a decryption key found in my Machine.config file (please note this is forged for example)
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, ASP_DECRYPT_KEY, $authCookie, MCRYPT_MODE_CBC, $iv);//$authCookie is the pack()'d cookie data
然而,这个方法失败了。我已经尝试过各种16字节全零IV的变化形式,尝试了不同的Rijndael大小(128 vs 256),也尝试过使用base64_decode(),但似乎都没起作用。我在这里找到了一个stackoverflow帖子并开始尝试使用使用sha256生成的key/iv的变化形式,但那也没有真正起作用。
有人知道我应该做什么吗?