Hello, ça fais plusieurs heure que je cherche et je n'arrive pas a faire un serveur Mitm en C#, j'ai tout essayé socket async ou non, j'ai même essayer avec le code d'un projet opensource qui s'appelle Dofus Lab mais pareil j'ai exactement le même problème : la conversation entre le client et le serveur s’arrête au début et ils n'envoient plus rien.
Merci d'avance pour votre aide.
Exemple d'un des codes que j'ai fais
Merci d'avance pour votre aide.
Exemple d'un des codes que j'ai fais
C#:
class Program
{
static IPEndPoint ipEnd;
static Socket sock;
static void Main(string[] args)
{
ipEnd = new IPEndPoint(IPAddress.Loopback, 5555);
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sock.Bind(ipEnd);
Thread t = new Thread(new ThreadStart(ClientToServer));
t.Start();
}
static IPEndPoint ipEnddofus;
static Socket sockDofus;
static bool connected;
static Socket clientSock;
static void ClientToServer()
{
while (true)
{
if (connected != true)
{
Console.WriteLine("Waiting for client to connect");
sock.Listen(100);
}
clientSock = sock.Accept();
byte[] truncArray = new byte[1024 * 5000];
int bytelen = clientSock.Receive(truncArray);
byte[] clientData = new byte[bytelen];
Array.Copy(truncArray, clientData, clientData.Length);
if (connected != true)
{
Console.WriteLine("Client connected");
connected = true;
ipEnddofus = new IPEndPoint(System.Net.IPAddress.Parse("172.65.235.192"), 5555);
sockDofus = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sockDofus.Connect(ipEnddofus);
Console.WriteLine("Connected to server");
Thread s = new Thread(new ThreadStart(ServerToClient));
s.Start();
}
if (bytelen < 0)
{
sockDofus.Send(clientData);
Console.WriteLine("1");
}
}
}
static void ServerToClient()
{
while (true)
{
byte[] truncArray = new byte[1024 * 5000];
int bytelen = sockDofus.Receive(truncArray);
byte[] clientData = new byte[bytelen];
Array.Copy(truncArray, clientData, clientData.Length);
if (bytelen < 0)
{
StringBuilder hex = new StringBuilder(clientData.Length * 2);
foreach (byte b in clientData)
hex.AppendFormat("{0:x2}", b);
Console.WriteLine(hex);
clientSock.Send(clientData);
Console.WriteLine("2");
}
}
}
}
Pièces jointes
-
343.1 KB Affichages: 41