Skip to content

Instantly share code, notes, and snippets.

@GMMan
Created March 28, 2024 04:01
Show Gist options
  • Save GMMan/2a96925005ee8ed1aa2ce55f3461e42b to your computer and use it in GitHub Desktop.
Save GMMan/2a96925005ee8ed1aa2ce55f3461e42b to your computer and use it in GitHub Desktop.
Steam CD-key cache decryption
byte[] key = { 0xd6, 0x22, 0x4d, 0x40, 0x36, 0xef, 0x80, 0x0b, 0x9c, 0x10, 0x7f, 0x02, 0x64, 0x13, 0x8c, 0xf5, 0x08, 0xd3, 0x32, 0x70, 0x33, 0xd3, 0x65, 0xe7, 0xbb, 0x84, 0x09, 0x6c, 0x14, 0xe5, 0xa4, 0x00 };
string encryptedTicket = "cdk_* from localconfig.vdf";
byte[] encryptedTicketBytes = Convert.FromHexString(encryptedTicket);
using Aes aes = Aes.Create();
aes.Key = key;
// Decrypt IV
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.None;
using (var decryptor = aes.CreateDecryptor())
{
var encryptedIv = encryptedTicketBytes.AsSpan().Slice(0, 16).ToArray();
var decryptedIv = decryptor.TransformFinalBlock(encryptedIv, 0, encryptedIv.Length);
aes.IV = decryptedIv;
}
// Decrypt data
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
byte[] decryptedData;
using (var inMs = new MemoryStream(encryptedTicketBytes.AsSpan().Slice(16).ToArray()))
using (var cryptStream = new CryptoStream(inMs, aes.CreateDecryptor(), CryptoStreamMode.Read))
using (var outMs = new MemoryStream())
{
cryptStream.CopyTo(outMs);
decryptedData = outMs.ToArray();
}
// Extract CD-key, starting at offset 4, maximum 512 bytes
StringBuilder sb = new();
for (int i = 4; i < decryptedData.Length; ++i)
{
if (decryptedData[i] != 0)
sb.Append((char)decryptedData[i]);
else
break;
}
Console.WriteLine(sb.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment