Skip to content

Commit

Permalink
Update steamkit, force websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Sep 4, 2024
1 parent c491265 commit 0c865e2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
72 changes: 72 additions & 0 deletions CryptoHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.IO;
using System.Security.Cryptography;

namespace SteamTokenDumper;
internal static class CryptoHelper
{
/// <summary>
/// Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a random IV prepended using AES/ECB/None
/// </summary>
public static byte[] SymmetricEncryptWithIV(byte[] input, byte[] key, byte[] iv)
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(key);
ArgumentNullException.ThrowIfNull(iv);

using var aes = Aes.Create();
aes.BlockSize = 128;
aes.KeySize = 256;

byte[] cryptedIv;

// encrypt iv using ECB and provided key
#pragma warning disable CA5358 // Review cipher mode usage with cryptography experts
aes.Mode = CipherMode.ECB;
#pragma warning restore CA5358 // Review cipher mode usage with cryptography experts
aes.Padding = PaddingMode.None;

#pragma warning disable CA5401 // Do not use CreateEncryptor with non-default IV
using (var aesTransform = aes.CreateEncryptor(key, null))
{
cryptedIv = aesTransform.TransformFinalBlock(iv, 0, iv.Length);
}
#pragma warning restore CA5401 // Do not use CreateEncryptor with non-default IV

// encrypt input plaintext with CBC using the generated (plaintext) IV and the provided key
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;

#pragma warning disable CA5401 // Do not use CreateEncryptor with non-default IV
using (var aesTransform = aes.CreateEncryptor(key, iv))
using (var ms = new MemoryStream())
using (var cs = new CryptoStream(ms, aesTransform, CryptoStreamMode.Write))
{
cs.Write(input, 0, input.Length);
cs.FlushFinalBlock();

var cipherText = ms.ToArray();

// final output is 16 byte ecb crypted IV + cbc crypted plaintext
var output = new byte[cryptedIv.Length + cipherText.Length];

Array.Copy(cryptedIv, 0, output, 0, cryptedIv.Length);
Array.Copy(cipherText, 0, output, cryptedIv.Length, cipherText.Length);

return output;
}
#pragma warning restore CA5401 // Do not use CreateEncryptor with non-default IV
}

/// <summary>
/// Performs an encryption using AES/CBC/PKCS7 with an input byte array and key, with a random IV prepended using AES/ECB/None
/// </summary>
public static byte[] SymmetricEncrypt(byte[] input, byte[] key)
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(key);

var iv = RandomNumberGenerator.GetBytes(16);
return SymmetricEncryptWithIV(input, key, iv);
}
}
8 changes: 6 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static async Task ReadCredentials()
}

var encryptedBytes = await File.ReadAllBytesAsync(RememberCredentialsFile);
var decryptedData = CryptoHelper.SymmetricDecrypt(encryptedBytes, EncryptionKey);
var decryptedData = SteamKit2.CryptoHelper.SymmetricDecrypt(encryptedBytes, EncryptionKey);

savedCredentials = JsonSerializer.Deserialize(decryptedData, SavedCredentialsJsonContext.Default.SavedCredentials);

Expand Down Expand Up @@ -328,7 +328,11 @@ private static void InitializeSteamKit()
DebugLog.AddListener(new SteamKitLogger());
DebugLog.Enabled = Configuration.Debug;

steamClient = new SteamClient("Dumper");
var config = SteamConfiguration.Create(b => b
.WithProtocolTypes(ProtocolTypes.WebSocket)
);

steamClient = new SteamClient(config, "Dumper");
manager = new CallbackManager(steamClient);

steamUser = steamClient.GetHandler<SteamUser>();
Expand Down
4 changes: 2 additions & 2 deletions SteamTokenDumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.0.0" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.0.2" />
<PackageReference Include="QRCoder" Version="1.6.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="SteamKit2" Version="3.0.0-Alpha.1" />
<PackageReference Include="SteamKit2" Version="3.0.0-Beta.2" />
<PackageReference Include="ValveKeyValue" Version="0.11.0.378" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 0c865e2

Please sign in to comment.