解密.ASPXAUTH Cookie WITH protect =验证 [英] Decrypting the .ASPXAUTH Cookie WITH protection=validation

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

问题描述

有一段时间,我一直在尝试破译ASP .ASPXAUTH cookie并使用PHP进行解密。我的理由很大,我需要这样做,别无选择。在PHP到目前为止,我已经成功地设法读取了这个cookie的数据,但是加密时似乎并没有这样做。无论如何,这里它... ...



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

 < authentication mode =None> 
< forms name =。ASPXAUTHprotection =验证cookieless =UseCookiestimeout =10080enableCrossAppRedirects =true/>
< / authentication>

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

  $ authCookie = $ _COOKIE ['_ ASPXAUTH']; 
echo'ASPXAUTH:'$ authCookie。'< br />'.\"\\\
/////输出你的明文十六进制cookie
$ packed = pack(H *, $ authCookie);
$ packed_exp = explode(\0,$ packed); //这将使用NULL分隔您的数据
$ random_bytes = array_shift($ packed_exp); //这将移除随机字节
echo print_r($ packed_exp,TRUE); //这将返回您的Cookie数据,而不是随机字节

这会打破cookie,或至少未加密的数据:





现在我知道我可以获取数据,我从我的Web中删除了'protection =验证'字符串。 config,我试图使用PHP mcrypt解密它。我尝试过无数次的方法,但这里是一个有希望的例子(失败)...

  define('ASP_DECRYPT_KEY' 0BC95D748C57F6162519C165E0C5DEB69EA1145676F453AB93DA9645B067DFB8'); //这是我的Machine.config文件中找到的一个解密密钥(请注意这是伪造的)
$ iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,MCRYPT_MODE_CBC),MCRYPT_RAND);
$ decryptpted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128,ASP_DECRYPT_KEY,$ authCookie,MCRYPT_MODE_CBC,$ iv); // $ authCookie是pack()'d cookie数据

但是失败。我已经尝试了IV的变化,所有的零都是@ 16个字节。我尝试了不同的Rijndael大小(128对256)。我已经尝试过base64_decode()ing,似乎没有任何工作。我发现这个 stackoverflow post here ,并开始使用关键/ iv是使用sha256制作的,但这不是真的有用。



有人会有线索我应该做什么?

解决方案

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



假设加密发生在AES CBC-IV模式下,随机生成IV,您需要首先找出IV的位置。



您显示的代码片段不能正常工作,因为你会生成一个随机的IV(这将是不正确的)。话虽如此,即使你的IV错误,在CBC模式下,你将只有前16个字节的解密密文乱码,其余的将正确解密 - 你可以使用这个作为一个测试来知道你是否正确地休息。在实践中,当使用随机IVs时,它很可能是密文之前的。为了检查这是否正确,可以尝试检查len(ciphertext)= len(plaintext)+ 16.这意味着最可能的前16个字节是你的IV(因此它应该在尝试前从密文中删除解密它)。



同样在你的代码片段中,似乎你使用的是ascii-string,而它应该是一个字节数组。尝试:

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

此外,这似乎是一个32字节的密钥,所以你需要使用AES-256。我不知道authcookie是如何看的,但是如果是base64编码,那么你还需要先解码它。



希望这有帮助!



注意:我不建议在重要的生产代码中执行此操作,因为如果您尝试实现即使是您自己的解密程序,也可能会出现许多问题。 。特别是,我猜想在尝试解密之前,你必须先检查一下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 WITH protect =验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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