Any1 out there have or know of a proxy i could use?
using System;
using System.Threading;
namespace COProxy
{
/// <summary>
/// Summary description for Cryptographer.
/// </summary>
public class Cryptographer : object
{
public ushort m_InCounter = 0;
public ushort m_OutCounter = 0;
bool m_UseAlt = false;
private byte[] m_Key1 = {
0x9D, 0x90, 0x83, 0x8A, 0xD1, 0x8C, 0xE7, 0xF6, 0x25, 0x28, 0xEB, 0x82, 0x99, 0x64, 0x8F, 0x2E,
0x2D, 0x40, 0xD3, 0xFA, 0xE1, 0xBC, 0xB7, 0xE6, 0xB5, 0xD8, 0x3B, 0xF2, 0xA9, 0x94, 0x5F, 0x1E,
0xBD, 0xF0, 0x23, 0x6A, 0xF1, 0xEC, 0x87, 0xD6, 0x45, 0x88, 0x8B, 0x62, 0xB9, 0xC4, 0x2F, 0x0E,
0x4D, 0xA0, 0x73, 0xDA, 0x01, 0x1C, 0x57, 0xC6, 0xD5, 0x38, 0xDB, 0xD2, 0xC9, 0xF4, 0xFF, 0xFE,
0xDD, 0x50, 0xC3, 0x4A, 0x11, 0x4C, 0x27, 0xB6, 0x65, 0xE8, 0x2B, 0x42, 0xD9, 0x24, 0xCF, 0xEE,
0x6D, 0x00, 0x13, 0xBA, 0x21, 0x7C, 0xF7, 0xA6, 0xF5, 0x98, 0x7B, 0xB2, 0xE9, 0x54, 0x9F, 0xDE,
0xFD, 0xB0, 0x63, 0x2A, 0x31, 0xAC, 0xC7, 0x96, 0x85, 0x48, 0xCB, 0x22, 0xF9, 0x84, 0x6F, 0xCE,
0x8D, 0x60, 0xB3, 0x9A, 0x41, 0xDC, 0x97, 0x86, 0x15, 0xF8, 0x1B, 0x92, 0x09, 0xB4, 0x3F, 0xBE,
0x1D, 0x10, 0x03, 0x0A, 0x51, 0x0C, 0x67, 0x76, 0xA5, 0xA8, 0x6B, 0x02, 0x19, 0xE4, 0x0F, 0xAE,
0xAD, 0xC0, 0x53, 0x7A, 0x61, 0x3C, 0x37, 0x66, 0x35, 0x58, 0xBB, 0x72, 0x29,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,
0x92, 0xFF, 0x98, 0x45, 0x0E, 0x9B, 0xB4, 0xC1, 0x4A, 0x77, 0x90, 0x7D, 0x46, 0x93, 0x2C, 0x79,
0x02, 0xEF, 0x88, 0xB5, 0x7E, 0x8B, 0xA4, 0x31, 0xBA, 0x67, 0x80, 0xED, 0xB6, 0x83, 0x1C, 0xE9,
0x72, 0xDF, 0x78, 0x25, 0xEE, 0x7B, 0x94, 0xA1, 0x2A, 0x57, 0x70, 0x5D, 0x26, 0x73, 0x0C, 0x59,
0xE2, 0xCF, 0x68, 0x95, 0x5E, 0x6B, 0x84, 0x11, 0x9A, 0x47, 0x60, 0xCD, 0x96, 0x63, 0xFC, 0xC9,
0x52, 0xBF, 0x58, 0x05, 0xCE, 0x5B, 0x74, 0x81, 0x0A, 0x37, 0x50, 0x3D, 0x06, 0x53, 0xEC, 0x39,
0xC2, 0xAF, 0x48, 0x75, 0x3E, 0x4B, 0x64, 0xF1, 0x7A, 0x27, 0x40, 0xAD, 0x76, 0x43, 0xDC, 0xA9,
0x32, 0x9F, 0x38, 0xE5, 0xAE, 0x3B, 0x54, 0x61, 0xEA, 0x17, 0x30, 0x1D, 0xE6, 0x33, 0xCC, 0x19,
0xA2, 0x8F, 0x28, 0x55, 0x1E, 0x2B, 0x44, 0xD1, 0x5A, 0x07, 0x20, 0x8D, 0x56, 0x23, 0xBC, 0x89,
0x12, 0x7F, 0x18, 0xC5, 0x8E, 0x1B, 0x34, 0x41, 0xCA, 0xF7, 0x10, 0xFD, 0xC6, 0x13, 0xAC, 0xF9,
0x82, 0x6F, 0x08, 0x35, 0xFE, 0x0B, 0x24, 0xB1, 0x3A, 0xE7, 0x00, 0x6D, 0x36, 0x03, 0x9C, 0x69,
0xF2, 0x5F, 0xF8, 0xA5, 0x6E, 0xFB, 0x14, 0x21, 0xAA, 0xD7, 0xF0, 0xDD, 0xA6, 0xF3, 0x8C, 0xD9};
private byte[] m_Key3;
private byte[] m_Key4;
public Cryptographer()
{
}
public void SetKeys(byte[] InKey1, byte[] InKey2)
{
byte[] addKey1 = new byte[4];
byte[] addKey2 = new byte[4];
byte[] addResult = new byte[4];
//addKey1.i = 0;
//addKey2.i = 0;
byte[] tempKey = new byte[4];
long LMULer;
// InKey1[0] = 0x20;
// InKey1[1] = 0x5c;
// InKey1[2] = 0x48;
// InKey1[3] = 0xf4;
// InKey2[0] = 0x00;
// InKey2[1] = 0x44;
// InKey2[2] = 0xa6;
// InKey2[3] = 0x2e;
//if (Key3) delete [] Key3;
//if (Key4) delete [] Key4;
Monitor.Enter(this);
m_Key3 = new Byte[256];
m_Key4 = new Byte[256];
for (int x = 0; x < 4; x++)
{
addKey1[x] = InKey1[3 - x];
addKey2[x] = InKey2[3 - x];
}
//cout << "Key1: " << addKey1.i << endl;
//cout << "Key2: " << addKey2.i << endl;
uint Adder1;
uint Adder2;
uint Adder3;
Adder1 = (uint)((addKey1[3] << 24) | (addKey1[2] << 16) | (addKey1[1] << 8) | (addKey1[0]));
Adder2 = (uint)((addKey2[3] << 24) | (addKey2[2] << 16) | (addKey2[1] << 8) | (addKey2[0]));
Adder3 = Adder1 + Adder2;
addResult[0] = (byte)(Adder3 & 0xff);
addResult[1] = (byte)((Adder3 >> 8) & 0xff);
addResult[2] = (byte)((Adder3 >> 16) & 0xff);
addResult[3] = (byte)((Adder3 >> 24) & 0xff);
for (int b = 3; b >= 0; b--)
{
// printf("%.2x ", addResult.c[b]);
tempKey[3 - b] = addResult[b];
}
tempKey[2] = (byte)(tempKey[2] ^ (byte)0x43);
tempKey[3] = (byte)(tempKey[3] ^ (byte)0x21);
for (int b = 0; b < 4; b++)
{
tempKey[b] = (byte)(tempKey[b] ^ InKey1[b]);
}
//Build the 3rd Key
for (int b = 0; b < 256; b++)
{
m_Key3[b] = (byte)(tempKey[3 - (b % 4)] ^ m_Key1[b]);
}
for (int x = 0; x < 4; x++)
{
addResult[x] = tempKey[3 - x];
}
Adder3 = (uint)((addResult[3] << 24) | (addResult[2] << 16) | (addResult[1] << 8) | (addResult[0]));
LMULer = Adder3 * Adder3;
LMULer = LMULer << 32;
LMULer = LMULer >> 32;
Adder3 = Convert.ToUInt32(LMULer & 0xffffffff);
addResult[0] = (byte)(Adder3 & 0xff);
addResult[1] = (byte)((Adder3 >> 8) & 0xff);
addResult[2] = (byte)((Adder3 >> 16) & 0xff);
addResult[3] = (byte)((Adder3 >> 24) & 0xff);
for (int b = 3; b >= 0; b--)
{
tempKey[3 - b] = addResult[b];
}
//Build the 4th Key
for (int b = 0; b < 256; b++)
{
m_Key4[b] = Convert.ToByte(tempKey[3 - (b % 4)] ^ m_Key2[b]);
}
Monitor.Exit(this);
//cout << "Int representation: " << charadd.i << endl;
}
public void ResetCounter()
{
//Monitor.Enter(this);
m_OutCounter = 0;
m_InCounter = 0;
//Monitor.Exit(this);
}
public void EnableAlternateKeys()
{
//Monitor.Enter(this);
m_UseAlt = true;
//m_InCounter = 0;
m_OutCounter = 0;
//Monitor.Exit(this);
}
public void DisableAlternateKeys()
{
//Monitor.Enter(this);
m_UseAlt = false;
m_InCounter = 0;
m_OutCounter = 0;
//Monitor.Exit(this);
}
public void Encrypt(ref byte[] Data, bool Reverse)
{
try
{
//Monitor.Enter(this);
if (!Reverse)
for (int b = 0; b < Data.Length; b++)
{
Data[b] = (byte)(Data[b] ^ 0xab);
Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4);
Data[b] = (byte)(m_Key2[m_OutCounter >> 8] ^ Data[b]);
Data[b] = (byte)(m_Key1[m_OutCounter & 0x00ff] ^ Data[b]);
m_OutCounter++;
}
else
for (int b = 0; b < Data.Length; b++)
{
Data[b] = (byte)(m_Key1[m_OutCounter & 0x00ff] ^ Data[b]);
Data[b] = (byte)(m_Key2[m_OutCounter >> 8] ^ Data[b]);
Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4);
Data[b] = (byte)(Data[b] ^ 0xab);
m_OutCounter++;
}
//Console.WriteLine("OutCounter = " + m_OutCounter);
//Monitor.Exit(this);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public void Decrypt(ref byte[] Data, bool Reverse)
{
try
{
byte[] Key1;
byte[] Key2;
if (m_UseAlt)
{
Key1 = m_Key3;
Key2 = m_Key4;
}
else
{
Key1 = m_Key1;
Key2 = m_Key2;
}
//Monitor.Enter(this);
if (!Reverse)
for (int b = 0; b < Data.Length; b++)
{
Data[b] = (byte)(Data[b] ^ 0xab);
Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4);
Data[b] = (byte)(Key2[m_InCounter >> 8] ^ Data[b]);
Data[b] = (byte)(Key1[(m_InCounter & 0x00ff)] ^ Data[b]);
m_InCounter++;
}
else
for (int b = 0; b < Data.Length; b++)
{
Data[b] = (byte)(Key1[(m_InCounter & 0x00ff)] ^ Data[b]);
Data[b] = (byte)(Key2[m_InCounter >> 8] ^ Data[b]);
Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4);
Data[b] = (byte)(Data[b] ^ 0xab);
m_InCounter++;
}
//Monitor.Exit(this);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public void PeekDecrypt(ref byte[] Data)
{
//Monitor.Enter(this);
for (int b = 0; b < Data.Length; b++)
{
Data[b] = (byte)(m_Key1[((m_InCounter + b) & 0x00ff)] ^ Data[b]);
Data[b] = (byte)(m_Key2[(m_InCounter + b) >> 8] ^ Data[b]);
Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4);
Data[b] = (byte)(Data[b] ^ 0xab);
}
//Monitor.Exit(this);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace COProxy
{
public unsafe class Native
{
[DllImport("msvcrt.dll")]
public static extern unsafe void* memcpy(void* dest, void* src, uint size);
[DllImport("user32.dll")]
public static extern int MessageBox(int h, string m,
string c, int type);
[DllImport("winmm.dll")]
public static extern uint timeGetTime();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace COProxy
{
class PacketSave
{
bool Hex = false;
string Path;
public PacketSave(string path, bool hex)
{
Hex = hex;
Path = path;
}
public void SavePacket(byte[] Data)
{
StreamWriter PacketLog = new StreamWriter(Path, true);
string Packet = "";
byte i = 0;
foreach (byte b in Data)
{
if (Hex)
Packet += b.ToString("X2") + " ";
else
Packet += b.ToString() + " ";
if (i % 16 == 15)
Packet += Environment.NewLine;
i++;
}
PacketLog.WriteLine(Environment.NewLine + "Packet ID: " + BitConverter.ToUInt16(Data, 2) + " Length: " + BitConverter.ToUInt16(Data, 0));
PacketLog.WriteLine(Packet);
PacketLog.Flush();
PacketLog.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace COProxy
{
class Program
{
public static Proxy AuthSniffer;
public static Proxy GameSniffer;
public static PacketSave PS = new PacketSave("C:\\Packets.txt", false);
static void Main(string[] args)
{
try
{
AuthSniffer = new Proxy();
AuthSniffer.SetServerConnHandler(new ConnectionArrived(AuthServerConnection));
AuthSniffer.SetClientDataHandler(new DataArrived(AuthClientData));
AuthSniffer.SetServerDataHandler(new DataArrived(AuthServerData));
AuthSniffer.SetServerDCHandler(new Disconnection(AuthServerDC));
AuthSniffer.SetClientDCHandler(new Disconnection(AuthClientDC));
AuthSniffer.Name = "AuthSniffer";
AuthSniffer.Start("IP_ADDRESS_HERE", 9958);
GameSniffer = new Proxy();
GameSniffer.SetServerConnHandler(new ConnectionArrived(GameServerConnection));
GameSniffer.SetClientDataHandler(new DataArrived(GameClientData));
GameSniffer.SetServerDataHandler(new DataArrived(GameServerData));
GameSniffer.SetServerDCHandler(new Disconnection(GameServerDC));
GameSniffer.SetClientDCHandler(new Disconnection(GameClientDC));
GameSniffer.Name = "GameSniffer";
GameSniffer.Start("IP_ADDRESS_HERE", 5816);
}
catch (Exception Exc) { Console.WriteLine(Exc); }
Console.ReadLine();
}
public static void AuthServerDC(StateObj S)
{
Environment.Exit(0);
}
public static void AuthClientDC(StateObj S)
{
Console.WriteLine("Proxy lost connection with Auth Server.");
Console.ReadLine();
Environment.Exit(0);
}
public static void GameServerDC(StateObj S)
{
Environment.Exit(0);
}
public static void GameClientDC(StateObj S)
{
Console.WriteLine("Proxy lost connection with Game Server.");
Console.ReadLine();
Environment.Exit(0);
}
public static void AuthServerConnection(StateObj S)
{
Console.WriteLine("Auth - Client connected to the proxy.");
}
public static unsafe void AuthServerData(StateObj StO, byte[] data)
{
try
{
byte[] Data = new byte[data.Length];
fixed (byte* p1 = Data, p2 = data)
Native.memcpy(p1, p2, (uint)data.Length);
AuthSniffer.ServerCrypto.Decrypt(ref Data, false);
ushort PacketID = BitConverter.ToUInt16(Data, 2);
Console.WriteLine("Auth - Packet: Client -> Server, ID: " + PacketID);
AuthSniffer.ClientCrypto.Decrypt(ref Data, true);
AuthSniffer.Client.SendTo(Data, AuthSniffer.Client.RemoteEndPoint);
}
catch (Exception Exc) { Console.WriteLine(Exc); }
}
public static unsafe void AuthClientData(StateObj StO, byte[] data)
{
try
{
AuthSniffer.ClientCrypto.Encrypt(ref data, true);
byte[] Data = new byte[data.Length];
fixed (byte* p1 = Data, p2 = data)
Native.memcpy(p1, p2, (uint)data.Length);
ushort PacketID = BitConverter.ToUInt16(Data, 2);
Console.WriteLine("Auth - Packet: Server -> Client, ID: " + PacketID);
string ip = "IP_ADDRESS_HERE";
if (PacketID == 1055)
{
fixed (byte* p = Data)
{
for (int i = 0; i < ip.Length; i++)
{
*(p + 12 + i) = Convert.ToByte(ip[i]);
}
for (int i = ip.Length; i < 16; i++)
*(p + 12 + i) = 0;
}
}
AuthSniffer.ServerCrypto.Encrypt(ref Data, false);
AuthSniffer.Soc.Send(Data);
}
catch (Exception Exc) { Console.WriteLine(Exc); }
}
public static void GameServerConnection(StateObj S)
{
Console.WriteLine("Game - Client connected to the proxy.");
}
public static unsafe void GameServerData(StateObj StO, byte[] data)
{
try
{
byte[] Data = new byte[data.Length];
fixed (byte* p1 = Data, p2 = data)
Native.memcpy(p1, p2, (uint)data.Length);
GameSniffer.ServerCrypto.Decrypt(ref Data, false);
ushort PacketID = BitConverter.ToUInt16(Data, 2);
Console.WriteLine("Game - Packet: Client -> Server, ID: " + PacketID);
if (PacketID == 1052)
{
GameSniffer.ServerCrypto.SetKeys(new byte[4] { Data[11], Data[10], Data[9], Data[8] }, new byte[4] { Data[7], Data[6], Data[5], Data[4] });
GameSniffer.ServerCrypto.EnableAlternateKeys();
GameSniffer.ClientCrypto.SetKeys(new byte[4] { Data[11], Data[10], Data[9], Data[8] }, new byte[4] { Data[7], Data[6], Data[5], Data[4] });
}
PS.SavePacket(Data);
GameSniffer.ClientCrypto.Decrypt(ref Data, true);
GameSniffer.Client.SendTo(Data, GameSniffer.Client.RemoteEndPoint);
if (PacketID == 1052)
GameSniffer.ClientCrypto.EnableAlternateKeys();
}
catch (Exception Exc) { Console.WriteLine(Exc); }
}
public static unsafe void GameClientData(StateObj StO, byte[] data)
{
try
{
byte[] Data = new byte[data.Length];
fixed (byte* p1 = Data, p2 = data)
Native.memcpy(p1, p2, (uint)data.Length);
GameSniffer.ClientCrypto.Encrypt(ref Data, true);
ushort PacketID = BitConverter.ToUInt16(Data, 2);
Console.WriteLine("Game - Packet: Server -> Client, ID: " + PacketID);
PS.SavePacket(Data);
GameSniffer.ServerCrypto.Encrypt(ref Data, false);
GameSniffer.Soc.Send(Data);
}
catch (Exception Exc) { Console.WriteLine(Exc); }
}
}
public class StateObj
{
public byte[] Buffer = new byte[1024];
public Socket MySock = null;
public object Wrapper;
}
public delegate void ConnectionArrived(StateObj StO);
public delegate void DataArrived(StateObj StO, byte[] Buffer);
public delegate void Disconnection(StateObj StO);
public class Proxy
{
public Socket Client;//Socket that listens for packets from Server to Client
public Socket Server;//Socket that listens for packets from Client to Server
public Socket Soc;
public string Name = "";
ConnectionArrived ServerConnHandler;
DataArrived ServerDataHandler;
DataArrived ClientDataHandler;
Disconnection ServerDCHandler;
Disconnection ClientDCHandler;
public Cryptographer ClientCrypto = new Cryptographer();
public Cryptographer ServerCrypto = new Cryptographer();
public void SetServerDCHandler(Disconnection C)
{
ServerDCHandler = C;
}
public void SetClientDCHandler(Disconnection C)
{
ClientDCHandler = C;
}
public void SetServerConnHandler(ConnectionArrived C)
{
ServerConnHandler = C;
}
public void SetServerDataHandler(DataArrived C)
{
ServerDataHandler = C;
}
public void SetClientDataHandler(DataArrived C)
{
ClientDataHandler = C;
}
public void Stop()
{
Client.Shutdown(SocketShutdown.Both);
Server.Shutdown(SocketShutdown.Both);
Client.Close();
Server.Close();
Client = null;
Server = null;
}
public void Start(string ServerIP, int Port)
{
Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ServEP = new IPEndPoint(IPAddress.Parse(ServerIP), Port);
Client.BeginConnect(ServEP, new AsyncCallback(ClientConnect), new StateObj());
Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint IPE = new IPEndPoint(IPAddress.Any, 432);
Server.Bind(IPE);
Server.Listen(100);
Server.BeginAccept(new AsyncCallback(ServerConnection), new StateObj());
}
public void ClientConnect(IAsyncResult R)
{
StateObj S = (StateObj)R.AsyncState;
Client.EndConnect(R);
S.MySock = Client;
S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ClientData), S);
Console.WriteLine(Name + " ->Connected to server successfully.");
}
public unsafe void ClientData(IAsyncResult R)//Client socket receives data from SERVER
{//Server -> Client Soc -> Client()
try
{
StateObj S = (StateObj)R.AsyncState;
SocketError SE;
int Len = S.MySock.EndReceive(R, out SE);
if (S.MySock.Connected)
{
if (SE == SocketError.Success && Len != 0)
{
byte[] data = new byte[Len];
fixed (byte* p1 = data, p2 = S.Buffer)
Native.memcpy(p1, p2, (uint)Len);
if (ClientDataHandler != null)
ClientDataHandler.Invoke(S, data);
}
else
if (ClientDCHandler != null)
ClientDCHandler.Invoke(S);
}
else
if (ClientDCHandler != null)
ClientDCHandler.Invoke(S);
try
{
S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ClientData), S);
}
catch { }
}
catch (Exception Exc) { Console.WriteLine(Exc); }
}
public void ServerConnection(IAsyncResult R)//Server gets new connection
{//Client -> Server Soc -> Server(Client Socket's remote address)
StateObj S = (StateObj)R.AsyncState;
try
{
S.MySock = Server.EndAccept(R);
Soc = S.MySock;
if (ServerConnHandler != null)
ServerConnHandler.Invoke(S);
Server.BeginAccept(new AsyncCallback(ServerConnection), new StateObj());
}
catch (Exception Exc) { Console.WriteLine(Exc); }
try
{
S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ServerReceive), S);
}
catch { }
}
public unsafe void ServerReceive(IAsyncResult R)//Server socket receives data from CLIENT
{
StateObj S = (StateObj)R.AsyncState;
try
{
SocketError SE;
int Len = S.MySock.EndReceive(R, out SE);
if (S.MySock.Connected)
{
if (SE == SocketError.Success && Len != 0)
{
byte[] data = new byte[Len];
fixed (byte* p1 = data, p2 = S.Buffer)
Native.memcpy(p1, p2, (uint)Len);
if (ServerDataHandler != null)
ServerDataHandler.Invoke(S, data);
}
else
if (ClientDCHandler != null)
ClientDCHandler.Invoke(S);
}
else
if (ClientDCHandler != null)
ClientDCHandler.Invoke(S);
}
catch (Exception Exc) { Console.WriteLine(Exc); }
try
{
S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ServerReceive), S);
}
catch { }
}
}
}
when i put the AuthSniffer Ip as the server ip and GameSniffer ip as my local IP it gives me that error and nvr get connect to the client msgQuote:
Works on 5017.
IP_ADDRESS_HERE means you put the IP there yes, as a string (within " and ")
you know that you are a big spammer ????????!Quote:
lmao pwnd
Quote:
Follow this guide:
Make a new console application, add:
Cryptographer.cs
Code:using System; using System.Threading; namespace COProxy { /// <summary> /// Summary description for Cryptographer. /// </summary> public class Cryptographer : object { public ushort m_InCounter = 0; public ushort m_OutCounter = 0; bool m_UseAlt = false; private byte[] m_Key1 = { 0x9D, 0x90, 0x83, 0x8A, 0xD1, 0x8C, 0xE7, 0xF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0xDF, 0x78, 0x25, 0xEE, 0x7B, 0x94, 0xA1, 0x2A, 0x57, 0x70, 0x5D, 0x26, 0x73, 0x0C, 0x59, 0xE2, 0xCF, 0x68, 0x95, 0x5E, 0x6B, 0x84, 0x11, 0x9A, 0x47, 0x60, 0xCD, 0x96, 0x63, 0xFC, 0xC9, 0x52, 0xBF, 0x58, 0x05, 0xCE, 0x5B, 0x74, 0x81, 0x0A, 0x37, 0x50, 0x3D, 0x06, 0x53, 0xEC, 0x39, 0xC2, 0xAF, 0x48, 0x75, 0x3E, 0x4B, 0x64, 0xF1, 0x7A, 0x27, 0x40, 0xAD, 0x76, 0x43, 0xDC, 0xA9, 0x32, 0x9F, 0x38, 0xE5, 0xAE, 0x3B, 0x54, 0x61, 0xEA, 0x17, 0x30, 0x1D, 0xE6, 0x33, 0xCC, 0x19, 0xA2, 0x8F, 0x28, 0x55, 0x1E, 0x2B, 0x44, 0xD1, 0x5A, 0x07, 0x20, 0x8D, 0x56, 0x23, 0xBC, 0x89, 0x12, 0x7F, 0x18, 0xC5, 0x8E, 0x1B, 0x34, 0x41, 0xCA, 0xF7, 0x10, 0xFD, 0xC6, 0x13, 0xAC, 0xF9, 0x82, 0x6F, 0x08, 0x35, 0xFE, 0x0B, 0x24, 0xB1, 0x3A, 0xE7, 0x00, 0x6D, 0x36, 0x03, 0x9C, 0x69, 0xF2, 0x5F, 0xF8, 0xA5, 0x6E, 0xFB, 0x14, 0x21, 0xAA, 0xD7, 0xF0, 0xDD, 0xA6, 0xF3, 0x8C, 0xD9}; private byte[] m_Key3; private byte[] m_Key4; public Cryptographer() { } public void SetKeys(byte[] InKey1, byte[] InKey2) { byte[] addKey1 = new byte[4]; byte[] addKey2 = new byte[4]; byte[] addResult = new byte[4]; //addKey1.i = 0; //addKey2.i = 0; byte[] tempKey = new byte[4]; long LMULer; // InKey1[0] = 0x20; // InKey1[1] = 0x5c; // InKey1[2] = 0x48; // InKey1[3] = 0xf4; // InKey2[0] = 0x00; // InKey2[1] = 0x44; // InKey2[2] = 0xa6; // InKey2[3] = 0x2e; //if (Key3) delete [] Key3; //if (Key4) delete [] Key4; Monitor.Enter(this); m_Key3 = new Byte[256]; m_Key4 = new Byte[256]; for (int x = 0; x < 4; x++) { addKey1[x] = InKey1[3 - x]; addKey2[x] = InKey2[3 - x]; } //cout << "Key1: " << addKey1.i << endl; //cout << "Key2: " << addKey2.i << endl; uint Adder1; uint Adder2; uint Adder3; Adder1 = (uint)((addKey1[3] << 24) | (addKey1[2] << 16) | (addKey1[1] << 8) | (addKey1[0])); Adder2 = (uint)((addKey2[3] << 24) | (addKey2[2] << 16) | (addKey2[1] << 8) | (addKey2[0])); Adder3 = Adder1 + Adder2; addResult[0] = (byte)(Adder3 & 0xff); addResult[1] = (byte)((Adder3 >> 8) & 0xff); addResult[2] = (byte)((Adder3 >> 16) & 0xff); addResult[3] = (byte)((Adder3 >> 24) & 0xff); for (int b = 3; b >= 0; b--) { // printf("%.2x ", addResult.c[b]); tempKey[3 - b] = addResult[b]; } tempKey[2] = (byte)(tempKey[2] ^ (byte)0x43); tempKey[3] = (byte)(tempKey[3] ^ (byte)0x21); for (int b = 0; b < 4; b++) { tempKey[b] = (byte)(tempKey[b] ^ InKey1[b]); } //Build the 3rd Key for (int b = 0; b < 256; b++) { m_Key3[b] = (byte)(tempKey[3 - (b % 4)] ^ m_Key1[b]); } for (int x = 0; x < 4; x++) { addResult[x] = tempKey[3 - x]; } Adder3 = (uint)((addResult[3] << 24) | (addResult[2] << 16) | (addResult[1] << 8) | (addResult[0])); LMULer = Adder3 * Adder3; LMULer = LMULer << 32; LMULer = LMULer >> 32; Adder3 = Convert.ToUInt32(LMULer & 0xffffffff); addResult[0] = (byte)(Adder3 & 0xff); addResult[1] = (byte)((Adder3 >> 8) & 0xff); addResult[2] = (byte)((Adder3 >> 16) & 0xff); addResult[3] = (byte)((Adder3 >> 24) & 0xff); for (int b = 3; b >= 0; b--) { tempKey[3 - b] = addResult[b]; } //Build the 4th Key for (int b = 0; b < 256; b++) { m_Key4[b] = Convert.ToByte(tempKey[3 - (b % 4)] ^ m_Key2[b]); } Monitor.Exit(this); //cout << "Int representation: " << charadd.i << endl; } public void ResetCounter() { //Monitor.Enter(this); m_OutCounter = 0; m_InCounter = 0; //Monitor.Exit(this); } public void EnableAlternateKeys() { //Monitor.Enter(this); m_UseAlt = true; //m_InCounter = 0; m_OutCounter = 0; //Monitor.Exit(this); } public void DisableAlternateKeys() { //Monitor.Enter(this); m_UseAlt = false; m_InCounter = 0; m_OutCounter = 0; //Monitor.Exit(this); } public void Encrypt(ref byte[] Data, bool Reverse) { try { //Monitor.Enter(this); if (!Reverse) for (int b = 0; b < Data.Length; b++) { Data[b] = (byte)(Data[b] ^ 0xab); Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4); Data[b] = (byte)(m_Key2[m_OutCounter >> 8] ^ Data[b]); Data[b] = (byte)(m_Key1[m_OutCounter & 0x00ff] ^ Data[b]); m_OutCounter++; } else for (int b = 0; b < Data.Length; b++) { Data[b] = (byte)(m_Key1[m_OutCounter & 0x00ff] ^ Data[b]); Data[b] = (byte)(m_Key2[m_OutCounter >> 8] ^ Data[b]); Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4); Data[b] = (byte)(Data[b] ^ 0xab); m_OutCounter++; } //Console.WriteLine("OutCounter = " + m_OutCounter); //Monitor.Exit(this); } catch (Exception e) { Console.WriteLine(e.ToString()); } } public void Decrypt(ref byte[] Data, bool Reverse) { try { byte[] Key1; byte[] Key2; if (m_UseAlt) { Key1 = m_Key3; Key2 = m_Key4; } else { Key1 = m_Key1; Key2 = m_Key2; } //Monitor.Enter(this); if (!Reverse) for (int b = 0; b < Data.Length; b++) { Data[b] = (byte)(Data[b] ^ 0xab); Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4); Data[b] = (byte)(Key2[m_InCounter >> 8] ^ Data[b]); Data[b] = (byte)(Key1[(m_InCounter & 0x00ff)] ^ Data[b]); m_InCounter++; } else for (int b = 0; b < Data.Length; b++) { Data[b] = (byte)(Key1[(m_InCounter & 0x00ff)] ^ Data[b]); Data[b] = (byte)(Key2[m_InCounter >> 8] ^ Data[b]); Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4); Data[b] = (byte)(Data[b] ^ 0xab); m_InCounter++; } //Monitor.Exit(this); } catch (Exception e) { Console.WriteLine(e.ToString()); } } public void PeekDecrypt(ref byte[] Data) { //Monitor.Enter(this); for (int b = 0; b < Data.Length; b++) { Data[b] = (byte)(m_Key1[((m_InCounter + b) & 0x00ff)] ^ Data[b]); Data[b] = (byte)(m_Key2[(m_InCounter + b) >> 8] ^ Data[b]); Data[b] = (byte)(Data[b] << 4 | Data[b] >> 4); Data[b] = (byte)(Data[b] ^ 0xab); } //Monitor.Exit(this); } } }
Native.cs
Code:using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace COProxy { public unsafe class Native { [DllImport("msvcrt.dll")] public static extern unsafe void* memcpy(void* dest, void* src, uint size); [DllImport("user32.dll")] public static extern int MessageBox(int h, string m, string c, int type); [DllImport("winmm.dll")] public static extern uint timeGetTime(); } }
PacketSave.cs
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace COProxy { class PacketSave { bool Hex = false; string Path; public PacketSave(string path, bool hex) { Hex = hex; Path = path; } public void SavePacket(byte[] Data) { StreamWriter PacketLog = new StreamWriter(Path, true); string Packet = ""; byte i = 0; foreach (byte b in Data) { if (Hex) Packet += b.ToString("X2") + " "; else Packet += b.ToString() + " "; if (i % 16 == 15) Packet += Environment.NewLine; i++; } PacketLog.WriteLine(Environment.NewLine + "Packet ID: " + BitConverter.ToUInt16(Data, 2) + " Length: " + BitConverter.ToUInt16(Data, 0)); PacketLog.WriteLine(Packet); PacketLog.Flush(); PacketLog.Close(); } } }
Program.cs
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; namespace COProxy { class Program { public static Proxy AuthSniffer; public static Proxy GameSniffer; public static PacketSave PS = new PacketSave("C:\\Packets.txt", false); static void Main(string[] args) { try { AuthSniffer = new Proxy(); AuthSniffer.SetServerConnHandler(new ConnectionArrived(AuthServerConnection)); AuthSniffer.SetClientDataHandler(new DataArrived(AuthClientData)); AuthSniffer.SetServerDataHandler(new DataArrived(AuthServerData)); AuthSniffer.SetServerDCHandler(new Disconnection(AuthServerDC)); AuthSniffer.SetClientDCHandler(new Disconnection(AuthClientDC)); AuthSniffer.Name = "AuthSniffer"; AuthSniffer.Start("IP_ADDRESS_HERE", 9958); GameSniffer = new Proxy(); GameSniffer.SetServerConnHandler(new ConnectionArrived(GameServerConnection)); GameSniffer.SetClientDataHandler(new DataArrived(GameClientData)); GameSniffer.SetServerDataHandler(new DataArrived(GameServerData)); GameSniffer.SetServerDCHandler(new Disconnection(GameServerDC)); GameSniffer.SetClientDCHandler(new Disconnection(GameClientDC)); GameSniffer.Name = "GameSniffer"; GameSniffer.Start("IP_ADDRESS_HERE", 5816); } catch (Exception Exc) { Console.WriteLine(Exc); } Console.ReadLine(); } public static void AuthServerDC(StateObj S) { Environment.Exit(0); } public static void AuthClientDC(StateObj S) { Console.WriteLine("Proxy lost connection with Auth Server."); Console.ReadLine(); Environment.Exit(0); } public static void GameServerDC(StateObj S) { Environment.Exit(0); } public static void GameClientDC(StateObj S) { Console.WriteLine("Proxy lost connection with Game Server."); Console.ReadLine(); Environment.Exit(0); } public static void AuthServerConnection(StateObj S) { Console.WriteLine("Auth - Client connected to the proxy."); } public static unsafe void AuthServerData(StateObj StO, byte[] data) { try { byte[] Data = new byte[data.Length]; fixed (byte* p1 = Data, p2 = data) Native.memcpy(p1, p2, (uint)data.Length); AuthSniffer.ServerCrypto.Decrypt(ref Data, false); ushort PacketID = BitConverter.ToUInt16(Data, 2); Console.WriteLine("Auth - Packet: Client -> Server, ID: " + PacketID); AuthSniffer.ClientCrypto.Decrypt(ref Data, true); AuthSniffer.Client.SendTo(Data, AuthSniffer.Client.RemoteEndPoint); } catch (Exception Exc) { Console.WriteLine(Exc); } } public static unsafe void AuthClientData(StateObj StO, byte[] data) { try { AuthSniffer.ClientCrypto.Encrypt(ref data, true); byte[] Data = new byte[data.Length]; fixed (byte* p1 = Data, p2 = data) Native.memcpy(p1, p2, (uint)data.Length); ushort PacketID = BitConverter.ToUInt16(Data, 2); Console.WriteLine("Auth - Packet: Server -> Client, ID: " + PacketID); string ip = "IP_ADDRESS_HERE"; if (PacketID == 1055) { fixed (byte* p = Data) { for (int i = 0; i < ip.Length; i++) { *(p + 12 + i) = Convert.ToByte(ip[i]); } for (int i = ip.Length; i < 16; i++) *(p + 12 + i) = 0; } } AuthSniffer.ServerCrypto.Encrypt(ref Data, false); AuthSniffer.Soc.Send(Data); } catch (Exception Exc) { Console.WriteLine(Exc); } } public static void GameServerConnection(StateObj S) { Console.WriteLine("Game - Client connected to the proxy."); } public static unsafe void GameServerData(StateObj StO, byte[] data) { try { byte[] Data = new byte[data.Length]; fixed (byte* p1 = Data, p2 = data) Native.memcpy(p1, p2, (uint)data.Length); GameSniffer.ServerCrypto.Decrypt(ref Data, false); ushort PacketID = BitConverter.ToUInt16(Data, 2); Console.WriteLine("Game - Packet: Client -> Server, ID: " + PacketID); if (PacketID == 1052) { GameSniffer.ServerCrypto.SetKeys(new byte[4] { Data[11], Data[10], Data[9], Data[8] }, new byte[4] { Data[7], Data[6], Data[5], Data[4] }); GameSniffer.ServerCrypto.EnableAlternateKeys(); GameSniffer.ClientCrypto.SetKeys(new byte[4] { Data[11], Data[10], Data[9], Data[8] }, new byte[4] { Data[7], Data[6], Data[5], Data[4] }); } PS.SavePacket(Data); GameSniffer.ClientCrypto.Decrypt(ref Data, true); GameSniffer.Client.SendTo(Data, GameSniffer.Client.RemoteEndPoint); if (PacketID == 1052) GameSniffer.ClientCrypto.EnableAlternateKeys(); } catch (Exception Exc) { Console.WriteLine(Exc); } } public static unsafe void GameClientData(StateObj StO, byte[] data) { try { byte[] Data = new byte[data.Length]; fixed (byte* p1 = Data, p2 = data) Native.memcpy(p1, p2, (uint)data.Length); GameSniffer.ClientCrypto.Encrypt(ref Data, true); ushort PacketID = BitConverter.ToUInt16(Data, 2); Console.WriteLine("Game - Packet: Server -> Client, ID: " + PacketID); PS.SavePacket(Data); GameSniffer.ServerCrypto.Encrypt(ref Data, false); GameSniffer.Soc.Send(Data); } catch (Exception Exc) { Console.WriteLine(Exc); } } } public class StateObj { public byte[] Buffer = new byte[1024]; public Socket MySock = null; public object Wrapper; } public delegate void ConnectionArrived(StateObj StO); public delegate void DataArrived(StateObj StO, byte[] Buffer); public delegate void Disconnection(StateObj StO); public class Proxy { public Socket Client;//Socket that listens for packets from Server to Client public Socket Server;//Socket that listens for packets from Client to Server public Socket Soc; public string Name = ""; ConnectionArrived ServerConnHandler; DataArrived ServerDataHandler; DataArrived ClientDataHandler; Disconnection ServerDCHandler; Disconnection ClientDCHandler; public Cryptographer ClientCrypto = new Cryptographer(); public Cryptographer ServerCrypto = new Cryptographer(); public void SetServerDCHandler(Disconnection C) { ServerDCHandler = C; } public void SetClientDCHandler(Disconnection C) { ClientDCHandler = C; } public void SetServerConnHandler(ConnectionArrived C) { ServerConnHandler = C; } public void SetServerDataHandler(DataArrived C) { ServerDataHandler = C; } public void SetClientDataHandler(DataArrived C) { ClientDataHandler = C; } public void Stop() { Client.Shutdown(SocketShutdown.Both); Server.Shutdown(SocketShutdown.Both); Client.Close(); Server.Close(); Client = null; Server = null; } public void Start(string ServerIP, int Port) { Client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ServEP = new IPEndPoint(IPAddress.Parse(ServerIP), Port); Client.BeginConnect(ServEP, new AsyncCallback(ClientConnect), new StateObj()); Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint IPE = new IPEndPoint(IPAddress.Any, 432); Server.Bind(IPE); Server.Listen(100); Server.BeginAccept(new AsyncCallback(ServerConnection), new StateObj()); } public void ClientConnect(IAsyncResult R) { StateObj S = (StateObj)R.AsyncState; Client.EndConnect(R); S.MySock = Client; S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ClientData), S); Console.WriteLine(Name + " ->Connected to server successfully."); } public unsafe void ClientData(IAsyncResult R)//Client socket receives data from SERVER {//Server -> Client Soc -> Client() try { StateObj S = (StateObj)R.AsyncState; SocketError SE; int Len = S.MySock.EndReceive(R, out SE); if (S.MySock.Connected) { if (SE == SocketError.Success && Len != 0) { byte[] data = new byte[Len]; fixed (byte* p1 = data, p2 = S.Buffer) Native.memcpy(p1, p2, (uint)Len); if (ClientDataHandler != null) ClientDataHandler.Invoke(S, data); } else if (ClientDCHandler != null) ClientDCHandler.Invoke(S); } else if (ClientDCHandler != null) ClientDCHandler.Invoke(S); try { S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ClientData), S); } catch { } } catch (Exception Exc) { Console.WriteLine(Exc); } } public void ServerConnection(IAsyncResult R)//Server gets new connection {//Client -> Server Soc -> Server(Client Socket's remote address) StateObj S = (StateObj)R.AsyncState; try { S.MySock = Server.EndAccept(R); Soc = S.MySock; if (ServerConnHandler != null) ServerConnHandler.Invoke(S); Server.BeginAccept(new AsyncCallback(ServerConnection), new StateObj()); } catch (Exception Exc) { Console.WriteLine(Exc); } try { S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ServerReceive), S); } catch { } } public unsafe void ServerReceive(IAsyncResult R)//Server socket receives data from CLIENT { StateObj S = (StateObj)R.AsyncState; try { SocketError SE; int Len = S.MySock.EndReceive(R, out SE); if (S.MySock.Connected) { if (SE == SocketError.Success && Len != 0) { byte[] data = new byte[Len]; fixed (byte* p1 = data, p2 = S.Buffer) Native.memcpy(p1, p2, (uint)Len); if (ServerDataHandler != null) ServerDataHandler.Invoke(S, data); } else if (ClientDCHandler != null) ClientDCHandler.Invoke(S); } else if (ClientDCHandler != null) ClientDCHandler.Invoke(S); } catch (Exception Exc) { Console.WriteLine(Exc); } try { S.MySock.BeginReceive(S.Buffer, 0, 1024, SocketFlags.None, new AsyncCallback(ServerReceive), S); } catch { } } } }
Figure rest out by yourself, enjoy.
Works great on patch 5017.