Skip to content
Permalink
Browse files
Disabled packet encryption for client connection from leaked client s…
…ource code.
  • Loading branch information
geralex committed Oct 25, 2022
1 parent d57ea04 commit 74434521dee9ed9ebb37160f1ecf6ace6472c745
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
@@ -24,8 +24,10 @@ public static partial class Program
private static IPAddress gatewayip = IPAddress.Any;
private static int authenticationport = 64001;
private static IPAddress authenticationip = IPAddress.Loopback;
private static string guidkey = "A928CDC9DBE8751B3BC99EB65AE07E0C849CE739";
private static string crckey = "ED90AA25AE906FB36308C8523A4737A7E7B1FC6F";
//private static string guidkey = "A928CDC9DBE8751B3BC99EB65AE07E0C849CE739";
//private static string crckey = "ED90AA25AE906FB36308C8523A4737A7E7B1FC6F";
private static string guidkey = "0000000000000000000000000000000000000000";
private static string crckey = "0000000000000000000000000000000000000000";
private static EncryptedManager<GatewayClient> networkManger;
private static ConsoleReader reader;

@@ -1,4 +1,6 @@
using Saga.Gateway.Packets;
using Saga.Packets;
using Saga.Shared.NetworkCore;
using Saga.Shared.PacketLib;
using Saga.Shared.PacketLib.Gateway;
using System;
@@ -17,6 +19,10 @@ public class GatewayClient : Shared.NetworkCore.EncryptedClient
public uint session = 0;
public WorldClient world;

//develop
public bool onKick = false;
public bool onKickMap = false;

public GatewayClient(Socket socket)
: base(socket)
{
@@ -91,6 +97,10 @@ protected override void ProcessPacket(ref byte[] body)
case 0x0104: OnIdentify(); return;
case 0x0501: RedirectMap(body); return;
case 0x0301: RedirectLogin(body); return;

case 0x0502: LogOut(body); return;


default: Trace.TraceWarning("Unsupported packet found with id: {0:X4}", packetIdentifier); this.Close(); break;
}
}
@@ -104,15 +114,18 @@ private void OnHeader()
Trace.TraceInformation("Header Recieved from {0}", this.socket.RemoteEndPoint);
try
{
byte[] tempServerKey = Encryption.GenerateKey();
byte[] expandedServerKey = Encryption.GenerateDecExpKey(tempServerKey);
SMSG_IDENTIFY spkt2 = new SMSG_IDENTIFY();
this.Send((byte[])spkt2);
/*
//byte[] tempServerKey = Encryption.GenerateKey();
//byte[] expandedServerKey = Encryption.GenerateDecExpKey(tempServerKey);
SMSG_SENDKEY spkt = new SMSG_SENDKEY();
spkt.Key = expandedServerKey;
//spkt.Key = expandedServerKey;
spkt.Collumns = 4;
spkt.Rounds = 10;
spkt.Direction = 2;
this.Send((byte[])spkt);
this.serverKey = tempServerKey;
//this.serverKey = tempServerKey;*/
}
catch (Exception ex)
{
@@ -130,6 +143,9 @@ private void OnKey(CMSG_SENDKEY cpkt)
SMSG_GUID spkt = new SMSG_GUID();
spkt.Key = Program.CrcKey;
this.Send((byte[])spkt);

Trace.TraceInformation("Key Recieved {0}", Program.CrcKey);

}
catch (Exception ex)
{
@@ -155,6 +171,8 @@ private void OnGUID(CMSG_GUID cpkt)
{
SMSG_IDENTIFY spkt2 = new SMSG_IDENTIFY();
this.Send((byte[])spkt2);
Trace.TraceInformation("GUID Recieved {0}", key);

}
}
catch (Exception ex)
@@ -216,6 +234,7 @@ internal void SetSessionId(uint session)
Trace.TraceInformation("Set session-id {1} received from: {0}", this.socket.RemoteEndPoint, session);
if (session > 0)
{

//Update session, add session to lookup table
this.session = session;
GatewayPool.Instance.lookup.Add(session, this);
@@ -248,6 +267,7 @@ internal void SetSessionId(uint session)
}
catch (System.Net.Sockets.SocketException)
{

//Closing connection
this.Close();
}
@@ -260,10 +280,14 @@ private void RedirectLogin(byte[] body)
LoginClient client;
if (NetworkManager.TryGetLoginClient(out client))
{
//Console.WriteLine("!!!");

client.Send(body);
}
else
{
//Console.WriteLine("!!!!");

//Output a error
byte[] buffer2 = new byte[] { 0x0B, 0x00, 0x74, 0x17, 0x91, 0x00, 0x02, 0x07, 0x00, 0x00, 0x01 };
Array.Copy(BitConverter.GetBytes(session), 0, buffer2, 2, 4);
@@ -287,6 +311,7 @@ private void RedirectMap(byte[] body)
if (world != null)
{
world.Send(body);
//Console.WriteLine("!!!!!");
}
else
{
@@ -306,6 +331,22 @@ private void RedirectMap(byte[] body)
}
}


private void LogOut(byte[] body)
{
Console.WriteLine("!LogOut!");

if (world != null) world.Close();

//Forward to out client
ClientKick spkt2 = new ClientKick();
spkt2.SessionId = this.session;
this.Send((byte[])spkt2);
//GatewayPool.Instance.lookup.Remove(this.session);
//RedirectLogin(body);

}

#endregion Internal Methods
}
}
@@ -75,7 +75,7 @@ private void OnRead(IAsyncResult asyn)
{
WaitCallback callback = delegate(object state)
{
packet = Encryption.Decrypt(packet, 2, this.clientKey);
//packet = Encryption.Decrypt(packet, 2, this.clientKey);
ProcessPacket(ref packet);
};

@@ -130,7 +130,7 @@ public void Send(byte[] buffer)
{
try
{
buffer = Encryption.Encrypt(buffer, 2, this.serverKey);
//buffer = Encryption.Encrypt(buffer, 2, this.serverKey);
this.socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, null, null);
}
catch (ObjectDisposedException)
@@ -143,8 +143,8 @@ public void Send(ref byte[] buffer)
{
try
{
byte[] tmpbuffer = Encryption.Encrypt(buffer, 2, this.serverKey);
this.socket.BeginSend(tmpbuffer, 0, tmpbuffer.Length, SocketFlags.None, null, null);
//byte[] tmpbuffer = Encryption.Encrypt(buffer, 2, this.serverKey);
this.socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, null, null);
}
catch (ObjectDisposedException)
{
@@ -11,13 +11,17 @@ namespace Saga.Shared.PacketLib
/// </summary>
public class Encryption
{


//private static byte[] XorKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
private static byte[] XorKey = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x0F, 0x1E, 0x2D, 0x3C, 0x4B, 0x5A, 0x69, 0x78 };

/// <summary>
/// The static key is the key used to encrypt the first messages between client and server.
/// In these messages a key exchange will take place which will be used for further communication.
/// </summary>
public static byte[] StaticKey = { 0x40, 0x21, 0xBF, 0xE4, 0xB0, 0xC7, 0xB8, 0xF0, 0xB8, 0xA3, 0xB0, 0xDA, 0xC1, 0xF6, 0x24, 0x00 };
public static byte[] StaticKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
//public static byte[] StaticKey = { 0x40, 0x21, 0xBF, 0xE4, 0xB0, 0xC7, 0xB8, 0xF0, 0xB8, 0xA3, 0xB0, 0xDA, 0xC1, 0xF6, 0x24, 0x00 };

/// <summary>
/// Generate a random 16 bytes AES key.

0 comments on commit 7443452

Please sign in to comment.