예제 #1
0
        public void BinarySerialization()
        {
            var dev = new CaptureFileReaderDevice("../../CaptureFiles/ipv6_icmpv6_packet.pcap");

            dev.Open();

            RawCapture rawCapture;
            bool       foundipv6 = false;

            while ((rawCapture = dev.GetNextPacket()) != null)
            {
                Packet p    = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data);
                var    ipv6 = (IPv6Packet)p.Extract(typeof(IPv6Packet));
                if (ipv6 == null)
                {
                    continue;
                }
                foundipv6 = true;

                var             memoryStream = new MemoryStream();
                BinaryFormatter serializer   = new BinaryFormatter();
                serializer.Serialize(memoryStream, ipv6);

                memoryStream.Seek(0, SeekOrigin.Begin);
                BinaryFormatter deserializer = new BinaryFormatter();
                IPv6Packet      fromFile     = (IPv6Packet)deserializer.Deserialize(memoryStream);

                Assert.AreEqual(ipv6.Bytes, fromFile.Bytes);
                Assert.AreEqual(ipv6.BytesHighPerformance.Bytes, fromFile.BytesHighPerformance.Bytes);
                Assert.AreEqual(ipv6.BytesHighPerformance.BytesLength, fromFile.BytesHighPerformance.BytesLength);
                Assert.AreEqual(ipv6.BytesHighPerformance.Length, fromFile.BytesHighPerformance.Length);
                Assert.AreEqual(ipv6.BytesHighPerformance.NeedsCopyForActualBytes, fromFile.BytesHighPerformance.NeedsCopyForActualBytes);
                Assert.AreEqual(ipv6.BytesHighPerformance.Offset, fromFile.BytesHighPerformance.Offset);
                Assert.AreEqual(ipv6.Color, fromFile.Color);
                Assert.AreEqual(ipv6.Header, fromFile.Header);
                Assert.AreEqual(ipv6.PayloadData, fromFile.PayloadData);
                Assert.AreEqual(ipv6.DestinationAddress, fromFile.DestinationAddress);
                Assert.AreEqual(ipv6.HeaderLength, fromFile.HeaderLength);
                Assert.AreEqual(ipv6.HopLimit, fromFile.HopLimit);
                Assert.AreEqual(ipv6.NextHeader, fromFile.NextHeader);
                Assert.AreEqual(ipv6.PayloadLength, fromFile.PayloadLength);
                Assert.AreEqual(ipv6.Protocol, fromFile.Protocol);
                Assert.AreEqual(ipv6.SourceAddress, fromFile.SourceAddress);
                Assert.AreEqual(ipv6.TimeToLive, fromFile.TimeToLive);
                Assert.AreEqual(ipv6.TotalLength, fromFile.TotalLength);
                Assert.AreEqual(ipv6.Version, fromFile.Version);
                Assert.AreEqual(ipv6.FlowLabel, fromFile.FlowLabel);
                Assert.AreEqual(ipv6.TrafficClass, fromFile.TrafficClass);

                //Method Invocations to make sure that a deserialized packet does not cause
                //additional errors.

                ipv6.PrintHex();
                ipv6.UpdateCalculatedValues();
            }

            dev.Close();
            Assert.IsTrue(foundipv6, "Capture file contained no ipv6 packets");
        }
예제 #2
0
        private void Attack()
        {
            while (true)
            {
                try
                {
                    /* INICIAR EL ATAQUE MODIFICANDO LA CACHE ARP (DoS IPv4) Y LAS TABLAS DE VECINOS (IPv6 SLAAC) */
                    foreach (Data.Attack attack in attacks.Where(A => A.attackType == Data.AttackType.SlaacMitm && A.attackStatus == Data.AttackStatus.Attacking))
                    {
                        if (attack is evilfoca.Data.MitmAttack)
                        {
                            evilfoca.Data.MitmAttack slaacMitm = (evilfoca.Data.MitmAttack)attack;
                            EthernetPacket           ethernet;

                            {
                                IPAddress       myIP  = Program.CurrentProject.data.GetIPv6LocalLinkFromDevice(Program.CurrentProject.data.GetDevice());
                                PhysicalAddress myMac = Program.CurrentProject.data.GetDevice().MacAddress;

                                // IPv6 (de vinculo local) y MAC atacada
                                IPAddress       IPdst  = slaacMitm.t2.ip;
                                PhysicalAddress MACdst = slaacMitm.t2.mac;

                                ICMPv6Packet routerAdvertisement = new ICMPv6Packet(new ByteArraySegment(new ICMPv6.NeighborRouterAdvertisement(myMac, slaacMitm.prefix, false).GetBytes()));
                                IPv6Packet   ipv6 = new IPv6Packet(myIP, IPdst);
                                ipv6.PayloadPacket = routerAdvertisement;
                                ipv6.HopLimit      = 255;

                                ethernet = new EthernetPacket(myMac, MACdst, EthernetPacketType.IpV6);
                                ethernet.PayloadPacket = ipv6;
                                Program.CurrentProject.data.SendPacket(ethernet);
                            }
                        }
                    }

                    /* PARAR ATAQUE Y RESTAURAR LA CACHE DNS Y TABLAS DE VECINOS */
                    foreach (Data.Attack attack in attacks.Where(A => A.attackType == Data.AttackType.SlaacMitm && A.attackStatus == Data.AttackStatus.Stopping))
                    {
                        if (attack is evilfoca.Data.MitmAttack)
                        {
                            evilfoca.Data.MitmAttack slaacMitm = (evilfoca.Data.MitmAttack)attack;

                            /* Enviar paquetes para que pare la denegacion de servicio IPv4 */

                            /* Enviar paquetes para que pare el envenenamiento de vecino IPv6 */

                            attack.attackStatus = Data.AttackStatus.Stop;
                        }
                    }


                    Thread.Sleep(SendPacketEachXSecs * 1000);
                }
                catch
                {
                }
            }
        }
예제 #3
0
        public void ConstructFromValues()
        {
            var sourceAddress      = RandomUtils.GetIPAddress(IPVersion.IPv6);
            var destinationAddress = RandomUtils.GetIPAddress(IPVersion.IPv6);
            var ipPacket           = new IPv6Packet(sourceAddress, destinationAddress);

            Assert.AreEqual(sourceAddress, ipPacket.SourceAddress);
            Assert.AreEqual(destinationAddress, ipPacket.DestinationAddress);
        }
예제 #4
0
        public static void PacketHandler(IPv6Packet ipv6Packet)
        {
            Icmpv6Packet icmpv6Handler = (Icmpv6Packet)ipv6Packet.Payload;

            if (icmpv6Handler.Icmpv6MessageType == Icmpv6MessageType.EchoRequest)
            {
                IPv6Packet packetEchoReply = new IPv6Packet();
                packetEchoReply.SourceAddress      = ipv6Packet.DestinationAddress;
                packetEchoReply.DestinationAddress = ipv6Packet.SourceAddress;
                packetEchoReply.NextHeader         = ipv6Packet.NextHeader;
                packetEchoReply.Flow          = ipv6Packet.Flow;
                packetEchoReply.HopLimit      = ipv6Packet.HopLimit;
                packetEchoReply.PayloadLength = ipv6Packet.PayloadLength;
                packetEchoReply.TrafficClass  = ipv6Packet.TrafficClass;
                packetEchoReply.Version       = ipv6Packet.Version;


                icmpv6Handler.Icmpv6MessageType = Icmpv6MessageType.EchoReply;
                Icmpv6EchoReply icmpv6EchoReply = new Icmpv6EchoReply((Icmpv6EchoRequest)icmpv6Handler.IcmpMessage);
                icmpv6Handler.IcmpMessage = icmpv6EchoReply;

                IPv6PseudoHeader ipv6PseudoHeader = new IPv6PseudoHeader(packetEchoReply.SourceAddress, packetEchoReply.DestinationAddress, packetEchoReply.PayloadLength, (byte)packetEchoReply.NextHeader);
                ushort           checkSum         = ipv6PseudoHeader.GetCheckSum();

                byte[] icmpData = icmpv6Handler.ToBytes();
                icmpData[2] = 0;
                icmpData[3] = 0;

                checkSum = NetUtilities.ComputeChecksum(checkSum, icmpData, true);

                icmpv6Handler.Checksum = checkSum;

                packetEchoReply.Payload = icmpv6Handler;

                NetworkInterface.Send(packetEchoReply.ToBytes());
            }
            else if (icmpv6Handler.Icmpv6MessageType == Icmpv6MessageType.EchoReply)
            {
                if (isResponseTimeout)
                {
                    return;
                }

                TimeSpan elapsed = DateTime.UtcNow - pingStart;

                replyTime = (short)elapsed.TotalMilliseconds;

//#if NETMF
//                replyTime = (short)elapsed.Milliseconds;
//#else
//                replyTime = (short)elapsed.TotalMilliseconds;
//#endif

                pingTimeout.Set();
            }
        }
예제 #5
0
        public static short SendEchoRequest(IPAddress destionationIPAddress)
        {
            IPv6PseudoHeader pv6PseudoHeader = new IPv6PseudoHeader(NetworkInterface.IPAddress, destionationIPAddress, 0x10, 58);
            ushort           checkSum        = pv6PseudoHeader.GetCheckSum();

            byte[] packet = new byte[16];
            packet[0] = 0x80;
            packet[1] = 0x00;
            packet[2] = 0x00; //Checksum
            packet[3] = 0x00; //Checksum

            packet[4] = 0x00;
            packet[5] = 0x01;
            packet[6] = 0x00;
            packet[7] = 0x0a;

            packet[8]  = 0x02;
            packet[9]  = 0xcd;
            packet[10] = 0x21;
            packet[11] = 0xf2;
            packet[12] = 0x00;
            packet[13] = 0x00;
            packet[14] = 0x00;
            packet[15] = 0x00;

            checkSum = NetUtilities.ComputeChecksum(checkSum, packet, true);

            Icmpv6Packet icmpv6Packet = new Icmpv6Packet();
            int          packetIndex  = 0;

            icmpv6Packet.FromBytes(packet, ref packetIndex);
            icmpv6Packet.Checksum = checkSum;

            IPv6Packet packetEchoRequest = new IPv6Packet();

            packetEchoRequest.DestinationAddress = destionationIPAddress;
            packetEchoRequest.SourceAddress      = NetworkInterface.IPAddress;
            packetEchoRequest.PayloadLength      = 0x10;
            packetEchoRequest.NextHeader         = IPv6Protocol.ICMPv6;
            packetEchoRequest.Payload            = icmpv6Packet;

            pingStart         = DateTime.UtcNow;
            isResponseTimeout = false;

            replyTime = -1;

            NetworkInterface.SendAndWait(packetEchoRequest.ToBytes());
            pingTimeout.WaitOne(5000, false);

            if (replyTime == -1)
            {
                isResponseTimeout = true;
            }

            return(replyTime);
        }
예제 #6
0
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[60]
            };

            ipv6Packet.SetByte(0, 0x65);

            ipv6Packet.Version.Should().Be(IPVersion.IPv6);
        }
        public void Set()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[60]
            };

            ipv6Packet.PayloadLength = 16;

            ipv6Packet.PayloadLength.Should().Be(16);
        }
        public void Set()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.HopLimit = 255;

            ipv6Packet.HopLimit.Should().Be(255);
        }
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.SetByte(7, 0xff);

            ipv6Packet.HopLimit.Should().Be(255);
        }
        public void Set()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.NextHeader = 0;

            ipv6Packet.NextHeader.Should().Be(0);
        }
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.SetByte(6, 0x00);

            ipv6Packet.NextHeader.Should().Be(0);
        }
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[60]
            };

            ipv6Packet.SetBytes(4, 2, new Byte[] { 0x00, 0x10 });

            ipv6Packet.PayloadLength.Should().Be(16);
        }
        public void Set()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.TrafficClass = 0b_0101_1010;

            ipv6Packet.GetByte(0).Should().Be(0b_0101);
            ipv6Packet.GetByte(1).Should().Be(0b_1010_0000);
        }
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.SetByte(0, 0b_0000_1010);
            ipv6Packet.SetByte(1, 0b_0101_0000);

            ipv6Packet.TrafficClass.Should().Be(0b_1010_0101);
        }
예제 #15
0
        /// <summary>
        /// Updates traffic statistics according to the received packet characteristics
        /// </summary>
        /// <param name="newPacket">Received packet depending on which statistics are updated</param>
        public static void UpdateStats(IPv6Packet newPacket)
        {
            //int newPacketLength = newPacket.IPv6Header[0].TotalLength;
            int newPacketLength = newPacket.IPv6Header[0].PayloadLength;

            //string newPacketProtocol = newPacket.IPv6Header[0].TransportProtocolName; // não tem essa, teria que checar o Next Header

            PacketsTotal++;
            BytesTotal += newPacket.IPv6Header[0].PayloadLength;

            SortPacketByLength(newPacketLength);
            //SortPacketByProtocol(newPacketProtocol);
        }
예제 #16
0
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet[8, 16] = new Byte[]
            {
                0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x15, 0x5d, 0xff, 0xfe, 0x02, 0x02, 0x45
            };

            ipv6Packet.SourceIPAddress.ToString().Should().Be("FE:80:00:00:00:00:00:00:02:15:5D:FF:FE:02:02:45");
        }
예제 #17
0
        public void Set(Byte input)
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.SetByte(0, 0x05);

            ipv6Packet.Version = (IPVersion)input;

            ipv6Packet.GetByte(0).Should().Be(0x65);
            ipv6Packet.Version.Should().Be(IPVersion.IPv6);
        }
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.SetByte(0, 0b_1111_1111);
            ipv6Packet.SetByte(1, 0b_1111_1010);
            ipv6Packet.SetByte(2, 0b_1010_1010);
            ipv6Packet.SetByte(3, 0b_0101_0101);

            ipv6Packet.FlowLabel.Should().Be(0b_1010_1010_1010_0101_0101);
        }
        public void Set()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet.FlowLabel = 0b_1010_1010_1010_0101_0101;

            ipv6Packet.GetByte(0).Should().Be(0);
            ipv6Packet.GetByte(1).Should().Be(0b_1010);
            ipv6Packet.GetByte(2).Should().Be(0b_1010_1010);
            ipv6Packet.GetByte(3).Should().Be(0b_0101_0101);
        }
        public void Get()
        {
            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[40]
            };

            ipv6Packet[24, 16] = new Byte[]
            {
                0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
            };

            ipv6Packet.DestinationIPAddress.ToString().Should().Be("FF:02:00:00:00:00:00:00:00:00:00:00:00:00:00:02");
        }
예제 #21
0
        // IP 协议

        private void Ip(IpPacket ip)
        {
            if (ip.Version == IpVersion.IPv4)
            {
                IPv4Packet ipv4 = ip as IPv4Packet;
                IPv4(ipv4);
            }
            else
            {
                IPv6Packet ipv6 = ip as IPv6Packet;
                IPv6(ipv6);
            }
            ipNext(ip);
        }
예제 #22
0
        private void ipNext(IpPacket ip)
        {
            PayLoadData = ip.PayloadData;
            switch (ip.NextHeader)
            {
            case IPProtocolType.TCP:    //最终协议为TCP
                TcpPacket tcp = TcpPacket.GetEncapsulated(packet);
                TCP(tcp);
                break;

            case IPProtocolType.UDP:
                UdpPacket udp = UdpPacket.GetEncapsulated(packet);
                UDP(udp);
                break;

            case IPProtocolType.ICMP:
                ICMPv4Packet icmp = ICMPv4Packet.GetEncapsulated(packet);
                ICMPv4(icmp);
                break;

            case IPProtocolType.ICMPV6:
                ICMPv6Packet icmpv6 = ICMPv6Packet.GetEncapsulated(packet);
                ICMPv6(icmpv6);
                break;

            case IPProtocolType.IGMP:
                IGMPv2Packet igmp = IGMPv2Packet.GetEncapsulated(packet);
                IGMP(igmp);
                break;

            case IPProtocolType.IPV6:
                List <byte> packetData = new List <byte>();
                byte[]      tmp        = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                packetData.AddRange(tmp);
                packetData.AddRange(new byte[] { 0x86, 0xdd });
                packetData.AddRange(ip.PayloadData);
                Packet     p   = Packet.ParsePacket(LinkLayers.Ethernet, packetData.ToArray());
                IPv6Packet ip6 = (IPv6Packet)IPv6Packet.GetEncapsulated(p);
                IPv6(ip6);
                packet = p;
                ipNext(ip6 as IpPacket);
                break;

            case IPProtocolType.GRE:
                GREPacket gre = new GREPacket(ip.PayloadData);
                GRE(gre);
                break;
            }
        }
예제 #23
0
        /// <summary>
        /// Adds newly received packet to packet lists
        /// </summary>
        /// <param name="newPacket">Packet to be added to packet lists</param>
        private void ReceiveNewPacket(IPv6Packet newPacket)
        {
            newPacket.PacketID = (uint)PacketList.Count + 1;

            lock (PacketList)
            {
                PacketList.Add(newPacket);
            }
            IsClearEnabled = true;

            lock (filteredPacketList)
            {
                AddToFilteredList(newPacket);
            }

            StatsHandler.UpdateStats(newPacket);
        }
예제 #24
0
        public void SendMLDQuery()
        {
            EthernetPacket ePacket  = new EthernetPacket(PhysicalAddress.Parse("98-5F-D3-3F-6D-B1"), PhysicalAddress.Parse("33-33-00-00-00-01"), EthernetPacketType.IpV6);
            IPv6Packet     ipPacket = new IPv6Packet(IPAddress.Parse("fe80::d0d6:8c11:a087:3941"), IPAddress.Parse("ff02::1"));

            ePacket.PayloadPacket = ipPacket;
            ICMPv6Packet icmp = new ICMPv6Packet(new PacketDotNet.Utils.ByteArraySegment(new byte[24]));

            Array.Copy(IPAddress.Parse("ff02::1").GetAddressBytes(), 0, icmp.Header, 8, 16);
            icmp.Type              = ICMPv6Types.MulticastLostenerQuery;
            icmp.Code              = 0;
            icmp.Checksum          = 0;
            ipPacket.PayloadPacket = icmp;
            icmp.UpdateCalculatedValues();

            _ncard.SendPacket(ePacket);
        }
예제 #25
0
        public void GenerateLLMNRResponse(Packet packet)
        {
            try
            {
                LLMNR.LLMNRPacket llmnr = new LLMNR.LLMNRPacket();
                llmnr.ParsePacket(((UdpPacket)(packet.PayloadPacket.PayloadPacket)).PayloadData);
                if (llmnr.Query.Name.ToLower().Equals("wpad") && (llmnr.Query.Type.Value == LLMNR.DNSType.AAAA || llmnr.Query.Type.Value == LLMNR.DNSType.A))
                {
                    WinPcapDevice dev      = Program.CurrentProject.data.GetDevice();
                    IPAddress     ip       = Program.CurrentProject.data.GetIPv6LocalLinkFromDevice(dev);
                    byte[]        ipv6Addr = ip.GetAddressBytes();

                    llmnr.AnswerList.Add(new LLMNR.DNSAnswer()
                    {
                        Class    = evilfoca.LLMNR.DNSClass.IN,
                        Name     = llmnr.Query.Name,
                        Type     = evilfoca.LLMNR.DNSType.AAAA,
                        RData    = ipv6Addr,
                        RDLength = (short)ipv6Addr.Length,
                        TTL      = 12
                    });
                    llmnr.IsResponse = true;


                    EthernetPacket ethDns  = new EthernetPacket(dev.MacAddress, ((EthernetPacket)packet).SourceHwAddress, EthernetPacketType.IpV6);
                    IPv6Packet     ipv6Dns = new IPv6Packet(ip, ((IPv6Packet)((EthernetPacket)packet).PayloadPacket).SourceAddress);
                    UdpPacket      udpDns  = new UdpPacket(((UdpPacket)(packet.PayloadPacket.PayloadPacket)).DestinationPort, ((UdpPacket)(packet.PayloadPacket.PayloadPacket)).SourcePort);

                    udpDns.PayloadData = llmnr.BuildPacket();

                    ipv6Dns.PayloadPacket = udpDns;


                    udpDns.UpdateCalculatedValues();
                    udpDns.UpdateUDPChecksum();

                    ipv6Dns.UpdateCalculatedValues();
                    ethDns.PayloadPacket = ipv6Dns;
                    Program.CurrentProject.data.SendPacket(ethDns);
                }
            }
            catch (Exception)
            {
            }
        }
예제 #26
0
        private void IPv6(IPv6Packet v6)
        {
            if (IPv6Node == null)
            {
                IPv6Node = new TreeNode();
            }

            IPv6Node.Nodes.Clear();
            IPv6Node.Text = string.Format("Internet Protocol Version 6, Src: {0}, Dst: {1}",
                                          v6.SourceAddress, v6.DestinationAddress);
            IPv6Node.Nodes.Add(string.Format("Version: {0}", v6.Version));
            IPv6Node.Nodes.Add(string.Format("Payload length: {0}", v6.PayloadLength));
            IPv6Node.Nodes.Add(string.Format("Next header: {0}", v6.NextHeader));
            IPv6Node.Nodes.Add(string.Format("Hot limit: {0}", v6.HopLimit));
            IPv6Node.Nodes.Add(string.Format("Source: {0}", v6.SourceAddress));
            IPv6Node.Nodes.Add(string.Format("Destination: {0}", v6.DestinationAddress));

            tree.Nodes.Add(IPv6Node);
        }
예제 #27
0
        private void Attack()
        {
            while (true)
            {
                try
                {
                    foreach (Data.Attack attack in attacks.Where(A => A.attackType == Data.AttackType.DoSSLAAC && A.attackStatus == Data.AttackStatus.Attacking))
                    {
                        if (attack is evilfoca.Data.DoSSLAACAttack)
                        {
                            for (int i = 0; i < NumberOfRouterAdvertisement; i++)
                            {
                                //MAC del equipo atacado
                                PhysicalAddress MACdst = (attack as evilfoca.Data.DoSSLAACAttack).t1.mac;

                                //IP de origen aleatoria pero siempre de vinculo local
                                IPAddress IPsrc = GetRandomLocalIPv6();
                                //IP atacada
                                IPAddress IPdst = (attack as evilfoca.Data.DoSSLAACAttack).t1.ip;

                                ICMPv6Packet routerAdvertisement = new ICMPv6Packet(new ByteArraySegment(new ICMPv6.NeighborRouterAdvertisement(MACsrc, GetRandomPrefix(), true).GetBytes()));
                                IPv6Packet   ipv6 = new IPv6Packet(IPsrc, IPdst);
                                ipv6.PayloadPacket = routerAdvertisement;
                                ipv6.HopLimit      = 255;
                                EthernetPacket ethernet = new EthernetPacket(MACsrc, MACdst, EthernetPacketType.IpV6);
                                ethernet.PayloadPacket = ipv6;
                                Program.CurrentProject.data.SendPacket(ethernet);
                            }
                        }
                    }


                    Thread.Sleep(SendDoSAttackEachXSecs * 1000);
                }
                catch (ThreadAbortException)
                {
                    return;
                }
                catch
                {
                }
            }
        }
예제 #28
0
        public Packet GetSendPacket(PhysicalAddress sourceMAC, IPAddress sourceIPAddress)
        {
            // EthernetPacket ePacket = new EthernetPacket(PhysicalAddress.Parse("00-E0-4C-68-02-91"), PhysicalAddress.Parse("33-33-00-01-00-02"), EthernetPacketType.IpV6);
            // IPv6Packet ipPacket = new IPv6Packet(IPAddress.Parse("fe80::1c66:e750:c259:df88"), IPAddress.Parse("ff02::1:2"));

            EthernetPacket ePacket  = new EthernetPacket(sourceMAC, PhysicalAddress.Parse("33-33-00-01-00-02"), EthernetPacketType.IpV6);
            IPv6Packet     ipPacket = new IPv6Packet(sourceIPAddress, IPAddress.Parse("ff02::1:2"));

            ePacket.PayloadPacket = ipPacket;

            UdpPacket udpPacket = new UdpPacket(SOURCE_PORT, DEST_PORT);

            udpPacket.PayloadData = AddOtherOptions(DhcpV6MessagePacket).Encode().getAllBytes();
            udpPacket.UpdateCalculatedValues();

            ipPacket.PayloadPacket = udpPacket;
            udpPacket.UpdateUDPChecksum();
            Console.WriteLine("Send Type({0}) transactionID:{1:X} ", DhcpV6MessagePacket.GetMessageType().ToString(), DhcpV6MessagePacket.GetTransactionId());
            return(ePacket);
        }
예제 #29
0
        public void Display_IPv6Packet()
        {
            var(displayer, mock) = BuildTextDisplayer();

            var ipv6Packet = new IPv6Packet
            {
                Bytes = new Byte[]
                {
                    0x61, 0x2d, 0xf6, 0x06,
                    0x00, 0x10,
                    0x3a,
                    0xff,
                    0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x15, 0x5d, 0xff, 0xfe, 0x02, 0x02, 0x45,
                    0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
                    0x85, 0x00, 0xbc, 0x75, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x15, 0x5d, 0x02, 0x02, 0x45
                }
            };

            displayer.Display(ipv6Packet);

            mock.Verify(_ => _.WriteLine("ipv6     : FE:80:00:00:00:00:00:00:02:15:5D:FF:FE:02:02:45 > FF:02:00:00:00:00:00:00:00:00:00:00:00:00:00:02"), Times.Once);
        }
예제 #30
0
        private void IPv6(IPv6Packet v6)
        {
            if (IPv6Node == null)
            {
                IPv6Node                    = new TreeNode("IPv6");
                IPv6Node.ImageIndex         = 0;
                IPv6Node.SelectedImageIndex = 0;
                IPv6Node.Name               = "IPv6";
            }
            IPv6Node.Nodes.Clear();

            string ipver = Convert.ToString((int)v6.Version, 2).PadLeft(4, '0');

            IPv6Node.Nodes.Add("Version:       " + ipver + " .... .... .... .... .... .... .... = " + v6.Version);
            #region Traffic Class
            string traffStr = Convert.ToString(v6.TrafficClass, 2).PadLeft(8, '0').Insert(4, " ");
            if (trafficNode == null)
            {
                trafficNode = new TreeNode();
            }
            trafficNode.Nodes.Clear();
            trafficNode.Text = "Traffic Class: .... " + traffStr + " .... .... .... .... .... = 0x" + v6.TrafficClass.ToString("X").PadLeft(8, '0');
            trafficNode.Nodes.Add("            .... " + traffStr.Substring(0, 7) + ".. .... .... .... .... .... = [" + (v6.TrafficClass >> 2) + "]Differentiated Services Field");
            trafficNode.Nodes.Add("            .... .... .." + traffStr[7] + ". .... .... .... .... .... = [" + traffStr[7] + "]ECT ECN-Capable Transport");
            trafficNode.Nodes.Add("            .... .... ..." + traffStr[8] + " .... .... .... .... .... = [" + traffStr[8] + "]ECN-CE");
            #endregion

            IPv6Node.Nodes.Add(trafficNode);

            string flowLableStr = Convert.ToString(v6.FlowLabel, 2).PadLeft(20, '0').Insert(16, " ").Insert(12, " ").Insert(8, " ").Insert(4, " ");
            IPv6Node.Nodes.Add("Flow Label:    .... .... .... " + flowLableStr + " = 0x" + v6.FlowLabel.ToString("X").PadLeft(8, '0'));
            IPv6Node.Nodes.Add("Payload Length: " + v6.PayloadLength.ToString());
            IPv6Node.Nodes.Add("Next Header: " + v6.NextHeader.ToString() + " (0x" + v6.NextHeader.ToString("d") + ")");
            IPv6Node.Nodes.Add("Hop Limit: " + v6.HopLimit.ToString());
            IPv6Node.Nodes.Add("Source: " + v6.SourceAddress.ToString());
            IPv6Node.Nodes.Add("Destination: " + v6.DestinationAddress.ToString());
            Tree.Nodes.Add(IPv6Node);
        }
예제 #31
0
    public static Packet CreatePacket(Param param)
    {
        Packet ret = null;

        //create layer 4
        if (param.packetType == Param.PacketType.TCP)
        {
            TcpPacket tcpPacket = new TcpPacket(param.sPort, param.dPort);
            tcpPacket.AllFlags = param.tcpFlag;
            if (param.dIP.ToString().Contains("."))
            {
                IPv4Packet ipPacket = new IPv4Packet(param.sIP, param.dIP);
                if (param.IPv4Frag) { ipPacket.FragmentFlags = (int)1; }
                ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV4);
                ipPacket.PayloadPacket = tcpPacket;
                tcpPacket.PayloadData = param.payload;
                ret.PayloadPacket = ipPacket;
                ipPacket.UpdateCalculatedValues();
                ipPacket.UpdateIPChecksum();
                tcpPacket.Checksum = (ushort)tcpPacket.CalculateTCPChecksum();
            }
            else
            {
                IPv6Packet ipPacket = new IPv6Packet(param.sIP, param.dIP);
                ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV6);
                ipPacket.PayloadPacket = tcpPacket;
                tcpPacket.PayloadData = param.payload;
                ret.PayloadPacket = ipPacket;
            }

        }
        else if (param.packetType == Param.PacketType.UDP)
        {
            UdpPacket udpPacket = new UdpPacket(param.sPort, param.dPort);
            if (param.dIP.ToString().Contains("."))
            {
                IPv4Packet ipPacket = new IPv4Packet(param.sIP, param.dIP);
                if (param.IPv4Frag) { ipPacket.FragmentFlags = (int)1; }
                ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV4);
                ipPacket.PayloadPacket = udpPacket;
                udpPacket.PayloadData = param.payload;
                udpPacket.UpdateUDPChecksum();
                ipPacket.PayloadLength = (ushort)(ipPacket.PayloadLength + param.payload.Length);
                ipPacket.UpdateIPChecksum();
                ret.PayloadPacket = ipPacket;
            }
            else
            {
                IPv6Packet ipPacket = new IPv6Packet(param.sIP, param.dIP);
                ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV6);
                ipPacket.PayloadPacket = udpPacket;
                udpPacket.PayloadData = param.payload;
                udpPacket.UpdateUDPChecksum();
                ipPacket.PayloadLength = (ushort)(ipPacket.PayloadLength + param.payload.Length);
                ret.PayloadPacket = ipPacket;
            }
        }
        else if (param.packetType == Param.PacketType.ICMP)
        {
            ICMPv4Packet icmpPacket = new ICMPv4Packet(new ByteArraySegment(new byte[32]));
            if (param.type != 0 && param.code != 0)
            {
                icmpPacket.TypeCode = (ICMPv4TypeCodes)((param.type * 256) + (param.code));
            }
            else if (param.type != 0)
            {
                icmpPacket.TypeCode = (ICMPv4TypeCodes)((param.type * 256));
            }
            else
            {
                icmpPacket.TypeCode = ICMPv4TypeCodes.EchoRequest;
            }

            IPv4Packet ipPacket = new IPv4Packet(param.sIP, param.dIP);
            if (param.IPv4Frag) { ipPacket.FragmentFlags = (int)1; }
            ipPacket.PayloadPacket = icmpPacket;
            ipPacket.Checksum = ipPacket.CalculateIPChecksum();
            ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV4);
            ret.PayloadPacket = ipPacket;
        }
        else if (param.packetType == Param.PacketType.ICMPv6)
        {
            ICMPv6Packet icmpv6Packet = CreateICMPv6Packet(param);
            IPv6Packet ipPacket = new IPv6Packet(param.sIP, param.dIP);
            ipPacket.PayloadPacket = icmpv6Packet;
            ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV6);
            ret.PayloadPacket = ipPacket;
        }
        else if (param.packetType == Param.PacketType.IP)
        {
            if (param.dIP.ToString().Contains("."))
            {
                ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV4);
                IPv4Packet ipPacket = new IPv4Packet(param.sIP, param.dIP);
                if (param.IPv4Frag) { ipPacket.FragmentFlags = (int)1; }
                ipPacket.Protocol = param.IPProtocol;
                ipPacket.PayloadData = param.payload;
                ipPacket.UpdateCalculatedValues();
                ret.PayloadPacket = ipPacket;
                ipPacket.UpdateIPChecksum();
            }
            else
            {
                ret = new EthernetPacket(param.sMAC, param.dMAC, EthernetPacketType.IpV6);

                //if extension headers were not specified, just put the payload
                if (param.ExtentionHeader.Count == 0)
                {
                    IPv6Packet ipPacket = new IPv6Packet(param.sIP, param.dIP);
                    ipPacket.Protocol = param.IPProtocol;
                    ipPacket.PayloadData = param.payload;
                    ipPacket.PayloadLength = (ushort)param.payload.Length;
                    ipPacket.UpdateCalculatedValues();
                    ret.PayloadPacket = ipPacket;
                }
                else
                {
                    ret = PacketFactory.CreateEHPacket(param, (EthernetPacket)ret);
                }
                ret.UpdateCalculatedValues();
            }
        }
        else if (param.packetType == Param.PacketType.EtherType)
        {
            ret = new EthernetPacket(param.sMAC, param.dMAC, param.EtherTypeProtocol);
            byte[] etherBuffer = (new byte[64]);
            var payload = new byte[etherBuffer.Length + (param.payload).Length];
            etherBuffer.CopyTo(payload, 0);
            (param.payload).CopyTo(payload, etherBuffer.Length);
            ret.PayloadData = payload;
            ret.UpdateCalculatedValues();
        }

        return ret;
    }
예제 #32
0
    //terrible hack to get extension headers working
    private static EthernetPacket CreateEHPacket(Param param, EthernetPacket ret)
    {
        IPv6Packet ipPacket = new IPv6Packet(param.sIP, param.dIP);
        ipPacket.Protocol = (IPProtocolType)param.ExtentionHeader[0];
        param.ExtentionHeader.RemoveAt(0);

        //need to find out what is the last packet so that we can decide on the length of the packet
        IPProtocolType endEH = param.ExtentionHeader[param.ExtentionHeader.Count - 1];
        int lastHeaderLength = 0;
        switch (endEH)
        {
            case IPProtocolType.TCP:
                lastHeaderLength = 20;
                break;
            case IPProtocolType.UDP:
                lastHeaderLength = 8;
                break;
            case IPProtocolType.ICMP:
                lastHeaderLength = 8;
                break;
            default:
                lastHeaderLength = 64;
                break;
        }

        //calculate the Extension header size
        int EHSize = 0;
        foreach (IPProtocolType eh in param.ExtentionHeader)
        {
            if (eh == IPProtocolType.FRAGMENT)
            {
                EHSize += 8;
            }
            else
            {
                EHSize += 24;
            }
        }

        if (ipPacket.Protocol == IPProtocolType.FRAGMENT)
        {
            EHSize -= 16;
        }

        byte[] tempPayload = new byte[EHSize + param.payload.Length + lastHeaderLength];
        param.payload.CopyTo(tempPayload, EHSize + lastHeaderLength);

        int loc = 0;
        byte previous = (byte)ipPacket.Protocol;
        foreach (byte eh in param.ExtentionHeader)
        {
            tempPayload.SetValue((byte)eh, loc);
            tempPayload.SetValue((byte)2, loc + 1);
            if ((IPProtocolType)previous == IPProtocolType.FRAGMENT)
            {
                loc += 8;
            }
            else
            {
                loc += 24;
            }
            previous = eh;
        }

        //set the port if the last EH is tcp or udp
        if (endEH == IPProtocolType.TCP || endEH == IPProtocolType.UDP)
        {
            //set the port numbers
            tempPayload.SetValue((byte)(param.sPort >> 8), loc);
            tempPayload.SetValue((byte)param.sPort, loc + 1);
            tempPayload.SetValue((byte)(param.dPort >> 8), loc + 2);
            tempPayload.SetValue((byte)param.dPort, loc + 3);
        }
        if (endEH == IPProtocolType.TCP)
        {
            tempPayload.SetValue((byte)0x50, loc + 12);
        }
        else if (endEH == IPProtocolType.UDP)
        {
            //set the length of the payload
            Int16 length = (Int16)(lastHeaderLength + param.payload.Length);
            BitConverter.GetBytes(length).CopyTo(tempPayload, loc + 5);
            tempPayload.SetValue((byte)0x12, loc + 6);
            tempPayload.SetValue((byte)0x34, loc + 7);
        }

        //set the tcp flags if they are TCP
        if (endEH == IPProtocolType.TCP)
        {
            tempPayload.SetValue((byte)param.tcpFlag, loc + 13);
        }

        ipPacket.PayloadData = tempPayload;
        ipPacket.PayloadLength = (ushort)tempPayload.Length;
        ipPacket.UpdateCalculatedValues();
        ret.PayloadPacket = ipPacket;
        return ret;
    }