midoazoz
2019-11-19, 05:40 PM
يا جدعان انا مليش في الثري دي ولا البروتتو ولا الجو ده
بس انا حلتلكم الايرورات الي بتجيلكم
وياريت حد يجرب ويقلي هيشتغل ولا لا
ولو لا هعدل الموضوع وانزلكم حل تاني بس نجرب ده الاول
اولا
هتفتح
Auth.cs
امسح الي فيه وحط ده
using SomailProject.Network.Cryptography;
using System;
using System.IO;
using System.Text;
namespace SomailProject.Network.AuthPackets
{
public unsafe class Authentications : Interfaces.IPacket
{
public string Username;
public string Password;
public string Server;
public string MacAddress;
public Authentications()
{
}
public void Deserialize(byte[] buffer)
{
if (buffer.Length == 312)
{
ushort length = BitConverter.ToUInt16(buffer, 0);
if (length == 312)
{
ushort type = BitConverter.ToUInt16(buffer, 2);
byte[] temp = new byte[16];
if (type == 1636)
{
MemoryStream MS = new MemoryStream(buffer);
BinaryReader BR = new BinaryReader(MS);
BR.ReadUInt16();
BR.ReadUInt16();
Username = Encoding.Default.GetString(BR.ReadBytes(32)).Repla ce("\0", "");
BR.ReadBytes(36);
var PasswordArray = BR.ReadBytes(32);
LoaderEncryption.Decrypt(PasswordArray, 32);
Password = Username;
BR.ReadBytes(32);
Server = Encoding.Default.GetString(BR.ReadBytes(16)).Repla ce("\0", ""); ;
MacAddress = Encoding.Default.GetString(BR.ReadBytes(12)).Repla ce("\0", "");
BR.Close();
MS.Close();
}
}
}
// Password == Username
//
}
public byte[] ToArray()
{
throw new NotImplementedException();
}
public void Send(Client.GameState client)
{
throw new NotImplementedException();
}
}
}
namespace SomailProject.Network.Cryptography
{
public class LoaderEncryption
{
private static byte[] Key =
{
180,
152,
187,
196,
231,
208,
204,
120,
177,
164,
184,
77,
9,
125,
114,
49,
9,
191,
20,
122,
9,
39,
123,
17,
115,
222,
188,
120,
109,
9,
65,
206,
85,
10,
29,
215,
143,
108,
231,
114
};
public static void Encrypt(byte[] arr)
{
int length = Key.Length;
for (int i = 0; i < arr.Length; i++)
{
arr[i] ^= Key[i % length];
arr[i] ^= Key[(i + 1) % length];
}
}
public static void Decrypt(byte[] arr, int size)
{
int length = Key.Length;
for (int i = 0; i < size; i++)
{
arr[i] ^= Key[(i + 1) % length];
arr[i] ^= Key[i % length];
}
}
}
}
هتخش ع LoaderEncryption.cs امسح الي فيه كله
ملف Forward زي مهو زي ما احمد منزله
بالنسبه ل program
هتبحث عن ده قبل متحطوا حاجه
static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
اقفله وبدل بده
public static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
{
var player = arg3.Connector as Client.AuthClient;
AuthClient authClient = arg3.Connector as AuthClient;
player.Cryptographer.Decrypt(buffer, length);
player.Queue.Enqueue(buffer, length);
while (player.Queue.CanDequeue())
{
byte[] packet = player.Queue.Dequeue();
ushort len = BitConverter.ToUInt16(packet, 0);
if (len == 312)
{
player.Info = new Authentications();
player.Info.Deserialize(packet);
player.Account = new AccountTable(player.Info.Username);
if (!LoginBruteForce.AcceptJoin(arg3.IP))
{
Console.WriteLine(string.Concat(new string[] { "Client > ", player.Info.Username, "was blocked address", arg3.IP, "!" }));
arg3.Disconnect();
break;
}
Forward Fw = new Forward();
System.Console.WriteLine("UserName: {0} Password: {1} ServerName: {2} Online", player.Info.Username, player.Info.Password, player.Info.Server);
if (player.Account.Username == player.Info.Username && player.Account.exists)
{
if (player.Account.Password == player.Info.Password && player.Account.exists)
{
Fw.Identifier = player.Account.GenerateKey();
Kernel.AwaitingPool[Fw.Identifier] = player.Account;
Fw.IP = GameIP;
Fw.Port = GamePort;
}
else
{
LoginBruteForce.ClientRegistred(arg3.IP);
Fw.Type = Forward.ForwardType.InvalidInfo;
}
}
else
{
Fw.Type = Forward.ForwardType.WrongAccount;
}
player.Send(Fw);
}
}
}
وتبحث عن
static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
اقفله وبدله بده
private static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
{
if (obj.Connector == null)
{
obj.Disconnect();
}
else
{
GameState connector = obj.Connector as GameState;
if (connector.Exchange)
{
connector.Exchange = false;
connector.Action = (byte)1;
SomailProject.Network.Cryptography.GameCryptograph y gameCryptography = new SomailProject.Network.Cryptography.GameCryptograph y(Encoding.Default.GetBytes(Constants.GameCryptogr aphyKey));
byte[] numArray = new byte[length];
Array.Copy((Array)buffer, (Array)numArray, length);
gameCryptography.Decrypt(numArray, length);
bool flag = false;
int offset = 0;
for (int x = 0; x < 80; x++)
{
if (BitConverter.ToInt32(numArray, x) == 128)
{
if (length >= 205)
{
offset = x;
flag = true;
connector.Cryptography.Decrypt(buffer, length - 40);
}
else
{
offset = x;
connector.Cryptography.Decrypt(buffer, length);
}
}
}
int int32 = BitConverter.ToInt32(buffer, offset);
int index1 = offset + 4;
if (int32 != 128)
{
connector.Disconnect(true);
}
else
{
byte[] bytes = new byte[128];
int index2 = 0;
while (index2 < int32)
{
bytes[index2] = buffer[index1];
++index2;
++index1;
}
string PublicKey = Encoding.Default.GetString(bytes);
connector.Cryptography = connector.DHKeyExchange.HandleClientKeyPacket(Publ icKey, connector.Cryptography);
if (!flag)
return;
byte[] buffer1 = new byte[40];
Buffer.BlockCopy((Array)buffer, length - 40, (Array)buffer1, 0, 40);
processData(buffer1, 40, connector);
}
}
else
processData(buffer, length, connector);
}
}
طبعا في ايرور مفيش مشكله
هتروح
المسار
Network_ AuthPackets
واعمل كلاس جديد اسمها
PacketLoginForce.cs
وضيف فيه ده
using System;
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;
using SomailProject;
namespace SomailProject.Network.Sockets
{
public unsafe class LoginBruteForce
{
public class ClientLogin
{
public string IPAdres;
public Time32 Timer;
public uint Trying;
}
public static object SyncRoot;
public static void CreatePoll()
{
SyncRoot = new object();
World.Subscribe(new Action<int>(Work), 500, ThreadPriority.Normal);
}
public static void Work(int Time)
{
ConcurrentQueue<int> concurrentQueue = new ConcurrentQueue<int>();
Time32 now = Time32.Now;
foreach (KeyValuePair<int, ClientLogin> current in Registered)
{
if (now > current.Value.Timer.AddSeconds(30))
{
if (current.Value.Trying > 0)
{
current.Value.Timer = Time32.Now;
current.Value.Trying -= 1;
}
else
{
concurrentQueue.Enqueue(current.Key);
}
}
}
int key = 0;
while (concurrentQueue.TryDequeue(out key))
{
ClientLogin clientLogin;
Registered.TryRemove(key, out clientLogin);
}
}
public static bool AcceptJoin(string Adres)
{
int hashCode = Adres.GetHashCode();
ClientLogin clientLogin;
return !Registered.TryGetValue(hashCode, out clientLogin) || clientLogin.Trying < 5;
}
public static void ClientRegistred(string Adrres)
{
//lock (SyncRoot)
{
int hashCode = Adrres.GetHashCode();
ClientLogin clientLogin;
if (Registered.TryGetValue(hashCode, out clientLogin))
{
clientLogin.Trying += 1;
clientLogin.Timer = Time32.Now;
}
else
{
clientLogin = new ClientLogin();
clientLogin.IPAdres = Adrres;
clientLogin.Timer = Time32.Now;
clientLogin.Trying = 1;
Registered.TryAdd(hashCode, clientLogin);
}
}
}
public static ConcurrentDictionary<int, ClientLogin> Registered = new ConcurrentDictionary<int, ClientLogin>();
}
}
ومتنساش constant لل kay
كده هيشتغل بنسبه 100% يشباب انا مجربتش برده بس باذن الله يشتغل
بس انا حلتلكم الايرورات الي بتجيلكم
وياريت حد يجرب ويقلي هيشتغل ولا لا
ولو لا هعدل الموضوع وانزلكم حل تاني بس نجرب ده الاول
اولا
هتفتح
Auth.cs
امسح الي فيه وحط ده
using SomailProject.Network.Cryptography;
using System;
using System.IO;
using System.Text;
namespace SomailProject.Network.AuthPackets
{
public unsafe class Authentications : Interfaces.IPacket
{
public string Username;
public string Password;
public string Server;
public string MacAddress;
public Authentications()
{
}
public void Deserialize(byte[] buffer)
{
if (buffer.Length == 312)
{
ushort length = BitConverter.ToUInt16(buffer, 0);
if (length == 312)
{
ushort type = BitConverter.ToUInt16(buffer, 2);
byte[] temp = new byte[16];
if (type == 1636)
{
MemoryStream MS = new MemoryStream(buffer);
BinaryReader BR = new BinaryReader(MS);
BR.ReadUInt16();
BR.ReadUInt16();
Username = Encoding.Default.GetString(BR.ReadBytes(32)).Repla ce("\0", "");
BR.ReadBytes(36);
var PasswordArray = BR.ReadBytes(32);
LoaderEncryption.Decrypt(PasswordArray, 32);
Password = Username;
BR.ReadBytes(32);
Server = Encoding.Default.GetString(BR.ReadBytes(16)).Repla ce("\0", ""); ;
MacAddress = Encoding.Default.GetString(BR.ReadBytes(12)).Repla ce("\0", "");
BR.Close();
MS.Close();
}
}
}
// Password == Username
//
}
public byte[] ToArray()
{
throw new NotImplementedException();
}
public void Send(Client.GameState client)
{
throw new NotImplementedException();
}
}
}
namespace SomailProject.Network.Cryptography
{
public class LoaderEncryption
{
private static byte[] Key =
{
180,
152,
187,
196,
231,
208,
204,
120,
177,
164,
184,
77,
9,
125,
114,
49,
9,
191,
20,
122,
9,
39,
123,
17,
115,
222,
188,
120,
109,
9,
65,
206,
85,
10,
29,
215,
143,
108,
231,
114
};
public static void Encrypt(byte[] arr)
{
int length = Key.Length;
for (int i = 0; i < arr.Length; i++)
{
arr[i] ^= Key[i % length];
arr[i] ^= Key[(i + 1) % length];
}
}
public static void Decrypt(byte[] arr, int size)
{
int length = Key.Length;
for (int i = 0; i < size; i++)
{
arr[i] ^= Key[(i + 1) % length];
arr[i] ^= Key[i % length];
}
}
}
}
هتخش ع LoaderEncryption.cs امسح الي فيه كله
ملف Forward زي مهو زي ما احمد منزله
بالنسبه ل program
هتبحث عن ده قبل متحطوا حاجه
static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
اقفله وبدل بده
public static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
{
var player = arg3.Connector as Client.AuthClient;
AuthClient authClient = arg3.Connector as AuthClient;
player.Cryptographer.Decrypt(buffer, length);
player.Queue.Enqueue(buffer, length);
while (player.Queue.CanDequeue())
{
byte[] packet = player.Queue.Dequeue();
ushort len = BitConverter.ToUInt16(packet, 0);
if (len == 312)
{
player.Info = new Authentications();
player.Info.Deserialize(packet);
player.Account = new AccountTable(player.Info.Username);
if (!LoginBruteForce.AcceptJoin(arg3.IP))
{
Console.WriteLine(string.Concat(new string[] { "Client > ", player.Info.Username, "was blocked address", arg3.IP, "!" }));
arg3.Disconnect();
break;
}
Forward Fw = new Forward();
System.Console.WriteLine("UserName: {0} Password: {1} ServerName: {2} Online", player.Info.Username, player.Info.Password, player.Info.Server);
if (player.Account.Username == player.Info.Username && player.Account.exists)
{
if (player.Account.Password == player.Info.Password && player.Account.exists)
{
Fw.Identifier = player.Account.GenerateKey();
Kernel.AwaitingPool[Fw.Identifier] = player.Account;
Fw.IP = GameIP;
Fw.Port = GamePort;
}
else
{
LoginBruteForce.ClientRegistred(arg3.IP);
Fw.Type = Forward.ForwardType.InvalidInfo;
}
}
else
{
Fw.Type = Forward.ForwardType.WrongAccount;
}
player.Send(Fw);
}
}
}
وتبحث عن
static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
اقفله وبدله بده
private static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
{
if (obj.Connector == null)
{
obj.Disconnect();
}
else
{
GameState connector = obj.Connector as GameState;
if (connector.Exchange)
{
connector.Exchange = false;
connector.Action = (byte)1;
SomailProject.Network.Cryptography.GameCryptograph y gameCryptography = new SomailProject.Network.Cryptography.GameCryptograph y(Encoding.Default.GetBytes(Constants.GameCryptogr aphyKey));
byte[] numArray = new byte[length];
Array.Copy((Array)buffer, (Array)numArray, length);
gameCryptography.Decrypt(numArray, length);
bool flag = false;
int offset = 0;
for (int x = 0; x < 80; x++)
{
if (BitConverter.ToInt32(numArray, x) == 128)
{
if (length >= 205)
{
offset = x;
flag = true;
connector.Cryptography.Decrypt(buffer, length - 40);
}
else
{
offset = x;
connector.Cryptography.Decrypt(buffer, length);
}
}
}
int int32 = BitConverter.ToInt32(buffer, offset);
int index1 = offset + 4;
if (int32 != 128)
{
connector.Disconnect(true);
}
else
{
byte[] bytes = new byte[128];
int index2 = 0;
while (index2 < int32)
{
bytes[index2] = buffer[index1];
++index2;
++index1;
}
string PublicKey = Encoding.Default.GetString(bytes);
connector.Cryptography = connector.DHKeyExchange.HandleClientKeyPacket(Publ icKey, connector.Cryptography);
if (!flag)
return;
byte[] buffer1 = new byte[40];
Buffer.BlockCopy((Array)buffer, length - 40, (Array)buffer1, 0, 40);
processData(buffer1, 40, connector);
}
}
else
processData(buffer, length, connector);
}
}
طبعا في ايرور مفيش مشكله
هتروح
المسار
Network_ AuthPackets
واعمل كلاس جديد اسمها
PacketLoginForce.cs
وضيف فيه ده
using System;
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;
using SomailProject;
namespace SomailProject.Network.Sockets
{
public unsafe class LoginBruteForce
{
public class ClientLogin
{
public string IPAdres;
public Time32 Timer;
public uint Trying;
}
public static object SyncRoot;
public static void CreatePoll()
{
SyncRoot = new object();
World.Subscribe(new Action<int>(Work), 500, ThreadPriority.Normal);
}
public static void Work(int Time)
{
ConcurrentQueue<int> concurrentQueue = new ConcurrentQueue<int>();
Time32 now = Time32.Now;
foreach (KeyValuePair<int, ClientLogin> current in Registered)
{
if (now > current.Value.Timer.AddSeconds(30))
{
if (current.Value.Trying > 0)
{
current.Value.Timer = Time32.Now;
current.Value.Trying -= 1;
}
else
{
concurrentQueue.Enqueue(current.Key);
}
}
}
int key = 0;
while (concurrentQueue.TryDequeue(out key))
{
ClientLogin clientLogin;
Registered.TryRemove(key, out clientLogin);
}
}
public static bool AcceptJoin(string Adres)
{
int hashCode = Adres.GetHashCode();
ClientLogin clientLogin;
return !Registered.TryGetValue(hashCode, out clientLogin) || clientLogin.Trying < 5;
}
public static void ClientRegistred(string Adrres)
{
//lock (SyncRoot)
{
int hashCode = Adrres.GetHashCode();
ClientLogin clientLogin;
if (Registered.TryGetValue(hashCode, out clientLogin))
{
clientLogin.Trying += 1;
clientLogin.Timer = Time32.Now;
}
else
{
clientLogin = new ClientLogin();
clientLogin.IPAdres = Adrres;
clientLogin.Timer = Time32.Now;
clientLogin.Trying = 1;
Registered.TryAdd(hashCode, clientLogin);
}
}
}
public static ConcurrentDictionary<int, ClientLogin> Registered = new ConcurrentDictionary<int, ClientLogin>();
}
}
ومتنساش constant لل kay
كده هيشتغل بنسبه 100% يشباب انا مجربتش برده بس باذن الله يشتغل