Ejemplo n.º 1
0
        private List <PacketSummary> HandleOutgoingData(string str)
        {
            List <PacketSummary> packets = new List <PacketSummary>();

            try
            {
                foreach (string packet in str.Split(new char[] { (char)1 }))
                {
                    if (packet.Length < 2)
                    {
                        continue;
                    }

                    String newPacket = packet.Replace("" + (char)1, "");

                    if (newPacket.StartsWith("@A") && frmMain.Form.chkDecodeEncryption.Checked)
                    {
                        String encodeKey = packet.Substring(2);
                        frmMain.Form.TcpForwarder._rc4Provider = new rc4Provider(encodeKey);
                    }

                    PacketSummary summary = new PacketSummary(packet.Substring(0, 2), (packet.Substring(0, 2).Length > 0 ? packet.Substring(2) : "") + (char)1);
                    packets.Add(summary);
                }
            }
            catch { }

            return(packets);
        }
Ejemplo n.º 2
0
        private List <PacketSummary> HandleIncomingData(string str)
        {
            List <PacketSummary> packets = new List <PacketSummary>();

            try
            {
                int amountRead = 0;

                while (amountRead < str.Length)
                {
                    int recieveLength = Base64Encoding.DecodeInt32(str.Substring(amountRead, 3));
                    amountRead += 3;

                    string packet = str.Substring(amountRead, recieveLength);

                    PacketSummary summary = new PacketSummary(packet.Substring(0, 2), (packet.Substring(0, 2).Length > 0 ? packet.Substring(2) : ""));
                    packets.Add(summary);

                    amountRead += recieveLength;
                }
            }
            catch { }

            return(packets);
        }
Ejemplo n.º 3
0
        private string BuildPacket(PacketSummary packet, string packetData, bool incoming)
        {
            string response;

            if (this._incoming)
            {
                response = packet.Header + packetData;
                response = "@" + Base64Encoding.EncodeInt32(response.Length, 2) + response;
            }
            else
            {
                response = packet.Header + packetData;
            }

            return(response);
        }
        public void LoadPcapFile(PcapFile file)
        {
            var stopwatch       = Stopwatch.StartNew();
            int packetCount     = 0;
            var errors          = new List <Exception>();
            var packetSummaries = new List <PacketSummary>();

            PcapParser.Parse(file.FilePath, p =>
            {
                try
                {
                    // insert packet summaries in batches
                    if (packetSummaries.Count >= 50000)
                    {
                        this.packetSummaryRepository.Create(packetSummaries);
                        packetCount += packetSummaries.Count;
                        packetSummaries.Clear();
                    }

                    Console.Write($"\rPackets: {packetCount}\tElapsed Time: {(int)(stopwatch.ElapsedMilliseconds / 1000)} (s)");

                    packetSummaries.Add(PacketSummary.Parse(p).ForFile(file.Id));
                }
                catch (Exception e)
                {
                    errors.Add(e);
                }
            });

            this.packetSummaryRepository.Create(packetSummaries);
            packetCount += packetSummaries.Count;
            packetSummaries.Clear();
            Console.Write($"\rPackets: {packetCount}/{packetCount + errors.Count}\tElapsed Time: {(int)(stopwatch.ElapsedMilliseconds / 1000)} (s)");
            Console.WriteLine(Environment.NewLine);

            stopwatch.Stop();
            //errors.ForEach(e => this.userInterface.Error(e.ToString()));
        }
Ejemplo n.º 5
0
        private void ShowDialogueSend(PacketSummary packet, bool incoming)
        {
            string packetData = Microsoft.VisualBasic.Interaction.InputBox((incoming ? "Incoming" : "Outgoing") + " packet received",
                                                                           "Please edit it if you wish before sending",
                                                                           frmSend.AddReadableCharacters(packet.Data),
                                                                           0,
                                                                           0);

            packetData = frmSend.AddUnreadableCharacters(packetData);

            byte[] processSend = Encoding.Default.GetBytes(BuildPacket(packet, packetData, incoming));

            if (this._incoming)
            {
                // Send to server
                frmMain.Form.TcpForwarder.DestinationState.DestinationSocket.Send(processSend, processSend.Length, SocketFlags.None);
            }
            else
            {
                // Send to client
                frmMain.Form.TcpForwarder.DestinationState.SourceSocket.Send(processSend, processSend.Length, SocketFlags.None);
            }
        }