Example #1
0
        private void AgentLocalThread()
        {
            try
            {
                while (true)
                {
                    lock (exit_lock)
                    {
                        if (should_exit)
                        {
                            break;
                        }
                    }

                    if (ag_local_stream.DataAvailable)
                    {
                        ag_local_recv_buffer.Offset = 0;
                        ag_local_recv_buffer.Size   = ag_local_stream.Read(ag_local_recv_buffer.Buffer, 0, ag_local_recv_buffer.Buffer.Length);
                        ag_local_security.Recv(ag_local_recv_buffer);
                    }

                    ag_local_recv_packets = ag_local_security.TransferIncoming();
                    if (ag_local_recv_packets != null)
                    {
                        foreach (Packet packet in ag_local_recv_packets)
                        {
                            if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000 || packet.Opcode == 0x2001)
                            {
                                continue;
                            }

                            //Send -> Packet to AG
                            ag_remote_security.Send(packet);

                            //Process -> Packet
                            byte[] packet_bytes = packet.GetBytes();
                            Framework.Bot.Packet.Handling.handlePacket(packet.Opcode, packet_bytes);

                            //Log -> Packet
                            BotLog(3, packet, packet_bytes);
                        }
                    }

                    ag_local_send_buffers = ag_local_security.TransferOutgoing();
                    if (ag_local_send_buffers != null)
                    {
                        foreach (var kvp in ag_local_send_buffers)
                        {
                            Packet         packet = kvp.Value;
                            TransferBuffer buffer = kvp.Key;

                            //////////////////////////////////////////////////////////////////////////
                            //RECEIVED PACKET FROM AG
                            //////////////////////////////////////////////////////////////////////////

                            //Send -> Packet to Client
                            ag_local_stream.Write(buffer.Buffer, 0, buffer.Size);

                            //Process -> Packet
                            Framework.Bot.Packet.Handling.handlePacket(buffer.Buffer);

                            //Log -> Packet
                            BotLog(1, packet, buffer.Buffer);
                        }
                    }

                    Thread.Sleep(1);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("[AgentLocalThread] Exception: {0}", ex);
            }
        }
Example #2
0
        private void GatewayRemoteThread()
        {
            try
            {
                while (true)
                {
                    lock (exit_lock)
                    {
                        if (should_exit)
                        {
                            break;
                        }
                    }

                    if (gw_remote_stream.DataAvailable)
                    {
                        gw_remote_recv_buffer.Offset = 0;
                        gw_remote_recv_buffer.Size   = gw_remote_stream.Read(gw_remote_recv_buffer.Buffer, 0, gw_remote_recv_buffer.Buffer.Length);
                        gw_remote_security.Recv(gw_remote_recv_buffer);
                    }

                    gw_remote_recv_packets = gw_remote_security.TransferIncoming();
                    if (gw_remote_recv_packets != null)
                    {
                        foreach (Packet packet in gw_remote_recv_packets)
                        {
                            byte[] packet_bytes = packet.GetBytes();

                            if (packet.Opcode == 0x5000 || packet.Opcode == 0x9000)
                            {
                                continue;
                            }

                            if (packet.Opcode == 0xA102)
                            {
                                byte result = packet.ReadUInt8();
                                if (result == 1)
                                {
                                    uint   id   = packet.ReadUInt32();
                                    string ip   = packet.ReadAscii();
                                    ushort port = packet.ReadUInt16();

                                    xfer_remote_ip   = ip;
                                    xfer_remote_port = port;

                                    Packet new_packet = new Packet(0xA102, true);
                                    new_packet.WriteUInt8(result);
                                    new_packet.WriteUInt32(id);
                                    new_packet.WriteAscii(Global.ProxyGlobal.Proxy_IPAddress);
                                    new_packet.WriteUInt16(Global.ProxyGlobal.Proxy_Agent_Port);

                                    gw_local_security.Send(new_packet);

                                    continue;
                                }
                            }

                            gw_local_security.Send(packet);
                        }
                    }

                    gw_remote_send_buffers = gw_remote_security.TransferOutgoing();
                    if (gw_remote_send_buffers != null)
                    {
                        foreach (var kvp in gw_remote_send_buffers)
                        {
                            Packet         packet = kvp.Value;
                            TransferBuffer buffer = kvp.Key;

                            byte[] packet_bytes = packet.GetBytes();

                            gw_remote_stream.Write(buffer.Buffer, 0, buffer.Size);
                        }
                    }

                    Thread.Sleep(1);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("[GatewayRemoteThread] Exception: {0}", ex);
            }
        }