-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCrypto.cs
187 lines (183 loc) · 7.2 KB
/
Crypto.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace SnifferGunbound
{
public class Crypto
{
private static Rijndael m_StaticRijndael;
//private static byte[] m_StaticKey = { 0xA9, 0x27, 0x53, 0x04, 0x1B, 0xFC, 0xAC, 0xE6, 0x5B, 0x23, 0x38, 0x34, 0x68, 0x46, 0x03, 0x8C };//static key broker
private static byte[] m_StaticKey = { 0xFF, 0xB3, 0xB3, 0xBE, 0xAE, 0x97, 0xAD, 0x83, 0xB9, 0x61, 0x0E, 0x23, 0xA4, 0x3C, 0x2E, 0xB0 };//static key gs
private Rijndael m_DynamicRijndael;
public static void Initialize()
{
Crypto.m_StaticRijndael = Rijndael.Create();
Crypto.m_StaticRijndael.Key = Crypto.m_StaticKey;
Crypto.m_StaticRijndael.Mode = CipherMode.ECB;
Crypto.m_StaticRijndael.Padding = PaddingMode.Zeros;
}
private static byte[] DecryptStatic(byte[] cipherData)
{
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, Crypto.m_StaticRijndael.CreateDecryptor(), CryptoStreamMode.Write);
cryptoStream.Write(cipherData, 0, cipherData.Length);
cryptoStream.Close();
return memoryStream.ToArray();
}
public static byte[] EncryptStatic(string strData)
{
byte[] cipherData = GetBytes(strData);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, Crypto.m_StaticRijndael.CreateEncryptor(), CryptoStreamMode.Write);
cryptoStream.Write(cipherData, 0, cipherData.Length);
cryptoStream.Close();
return memoryStream.ToArray();
}
public static byte[] EncryptStatic(byte[] cipherData)
{
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, Crypto.m_StaticRijndael.CreateEncryptor(), CryptoStreamMode.Write);
cryptoStream.Write(cipherData, 0, cipherData.Length);
cryptoStream.Close();
return memoryStream.ToArray();
}
public byte[] EncryptDynamic(byte[] cipherData)
{
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, this.m_DynamicRijndael.CreateEncryptor(), CryptoStreamMode.Write);
cryptoStream.Write(cipherData, 0, cipherData.Length);
cryptoStream.Close();
return memoryStream.ToArray();
}
public byte[] DecryptDynamic(byte[] cipherData)
{
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, this.m_DynamicRijndael.CreateDecryptor(), CryptoStreamMode.Write);
cryptoStream.Write(cipherData, 0, cipherData.Length);
cryptoStream.Close();
return memoryStream.ToArray();
}
public static byte[] DecryptStaticBuffer(byte[] decryptme)
{
byte[] result;
if (decryptme.Length != 16)
{
Debug.WriteLine("DecyryptStatic() is 128-bit only.");
result = null;
}
else
{
result = Crypto.DecryptStatic(decryptme);
}
return result;
}
public void Dispose()
{
this.m_DynamicRijndael.Clear();
this.m_DynamicRijndael = null;
}
public bool PacketDecrypt(byte[] input, ref byte[] output, ushort packetid)
{
bool result;
if (input.Length == 0)
{
Debug.WriteLine("Empty buffer passed for decryption");
result = false;
}
else
{
if (input.Length % 16 != 0)
{
Debug.WriteLine("Decrypt failed. Input byte count is not a multiple of 16.");
result = false;
}
else
{
int num = input.Length / 16;
int num2 = num * 12;
byte[] array = new byte[input.Length];
byte[] array2 = new byte[num2];
array = this.DecryptDynamic(input);
uint num3 = 2251382910u;
for (int i = 0; i < num; i++)
{
uint num4 = BitConverter.ToUInt32(array, 16 * i);
if (num4 - (uint)packetid != num3)
{
Debug.WriteLine($"Bad Packet Signature. G: {num4.ToString("x8")} E: {(num3 + (uint)packetid).ToString("x8")}");
result = false;
return result;
}
for (int j = 4; j < 16; j++)
{
array2[i * 12 + (j - 4)] = array[i * 16 + j];
}
}
output = array2;
result = true;
}
}
return result;
}
public Crypto(string login, string pass, uint dword)
{
if (login.Length <= 16 && pass.Length <= 20)
{
SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
SpecialSHA specialSHA = new SpecialSHA();
String text = String.Empty;
byte[] AuthDword = GetBytes(dword);
Array.Reverse(AuthDword);
List<byte> Temp = new List<byte>();
Temp.AddRange(Encoding.ASCII.GetBytes(login + pass));
Temp.AddRange(AuthDword);
byte[] Key = specialSHA.SHA1(Temp.ToArray());
this.m_DynamicRijndael = Rijndael.Create();
this.m_DynamicRijndael.Key = Key;
this.m_DynamicRijndael.Mode = CipherMode.ECB;
this.m_DynamicRijndael.Padding = PaddingMode.Zeros;
}
}
public static byte[] GetBytes(string s)
{
byte[] bytes = new byte[s.Length];
int index = 0;
for (int i = 0; i < s.Length; i++)
{
char c = s[i];
bytes[index++] = (byte)c;
}
return bytes;
}
public static byte[] GetBytes(ushort u)
{
byte[] bytes = new byte[2];
for (int c = 1; c <= 2; c++)
{
bytes[c - 1] = (byte)(u >> 16 - c * 8);
}
return bytes;
}
public static byte[] GetBytes(long s)
{
byte[] bytes = new byte[8];
for (int c = 1; c <= 8; c++)
{
bytes[c - 1] = (byte)((ulong)s >> 64 - c * 8);
}
return bytes;
}
public static byte[] GetBytes(uint t)
{
byte[] bytes = new byte[4];
for (int c = 1; c <= 4; c++)
{
bytes[c - 1] = (byte)(t >> 32 - c * 8);
}
return bytes;
}
}
}