public static RealmPacket CreateAuthResponse(String name, String password) { SHA1 sha = new SHA1CryptoServiceProvider(); byte[] user_pass = System.Text.Encoding.UTF8.GetBytes(((name + ":" + password).ToCharArray())); byte[] hash = sha.ComputeHash(user_pass); byte[] salt = new byte[32]; new Random().NextBytes(salt); byte[] result = new byte[hash.Length + salt.Length]; hash.CopyTo(result, 0); salt.CopyTo(result, hash.Length); byte[] finalhash = sha.ComputeHash(result); byte[] rand = new byte[20]; new Random().NextBytes(rand); //BigInteger int_a = new BigInteger(reverse(finalhash)); //BigInteger int_b = new BigInteger(reverse(N)); BigInteger int_c = new BigInteger(new Byte[] { 7 }); BigInteger int_d = int_c.modPow(new BigInteger(reverse(finalhash)), new BigInteger(reverse(N))); BigInteger K = new BigInteger(new Byte[] { 3 }); BigInteger temp = ((K * int_d) + int_c.modPow(new BigInteger(reverse(rand)), new BigInteger(reverse(N)))) % new BigInteger(reverse(N)); RealmPacket response = new RealmPacket(); response.opcode = RealmOpcode.RS_AUTH_LOGON_CHALLENGE; response.Data.Add(RealmData.RD_AUTH_ERROR, 0); response.Data.Add(RealmData.RD_AUTH_HASH, temp.getBytes()); response.Data.Add(RealmData.RD_AUTH_SALT, salt); response.Data.Add(RealmData.RD_AUTH_N, N); return(response); }
public static RealmPacket FromStream(Stream stream) { RealmPacket p = new RealmPacket(); BinaryReader reader = new BinaryReader(stream); p.opcode = (RealmOpcode)(reader.ReadByte()); reader.ReadByte(); int packetSize = reader.ReadUInt16(); switch (p.opcode) { case RealmOpcode.RS_AUTH_RECON_CHALLENGE: case RealmOpcode.RS_AUTH_LOGON_CHALLENGE: reader.ReadBytes(4); p.Data.Add(RealmData.RD_CLIENT_VERSION, reader.ReadByte() + "." + reader.ReadByte() + "." + reader.ReadByte()); p.Data.Add(RealmData.RD_CLIENT_BUILD, reader.ReadUInt16()); reader.ReadBytes(16); p.Data.Add(RealmData.RD_CLIENT_IP, new IPAddress(reader.ReadBytes(4))); p.Data.Add(RealmData.RD_ACCOUNT_NAME, reader.ReadString()); break; case RealmOpcode.RS_AUTH_RECON_PROOF: case RealmOpcode.RS_AUTH_LOGON_PROOF: p.Data.Add(RealmData.RD_SRP6_A, reader.ReadBytes(32)); p.Data.Add(RealmData.RD_SRP6_M1, reader.ReadBytes(20)); p.Data.Add(RealmData.RD_SRP6_CRC, reader.ReadBytes(20)); p.Data.Add(RealmData.RD_SRP6_KEYNUM, reader.ReadByte()); break; default: throw new InvalidDataException(); } return(p); }
private void _read_packets_loop() { _is_running = true; _client.Client.Blocking = true; _client.Client.ReceiveTimeout = -1; while (_is_running) { Thread.Sleep(10); if ((_client == null) || !_client.Connected) { _is_running = false; } byte[] buffer = new byte[4]; try { _client.Client.Receive(buffer); int size = (int)BitConverter.ToUInt16(buffer, 2); if (size == 0) { continue; } Array.Resize <byte>(ref buffer, buffer.Length + size); _client.Client.Receive(buffer, 4, size, SocketFlags.None); } catch // Disconnected { break; } RealmPacket packet = RealmPacket.FromByteArray(buffer); switch (packet.opcode) { #region AUTH Packet case RealmOpcode.RS_AUTH_RECON_CHALLENGE: case RealmOpcode.RS_AUTH_LOGON_CHALLENGE: { RealmPacket response = new RealmPacket(); byte[] bytestosend; SHA1 sha = new SHA1CryptoServiceProvider(); byte[] user_pass = System.Text.Encoding.UTF8.GetBytes((("WoWMS:" + _password).ToCharArray())); byte[] hash = sha.ComputeHash(user_pass); byte[] salt = new byte[32]; new Random().NextBytes(salt); byte[] result = new byte[hash.Length + salt.Length]; hash.CopyTo(result, 0); salt.CopyTo(result, hash.Length); byte[] finalhash = sha.ComputeHash(result); byte[] rand = new byte[20]; new Random().NextBytes(rand); bR = (byte[])rand.Clone(); //BigInteger int_a = new BigInteger(reverse(finalhash)); //BigInteger int_b = new BigInteger(reverse(N)); BigInteger int_c = new BigInteger(new Byte[] { 7 }); BigInteger int_d = int_c.modPow(new BigInteger(reverse(finalhash)), new BigInteger(reverse(N))); BigInteger K = new BigInteger(new Byte[] { 3 }); BigInteger temp = ((K * int_d) + int_c.modPow(new BigInteger(reverse(rand)), new BigInteger(reverse(N)))) % new BigInteger(reverse(N)); this.bB = temp.getBytes(); response = new RealmPacket(); response.opcode = RealmOpcode.RS_AUTH_LOGON_CHALLENGE; response.Data.Add(RealmData.RD_AUTH_ERROR, 0); response.Data.Add(RealmData.RD_AUTH_HASH, temp.getBytes()); response.Data.Add(RealmData.RD_AUTH_SALT, salt); response.Data.Add(RealmData.RD_AUTH_N, N); //RealmPacket p = RealmPacket.CreateAuthResponse((string)packet.Data[RealmData.RD_ACCOUNT_NAME], _password); bytestosend = response.ToByteArray(); _client.Client.Send(bytestosend); break; } #endregion #region PROOF Packet case RealmOpcode.RS_AUTH_RECON_PROOF: case RealmOpcode.RS_AUTH_LOGON_PROOF: { RealmPacket response = new RealmPacket(); byte[] bytestosend; SHA1 sha = new SHA1CryptoServiceProvider(); response = new RealmPacket(); response.opcode = RealmOpcode.RS_AUTH_LOGON_PROOF; byte[] b = new byte[32 + bB.Length + 1 + 16 + 16]; BinaryWriter writer = new BinaryWriter(new MemoryStream(b)); //((byte[])packet.Data[RealmData.RD_SRP6_M1]).CopyTo(b, 0); writer.Write((byte[])packet.Data[RealmData.RD_SRP6_M1]); //bB.CopyTo(b, 32); writer.Write(bB); BigInteger u = new BigInteger(sha.ComputeHash(b)); BigInteger s = ((BigInteger)(new BigInteger((byte[])(packet.Data[RealmData.RD_SRP6_M1])) * (new BigInteger(bV).modPow(u, new BigInteger(N))))).modPow(new BigInteger(bR), new BigInteger(N)); byte[] t = s.getBytes(); byte[] t1 = new byte[16]; for (int i = 0; i < 16; i++) { t1[i] = t[i * 2]; } writer.Write(t1); byte[] hash = sha.ComputeHash(b); byte[] vK = new byte[40]; for (int i = 0; i < 20; i++) { vK[2 * i] = sha.ComputeHash(b)[i]; } for (int i = 0; i < 16; i++) { t1[i] = t[i * 2 + 1]; } writer.Write(t1); for (int i = 0; i < 20; i++) { vK[2 * i + 1] = sha.ComputeHash(b)[i]; } bytestosend = response.ToByteArray(); _client.Client.Send(bytestosend); break; } #endregion default: break; } } }
public static RealmPacket FromByteArray(byte[] array) { return(RealmPacket.FromStream(new MemoryStream(array))); }
public static RealmPacket CreateAuthResponse(String name, String password) { SHA1 sha = new SHA1CryptoServiceProvider(); byte[] user_pass = System.Text.Encoding.UTF8.GetBytes(((name + ":" + password).ToCharArray())); byte[] hash = sha.ComputeHash(user_pass); byte[] salt = new byte[32]; new Random().NextBytes(salt); byte[] result = new byte[hash.Length + salt.Length]; hash.CopyTo(result, 0); salt.CopyTo(result, hash.Length); byte[] finalhash = sha.ComputeHash(result); byte[] rand = new byte[20]; new Random().NextBytes(rand); //BigInteger int_a = new BigInteger(reverse(finalhash)); //BigInteger int_b = new BigInteger(reverse(N)); BigInteger int_c = new BigInteger(new Byte[] { 7 }); BigInteger int_d = int_c.modPow(new BigInteger(reverse(finalhash)),new BigInteger(reverse(N))); BigInteger K = new BigInteger(new Byte[] { 3 }); BigInteger temp = ((K * int_d) + int_c.modPow(new BigInteger(reverse(rand)), new BigInteger(reverse(N)))) % new BigInteger(reverse(N)); RealmPacket response = new RealmPacket(); response.opcode = RealmOpcode.RS_AUTH_LOGON_CHALLENGE; response.Data.Add(RealmData.RD_AUTH_ERROR, 0); response.Data.Add(RealmData.RD_AUTH_HASH, temp.getBytes()); response.Data.Add(RealmData.RD_AUTH_SALT, salt); response.Data.Add(RealmData.RD_AUTH_N, N); return response; }
private void _read_packets_loop() { _is_running = true; _client.Client.Blocking = true; _client.Client.ReceiveTimeout = -1; while (_is_running) { Thread.Sleep(10); if ((_client == null) || !_client.Connected) _is_running = false; byte[] buffer = new byte[4]; try { _client.Client.Receive(buffer); int size = (int)BitConverter.ToUInt16(buffer, 2); if (size == 0) continue; Array.Resize<byte>(ref buffer, buffer.Length + size); _client.Client.Receive(buffer,4,size,SocketFlags.None); } catch // Disconnected { break; } RealmPacket packet = RealmPacket.FromByteArray(buffer); switch (packet.opcode) { #region AUTH Packet case RealmOpcode.RS_AUTH_RECON_CHALLENGE: case RealmOpcode.RS_AUTH_LOGON_CHALLENGE: { RealmPacket response = new RealmPacket(); byte[] bytestosend; SHA1 sha = new SHA1CryptoServiceProvider(); byte[] user_pass = System.Text.Encoding.UTF8.GetBytes((("WoWMS:" + _password).ToCharArray())); byte[] hash = sha.ComputeHash(user_pass); byte[] salt = new byte[32]; new Random().NextBytes(salt); byte[] result = new byte[hash.Length + salt.Length]; hash.CopyTo(result, 0); salt.CopyTo(result, hash.Length); byte[] finalhash = sha.ComputeHash(result); byte[] rand = new byte[20]; new Random().NextBytes(rand); bR = (byte[])rand.Clone(); //BigInteger int_a = new BigInteger(reverse(finalhash)); //BigInteger int_b = new BigInteger(reverse(N)); BigInteger int_c = new BigInteger(new Byte[] { 7 }); BigInteger int_d = int_c.modPow(new BigInteger(reverse(finalhash)), new BigInteger(reverse(N))); BigInteger K = new BigInteger(new Byte[] { 3 }); BigInteger temp = ((K * int_d) + int_c.modPow(new BigInteger(reverse(rand)), new BigInteger(reverse(N)))) % new BigInteger(reverse(N)); this.bB = temp.getBytes(); response = new RealmPacket(); response.opcode = RealmOpcode.RS_AUTH_LOGON_CHALLENGE; response.Data.Add(RealmData.RD_AUTH_ERROR, 0); response.Data.Add(RealmData.RD_AUTH_HASH, temp.getBytes()); response.Data.Add(RealmData.RD_AUTH_SALT, salt); response.Data.Add(RealmData.RD_AUTH_N, N); //RealmPacket p = RealmPacket.CreateAuthResponse((string)packet.Data[RealmData.RD_ACCOUNT_NAME], _password); bytestosend = response.ToByteArray(); _client.Client.Send(bytestosend); break; } #endregion #region PROOF Packet case RealmOpcode.RS_AUTH_RECON_PROOF: case RealmOpcode.RS_AUTH_LOGON_PROOF: { RealmPacket response = new RealmPacket(); byte[] bytestosend; SHA1 sha = new SHA1CryptoServiceProvider(); response = new RealmPacket(); response.opcode = RealmOpcode.RS_AUTH_LOGON_PROOF; byte[] b = new byte[32 + bB.Length + 1 + 16 + 16]; BinaryWriter writer = new BinaryWriter(new MemoryStream(b)); //((byte[])packet.Data[RealmData.RD_SRP6_M1]).CopyTo(b, 0); writer.Write((byte[])packet.Data[RealmData.RD_SRP6_M1]); //bB.CopyTo(b, 32); writer.Write(bB); BigInteger u = new BigInteger(sha.ComputeHash(b)); BigInteger s = ((BigInteger)(new BigInteger((byte[])(packet.Data[RealmData.RD_SRP6_M1])) * (new BigInteger(bV).modPow(u, new BigInteger(N))))).modPow(new BigInteger(bR), new BigInteger(N)); byte[] t = s.getBytes(); byte[] t1 = new byte[16]; for (int i = 0; i < 16; i++) t1[i] = t[i * 2]; writer.Write(t1); byte[] hash = sha.ComputeHash(b); byte[] vK = new byte[40]; for (int i = 0; i < 20; i++) { vK[2 * i] = sha.ComputeHash(b)[i]; } for (int i = 0; i < 16; i++) t1[i] = t[i * 2 + 1]; writer.Write(t1); for (int i = 0; i < 20; i++) { vK[2 * i + 1] = sha.ComputeHash(b)[i]; } bytestosend = response.ToByteArray(); _client.Client.Send(bytestosend); break; } #endregion default: break; } } }
public static RealmPacket FromStream(Stream stream) { RealmPacket p = new RealmPacket(); BinaryReader reader = new BinaryReader(stream); p.opcode = (RealmOpcode)(reader.ReadByte()); reader.ReadByte(); int packetSize = reader.ReadUInt16(); switch (p.opcode) { case RealmOpcode.RS_AUTH_RECON_CHALLENGE: case RealmOpcode.RS_AUTH_LOGON_CHALLENGE: reader.ReadBytes(4); p.Data.Add(RealmData.RD_CLIENT_VERSION, reader.ReadByte() + "." + reader.ReadByte() + "." + reader.ReadByte()); p.Data.Add(RealmData.RD_CLIENT_BUILD, reader.ReadUInt16()); reader.ReadBytes(16); p.Data.Add(RealmData.RD_CLIENT_IP, new IPAddress(reader.ReadBytes(4))); p.Data.Add(RealmData.RD_ACCOUNT_NAME, reader.ReadString()); break; case RealmOpcode.RS_AUTH_RECON_PROOF: case RealmOpcode.RS_AUTH_LOGON_PROOF: p.Data.Add(RealmData.RD_SRP6_A, reader.ReadBytes(32)); p.Data.Add(RealmData.RD_SRP6_M1, reader.ReadBytes(20)); p.Data.Add(RealmData.RD_SRP6_CRC, reader.ReadBytes(20)); p.Data.Add(RealmData.RD_SRP6_KEYNUM, reader.ReadByte()); break; default: throw new InvalidDataException(); } return p; }