解密.ASPXAUTH的cookie保护=验证 [英] Decrypting the .ASPXAUTH Cookie WITH protection=validation

查看:5384
本文介绍了解密.ASPXAUTH的cookie保护=验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相当一段时间我一直在试图破译ASP .ASPXAUTH cookie,并使用PHP解密。我的理由是巨大的,我要做到这一点,没有其他选择。在PHP到目前为止,我已经成功地设法从这个cookie读取数据,但我似乎无法做到这一点,而它是加密的。无论如何,这里有云...

首先,你需要改变你的服务器的Web.config文件(保护需要设置为验证):

 <身份验证模式=无>
        <ASPXAUTH形式的名称=保护=验证无Cookie =UseCookies超时=10080enableCrossAp predirects =真/>
    < /认证>

然后在同一个域中的一个PHP脚本,可以执行以下操作来读取数据,这是一个非常简单的例子,但就是明证:

  $ authCookie = $ _COOKIE ['_ ASPXAUTH'];
回声'ASPXAUTH:'$ authCookie'< BR />'.\"\
\";//This输出的明文十六进制的cookie。
$ =装包(H *,$ authCookie);
$ packed_exp =爆炸(\\ 0,$装); //这会分开使用NULL数据
$ random_bytes = array_shift($ packed_exp); //这会推卸的随机字节
回声的print_r($ packed_exp,TRUE); //这将返回你的cookies数据,而随机字节

这打破了饼干,或者至少是未加密的数据:

现在,我知道我能得到的数据,我删除了我的web.config的'保护=验证'字符串我试图使用PHP的mcrypt解密。我已经试过无数方法,但这里是一个有前途的例子(失败)...

<$p$p><$c$c>define('ASP_DECRYPT_KEY','0BC95D748C57F6162519C165E0C5DEB69EA1145676F453AB93DA9645B067DFB8');//This被解密密钥在我的Machine.config文件中(请注意,这是伪造的为例)
$ IV = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,MCRYPT_MODE_CBC),MCRYPT_RAND);
$解密= mcrypt_decrypt(MCRYPT_RIJNDAEL_128,ASP_DECRYPT_KEY,$ authCookie,MCRYPT_MODE_CBC,$ IV); // $ authCookie是包()处理Cookie数据

这不过失败。我试过IV的变化都是零@ 16字​​节。我已经尝试了不同的Rijndael尺寸(128 VS 256)。我试过base64_de code()荷兰国际集团,似乎没有任何工作。我发现这个<一个href=\"http://stackoverflow.com/questions/7387080/net-and-php-rijndael-encryption-not-matching\">stackoverflow张贴在这里并使用该密钥/ IV正在使用SHA256制成的变化开始,但是是不是真正的工作无论是。

任何人有一个线索,我应该怎么办呢?


解决方案

我不知道加密是如何在.NET AuthCookies做,但我可以尝试回答。

假设加密发生在AES CBC-IV模式,具有随机生成的IV,你需要先找出IV是。

告诉你不能工作,因为你正在生成一个随机IV(这将是不正确的)的code片段。话虽这么说,就算你得到IV错了,CBC模式下,您只需将前16个字节的解密的密文的乱码,其余将正确解密 - 你可以使用它作为一个测试来知道你是否做正确的休息。在实践中采用随机的IV的时候,它很可能,它的ppended为密文$ P $。要检查是否这是正确的,你可以尝试检查如果len(密文)= LEN(明文)+ 16,这意味着最有可能第一个16个字节是你的IV(因此它应该从密文试图之前被删除解密)。

也在你的code片段,看来你正在使用的密钥作为一个ASCII字符串,而应该是一个字节数组。尝试:

<$p$p><$c$c>define('ASP_DECRYPT_KEY',hex2bin('0BC95D748C57F6162519C165E0C5DEB69EA1145676F453AB93DA9645B067DFB8'));

此外,这似乎是一个32字节的密钥,所以你需要使用AES-256。我不知道该怎么authcookie样子,但如果它的base64 EN codeD,你也需要去code首先显而易见的。

希望这有助于!

请注意:我没有电子书籍做这个重要的生产code,但是 - 因为有很多的事情,如果你尝试,即使你在这里做,以实现自己的解密例程可能出错。特别是,我猜应该是在某个地方你的有无以的检查试图解密之前,但也有许多其他的东西可以去错实现自己的密码。

一个MAC标签

For quite sometime I've been trying to decipher the ASP .ASPXAUTH cookie and decrypt it using PHP. My reasons are huge and I need to do this, there is no alternative. In PHP so far I have successfully managed to read the data from this cookie, but I cannot seem to do it while it is encrypted. Anyway, here it goes...

First you need to alter your servers Web.config file (protection needs to be set to Validation):

    <authentication mode="None">
        <forms name=".ASPXAUTH" protection="Validation" cookieless="UseCookies" timeout="10080" enableCrossAppRedirects="true"/>
    </authentication>

Then in a PHP script on the same domain, you can do the following to read the data, this is a very basic example, but is proof:

$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

This breaks down the cookie, or at least the unencrypted data:

Now that I know I can get the data, I removed the 'protection="validation"' string from my Web.config and I tried to decrypt it using PHP mcrypt. I have tried countless methods, but here is a promising example (which fails)...

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

This however fails. I've tried variations of IV with all zeros @ 16 bytes. I've tried different Rijndael sizes (128 vs 256). I've tried base64_decode()ing, nothing seems to work. I've found this stackoverflow post here and started using variations of the key/iv that are made using sha256, but that isn't really working either.

Anybody have a clue what I should do?

解决方案

I don't know how encryption is made in .NET AuthCookies, but I can try to answer.

Assuming the encryption occurs in AES CBC-IV mode, with randomly generated IVs, you need to first find out where the IV is.

The code snippet you show cannot work, as you are generating a random IV (which will be incorrect). That being said, even if you get the IV wrong, in CBC mode you will only have the first 16 bytes of your decrypted ciphertext "garbled" and the rest will decrypt properly - you can use this as a test to know if you're doing the rest correctly. In practice when using random IVs, it's very likely that it's prepended to the ciphertext. To check if this correct, you can try to check if len(ciphertext) = len(plaintext) + 16. This would mean that most likely the first 16 bytes are your IV (and therefore it should be removed from the ciphertext before attempting to decrypt it).

Also on your code snippet, it seems you are using the key as an ascii-string, whereas it should be a byte array. Try:

define('ASP_DECRYPT_KEY',hex2bin('0BC95D748C57F6162519C165E0C5DEB69EA1145676F453AB93DA9645B067DFB8'));

Also, this seems to be a 32 byte key, so you need to use AES-256. I don't know how the authcookie looks like, but if it's base64 encoded, you also need to decode it first obviously.

Hope this helps!

Note: I don't recomment doing this for important production code, however - because there are many things that can go wrong if you try to implement even your own decryption routine as you are doing here. In particular, I would guess there should be a MAC tag somewhere that you have to check before attempting decryption, but there are many other things that can go wrong implementing your own crypto.

这篇关于解密.ASPXAUTH的cookie保护=验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆