Пример #1
0
        void Inject(NetworkSniffer sniffer, TcpStream stream, Packet[] packets)
        {
            WriteInfo("Injecting packets");

            foreach (EthernetPacket p in packets)
            {
                // Override ethernet
                p.DestinationHwAddress = stream.DestinationHwAddress;
                p.SourceHwAddress      = stream.SourceHwAddress;
                p.UpdateCalculatedValues();

                IpPacket ip = (IpPacket)p.PayloadPacket;
                ip.SourceAddress      = stream.Source.Address;
                ip.DestinationAddress = stream.Destination.Address;
                ip.UpdateCalculatedValues();

                if (ip.Protocol != IPProtocolType.TCP)
                {
                    continue;
                }

                TcpPacket tcp = (TcpPacket)ip.PayloadPacket;
                tcp.SourcePort      = (ushort)stream.Source.Port;
                tcp.DestinationPort = (ushort)stream.Destination.Port;
                tcp.UpdateCalculatedValues();

                // Send
                sniffer.Send(p);
            }
        }