public static void ProxyToDrain() //Proxy-Client will connect to the remote Server { Console.WriteLine("Trying to connect to Drain [Server] ..."); ProxyToDrainBuffer = new byte[BufferSize]; //Create 'read' Buffer try { DrainClient.Connect(DrainHost); Console.WriteLine("Successfully connected to Drain [Server]"); StopWatch = new Stopwatch(); StopWatch.Start(); if (InjectMode) { Thread InjectPacketThread = new Thread(InjectPacket); InjectPacketThread.Start(); } while (true) { ProxyToDrainBuffer = new byte[BufferSize]; //Clear 'read' Buffer int lenght = DrainClient.Receive(ProxyToDrainBuffer, ProxyToDrainBuffer.Length, 0); //Read Data from Server BytesDownloadedServer += lenght; if (!InjectMode) { if (PwnAdventure3) { PacketParser.CheckForServersData(DeleteZeroTrail(ProxyToDrainBuffer), lenght); } else { Console.WriteLine("[Server -> Client] " + PacketParser.ByteToHex(DeleteZeroTrail(ProxyToDrainBuffer))); } } if (!Allowed_SendToClient) { Allowed_SendToClient = true; continue; } SourceHandler.Send(ProxyToDrainBuffer, lenght, SocketFlags.None); //Forward the read Data to Client } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("### Connection Problems with Server ### " + e); Console.ResetColor(); } }
/***************************************************************/ public static void SourceToProxy() //Local Proxy Server waiting for connection, the real Client will be connected here { SourceToProxyBuffer = new byte[BufferSize]; //Create 'read' Buffer try { SourceListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); SourceListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); SourceListener.Bind(SourceHost); SourceListener.Listen(1); Console.WriteLine("Waiting for Source [Client] ... \n"); Thread AnimationThread = new Thread(DisplayAnimation); //If Client has connected to Proxy -> start connection to the remote Server AnimationThread.Start(); SourceHandler = SourceListener.Accept(); AnimationThread.Abort(); Console.WriteLine(""); Console.WriteLine("Source [Client] has connected! \n"); Thread ProxyToDrainThread = new Thread(ProxyToDrain); //If Client has connected to Proxy -> start connection to the remote Server ProxyToDrainThread.Start(); while (true) { SourceToProxyBuffer = new byte[BufferSize]; //Clear 'read' Buffer int lenght = SourceHandler.Receive(SourceToProxyBuffer, SourceToProxyBuffer.Length, 0); //Read Data from Client BytesDownloadedClient += lenght; while (!DrainClient.Connected) //Don't do anything if Proxy hasn't connected to the remote Server { } if (!InjectMode) { if (PwnAdventure3) { PacketParser.CheckForClientsData(DeleteZeroTrail(SourceToProxyBuffer), lenght); } else { Console.WriteLine("[Client -> Server] " + PacketParser.ByteToHex(DeleteZeroTrail(SourceToProxyBuffer))); } } if (!Allowed_SendToServer) { Allowed_SendToServer = true; continue; } DrainClient.Send(SourceToProxyBuffer, lenght, SocketFlags.None); //Forward the read Data to Server } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("### Connection Problems with Client ### " + e); Console.ResetColor(); } }