Decrypting the .ASPXAUTH Cookie WITH protection=validation

后端 未结 3 2012
梦谈多话
梦谈多话 2021-01-04 09:19

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

相关标签:
3条回答
  • 2021-01-04 09:49

    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.

    0 讨论(0)
  • 2021-01-04 09:52

    I know what a pain is to decrypt in PHP something encrypted in .NET and vice versa.

    I had to end up coding myself the Rijndael algorithm ( translated it from another language ).

    Here is the link to the source code of the algorithm: http://pastebin.com/EnCJBLSY

    At the end of the source code there is some usage example.

    But on .NET, you should use zero padding when encrypting. Also test it with ECB mode, I'm not sure if CBC works.

    Good luck and hope it helps

    edit: the algorithm returns the hexadecimal string when encrypts, and also expects hexadecimal string when decrypting.

    0 讨论(0)
  • 2021-01-04 09:55

    I understand this may not have been possible for the OP but for other people heading down this route here is a simple alternative.

    1. Create a .net web service with a method like:

      public FormsAuthenticationTicket DecryptFormsAuthCookie(string ticket)
      {
      return FormsAuthentication.Decrypt(ticket);
      }

    2. Pass cookie to web service from PHP:

      $authCookie = $_COOKIE['.ASPXAUTH'];
      $soapClient = new SoapClient("http://localhost/Service1.svc?wsdl");
      $params= array(
      "ticket" => $authCookie
      );
      $result = $soapClient->DecryptFormsAuthCookie($params);

    0 讨论(0)
提交回复
热议问题