Misc corrections

This commit is contained in:
JustArchi
2019-07-20 00:28:35 +02:00
parent 535ce04a47
commit 82c90498a6
2 changed files with 50 additions and 41 deletions

View File

@@ -31,14 +31,14 @@ namespace ArchiSteamFarm {
public static class ArchiCryptoHelper {
private static byte[] EncryptionKey = Encoding.UTF8.GetBytes(nameof(ArchiSteamFarm));
internal static string BruteforceSteamParentalCode(byte[] passwordHash, byte[] salt, bool derivedKey = true) {
internal static string BruteforceSteamParentalCode(byte[] passwordHash, byte[] salt, bool scrypt = true) {
if ((passwordHash == null) || (salt == null)) {
ASF.ArchiLogger.LogNullError(nameof(passwordHash) + " || " + nameof(salt));
return null;
}
return derivedKey ? BruteforceSteamParentalCodeDerived(passwordHash, salt) : BruteforceSteamParentalCodePbkdf2(passwordHash, salt);
return scrypt ? BruteforceSteamParentalCodeScrypt(passwordHash, salt) : BruteforceSteamParentalCodePbkdf2(passwordHash, salt);
}
internal static string Decrypt(ECryptoMethod cryptoMethod, string encrypted) {
@@ -93,40 +93,6 @@ namespace ArchiSteamFarm {
EncryptionKey = Encoding.UTF8.GetBytes(key);
}
private static string BruteforceSteamParentalCodeDerived(byte[] passwordHash, byte[] salt) {
if ((passwordHash == null) || (salt == null)) {
ASF.ArchiLogger.LogNullError(nameof(passwordHash) + " || " + nameof(salt));
return null;
}
byte[] password = new byte[4];
for (char a = '0'; a <= '9'; a++) {
password[0] = (byte) a;
for (char b = '0'; b <= '9'; b++) {
password[1] = (byte) b;
for (char c = '0'; c <= '9'; c++) {
password[2] = (byte) c;
for (char d = '0'; d <= '9'; d++) {
password[3] = (byte) d;
byte[] passwordHashTry = SCrypt.ComputeDerivedKey(password, salt, 8192, 8, 1, null, passwordHash.Length);
if (passwordHashTry.SequenceEqual(passwordHash)) {
return Encoding.UTF8.GetString(password);
}
}
}
}
}
return null;
}
private static string BruteforceSteamParentalCodePbkdf2(byte[] passwordHash, byte[] salt) {
if ((passwordHash == null) || (salt == null)) {
ASF.ArchiLogger.LogNullError(nameof(passwordHash) + " || " + nameof(salt));
@@ -163,6 +129,40 @@ namespace ArchiSteamFarm {
return null;
}
private static string BruteforceSteamParentalCodeScrypt(byte[] passwordHash, byte[] salt) {
if ((passwordHash == null) || (salt == null)) {
ASF.ArchiLogger.LogNullError(nameof(passwordHash) + " || " + nameof(salt));
return null;
}
byte[] password = new byte[4];
for (char a = '0'; a <= '9'; a++) {
password[0] = (byte) a;
for (char b = '0'; b <= '9'; b++) {
password[1] = (byte) b;
for (char c = '0'; c <= '9'; c++) {
password[2] = (byte) c;
for (char d = '0'; d <= '9'; d++) {
password[3] = (byte) d;
byte[] passwordHashTry = SCrypt.ComputeDerivedKey(password, salt, 8192, 8, 1, null, passwordHash.Length);
if (passwordHashTry.SequenceEqual(passwordHash)) {
return Encoding.UTF8.GetString(password);
}
}
}
}
}
return null;
}
private static string DecryptAES(string encrypted) {
if (string.IsNullOrEmpty(encrypted)) {
ASF.ArchiLogger.LogNullError(nameof(encrypted));

View File

@@ -25,6 +25,7 @@ using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Threading.Tasks;
using ArchiSteamFarm.CMsgs;
using ArchiSteamFarm.Localization;
@@ -665,15 +666,15 @@ namespace ArchiSteamFarm {
return (false, null);
}
bool derivedKey;
bool scrypt;
switch (body.settings.passwordhashtype) {
case 4:
derivedKey = false;
scrypt = false;
break;
case 6:
derivedKey = true;
scrypt = true;
break;
default:
@@ -695,7 +696,15 @@ namespace ArchiSteamFarm {
}
if (i >= steamParentalCode.Length) {
byte[] passwordHash = derivedKey ? SCrypt.ComputeDerivedKey(password, body.settings.salt, 8192, 8, 1, null, body.settings.passwordhash.Length) : SCrypt.GetEffectivePbkdf2Salt(password, body.settings.salt, 8192, 8, 1, null);
byte[] passwordHash;
if (scrypt) {
passwordHash = SCrypt.ComputeDerivedKey(password, body.settings.salt, 8192, 8, 1, null, body.settings.passwordhash.Length);
} else {
using (KeyedHashAlgorithm hmacAlgorithm = KeyedHashAlgorithm.Create()) {
passwordHash = Pbkdf2.ComputeDerivedKey(hmacAlgorithm, body.settings.salt, 10000, body.settings.passwordhash.Length);
}
}
if (passwordHash.SequenceEqual(body.settings.passwordhash)) {
return (true, steamParentalCode);
@@ -705,7 +714,7 @@ namespace ArchiSteamFarm {
ArchiLogger.LogGenericInfo(Strings.PleaseWait);
steamParentalCode = ArchiCryptoHelper.BruteforceSteamParentalCode(body.settings.passwordhash, body.settings.salt, derivedKey);
steamParentalCode = ArchiCryptoHelper.BruteforceSteamParentalCode(body.settings.passwordhash, body.settings.salt, scrypt);
ArchiLogger.LogGenericInfo(Strings.Done);