コード例 #1
0
ファイル: HTTPSendPacket.cs プロジェクト: Innerfear/InfSec
        public HTTPSendPacket(string MACsrc, string MACdst, string IPsrc, string IPdst,
            string IpId, string TTL,
            string PORTsrc, string SQN, string ACK, string WIN, string Data, string Domain)
        {
            GetBase(MACsrc, MACdst, IPsrc, IPdst, IpId, TTL);

            tcpLayer = new TcpLayer
            {
                SourcePort = StringToUShort(PORTsrc),
                DestinationPort = 80,
                Checksum = null, // Will be filled automatically.
                SequenceNumber = StringToUShort(SQN),
                AcknowledgmentNumber = StringToUShort(ACK),
                ControlBits = TcpControlBits.Acknowledgment,
                Window = StringToUShort(WIN),
                UrgentPointer = 0,
                Options = TcpOptions.None,
            };

            httpLayer = new HttpRequestLayer
            {
                Version = HttpVersion.Version11,
                Header = new HttpHeader(new HttpContentLengthField(11)),
                Body = new Datagram(Encoding.ASCII.GetBytes(Data)),
                Method = new HttpRequestMethod(HttpRequestKnownMethod.Get),
                Uri = @"http://" + Domain + "/",
            };
        }
コード例 #2
0
 /// <summary>
 /// True iff the SequenceNumber, AcknowledgmentNumber, ControlBits, Window, UrgentPointer and Options fields are equal.
 /// </summary>
 private bool EqualFields(TcpLayer other)
 {
     return(other != null &&
            SequenceNumber == other.SequenceNumber && AcknowledgmentNumber == other.AcknowledgmentNumber &&
            ControlBits == other.ControlBits &&
            Window == other.Window && UrgentPointer == other.UrgentPointer &&
            Options.Equals(other.Options));
 }
コード例 #3
0
 private bool EqualFields(TcpLayer other)
 {
     if (other != null && (int)this.SequenceNumber == (int)other.SequenceNumber && ((int)this.AcknowledgmentNumber == (int)other.AcknowledgmentNumber && this.ControlBits == other.ControlBits) && ((int)this.Window == (int)other.Window && (int)this.UrgentPointer == (int)other.UrgentPointer))
     {
         return(this.Options.Equals((PcapDotNet.Packets.Options <TcpOption>)other.Options));
     }
     return(false);
 }
コード例 #4
0
        public override ILayer ExtractLayer()
        {
            TcpLayer tcpLayer = new TcpLayer();

            tcpLayer.Checksum             = new ushort?(this.Checksum);
            tcpLayer.SourcePort           = this.SourcePort;
            tcpLayer.DestinationPort      = this.DestinationPort;
            tcpLayer.SequenceNumber       = this.SequenceNumber;
            tcpLayer.AcknowledgmentNumber = this.AcknowledgmentNumber;
            tcpLayer.ControlBits          = this.ControlBits;
            tcpLayer.Window        = this.Window;
            tcpLayer.UrgentPointer = this.UrgentPointer;
            tcpLayer.Options       = this.Options;
            return((ILayer)tcpLayer);
        }
コード例 #5
0
 public OwnPacketBuilder(PacketType packetType)
 {
     GetLocalInformation.LocalMacAndIPAddress( out _ownIpAddress, out _ownMacAddress );
     ethernetLayer = null;
     ipV4Layer = null;
     tcpLayer = null;
     arpLayer = null;
     switch(packetType)
     {
         case PacketType.ARP :
             BuildingArpPacket();
             break;
         case PacketType.TCP :
             BuildingTcpPacket();
             break;
         case PacketType.Unknown :
             break;
         default :
             break;
     }
 }
コード例 #6
0
ファイル: TCPSendPacket.cs プロジェクト: Innerfear/InfSec
        public TCPSendPacket(string MACsrc, string MACdst, string IPsrc, string IPdst, 
            string IpId, string TTL, string PORTsrc, string SQN, string ACK, string WIN, string data)
        {
            GetBase(MACsrc, MACdst, IPsrc, IPdst, IpId, TTL);

            tcpLayer = new TcpLayer
            {
                SourcePort = StringToUShort(PORTsrc),
                DestinationPort = 25,
                Checksum = null, // Will be filled automatically.
                SequenceNumber = StringToUShort(SQN),
                AcknowledgmentNumber = StringToUShort(ACK),
                ControlBits = TcpControlBits.Acknowledgment,
                Window = StringToUShort(WIN),
                UrgentPointer = 0,
                Options = TcpOptions.None,
            };

            payloadLayer = new PayloadLayer
            {
                Data = new Datagram(Encoding.ASCII.GetBytes(data)),
            };
        }
コード例 #7
0
ファイル: ArpPoisoner.cs プロジェクト: bmuthoga/dipw
        //Forwards packets from the gateway to the victim and from the victim to the gateway
        public void Forwarder(Packet packet)
        {
            using (PacketCommunicator communicator = _forwardingListener.Device.Open())
            {

                var etherpacket = packet.Ethernet;
                var ippacket = etherpacket.IpV4;

                PayloadLayer payloadLayer;
                PacketBuilder builder;

                MacAddress newMacDestination;
                String ipDestination = ippacket.Destination.ToString();
                try
                {
                    newMacDestination = new MacAddress(_targets.First(x => x.IP == ipDestination).MAC);
                }
                catch
                {
                    newMacDestination = new MacAddress(_gateway.MAC);
                }

                EthernetLayer ethernetLayer =
                    new EthernetLayer
                    {
                        Source = etherpacket.Destination,
                        Destination = newMacDestination,
                        EtherType = EthernetType.IpV4,
                    };

                IpV4Layer ipLayer =
                    new IpV4Layer
                    {
                        Source = ippacket.Source,
                        CurrentDestination = ippacket.Destination,
                        Fragmentation = ippacket.Fragmentation,
                        Identification = ippacket.Identification,
                        Options = ippacket.Options,
                        HeaderChecksum = null, // Will be filled automatically.
                        Ttl = ippacket.Ttl,
                        TypeOfService = ippacket.TypeOfService,
                    };

                switch (ippacket.Protocol)
                {
                    case IpV4Protocol.Udp:

                        var udpPacket = ippacket.Udp;

                        //dns spoofing
                        if (IsDnsSpoofingEnabled && udpPacket.DestinationPort == 53 && udpPacket.Dns.Queries[0].DnsType == DnsType.A)
                        {
                            try
                            {
                                var spoofingEntry = _dnsSpoofingList.First(x => x.DomainName == udpPacket.Dns.Queries[0].DomainName.ToString());
                                communicator.SendPacket(CreateDnsReply(etherpacket, new IpV4Address(spoofingEntry.IP)));
                                return;
                            }
                            catch { }
                        }

                        UdpLayer udpLayer = new UdpLayer
                        {
                            SourcePort = udpPacket.SourcePort,
                            DestinationPort = udpPacket.DestinationPort,
                            Checksum = null, // Will be filled automatically.
                            CalculateChecksumValue = true
                        };
                        payloadLayer = new PayloadLayer
                        {
                            Data = udpPacket.Payload
                        };
                        builder = new PacketBuilder(ethernetLayer, ipLayer, udpLayer, payloadLayer);
                        break;

                    case IpV4Protocol.Tcp:
                        var tcpPacket = ippacket.Tcp;
                        TcpLayer tcpLayer = new TcpLayer
                        {
                            SourcePort = tcpPacket.SourcePort,
                            DestinationPort = tcpPacket.DestinationPort,
                            Checksum = null, // Will be filled automatically.
                            AcknowledgmentNumber = tcpPacket.AcknowledgmentNumber,
                            ControlBits = tcpPacket.ControlBits,
                            Window = tcpPacket.Window,
                            UrgentPointer = tcpPacket.UrgentPointer,
                            Options = tcpPacket.Options,
                            SequenceNumber = tcpPacket.SequenceNumber
                        };

                        payloadLayer = new PayloadLayer()
                        {
                            Data = tcpPacket.Payload
                        };
                        builder = new PacketBuilder(ethernetLayer, ipLayer, tcpLayer, payloadLayer);
                        break;

                    default:
                        Console.WriteLine("packet type was not udp or tcp!");
                        return;
                }

                communicator.SendPacket(builder.Build(DateTime.Now));
            }
        }
コード例 #8
0
 void BuildingTcpPacket()
 {
     ethernetLayer = new EthernetLayer
     {
         Source = new MacAddress( ToMac( _ownMacAddress.ToString() ) ),
         EtherType = EthernetType.None, // Will be filled automatically.
     };
     ipV4Layer = new IpV4Layer
     {
         Source = new IpV4Address( new IPAddress( _ownIpAddress ).ToString() ),
         Fragmentation = IpV4Fragmentation.None,
         HeaderChecksum = null, // Will be filled automatically.
         Identification = 0,
         Options = IpV4Options.None,
         Protocol = null, // Will be filled automatically.
         Ttl = 100,
         TypeOfService = 0,
     };
     tcpLayer = new TcpLayer
     {
         SourcePort = 62000,
         Checksum = null, // Will be filled automatically.
         SequenceNumber = 100,
         AcknowledgmentNumber = 0,
         ControlBits = TcpControlBits.Synchronize,
         Window = 8192,
         UrgentPointer = 0,
         Options = new TcpOptions( new TcpOptionMaximumSegmentSize( 1460 ), TcpOption.Nop, new TcpOptionWindowScale( 2 ), new TcpOptionSelectiveAcknowledgmentPermitted(), new TcpOptionTimestamp( (uint)DateTime.Now.Ticks, 0 ) ),
     };
 }
コード例 #9
0
ファイル: TapWorker.cs プロジェクト: SortByte/Network-Manager
 public void SendSynAck(Guid guid)
 {
     EthernetLayer ethernetLayer = new EthernetLayer
     {
         Source = ownHardwareAddress,
         Destination = ifHardwareAddress,
         EtherType = EthernetType.None,
     };
     IpV4Layer ipV4Layer = new IpV4Layer
     {
         Source = RoutingTable.connParams[guid].remoteIp,
         CurrentDestination = ifProtocolAddress,
         Fragmentation = IpV4Fragmentation.None,
         HeaderChecksum = null, // Will be filled automatically.
         Identification = ipID,
         Options = IpV4Options.None,
         Protocol = IpV4Protocol.Tcp,
         Ttl = 128,
         TypeOfService = 0,
     };
     TcpLayer tcpLayer = new TcpLayer
     {
         SourcePort = RoutingTable.connParams[guid].remotePort,
         DestinationPort = RoutingTable.connParams[guid].localPort,
         Checksum = null, // Will be filled automatically.
         SequenceNumber = RoutingTable.connParams[guid].seq,
         AcknowledgmentNumber = RoutingTable.connParams[guid].ack,
         ControlBits = TcpControlBits.Synchronize | TcpControlBits.Acknowledgment,
         Window = RoutingTable.connParams[guid].GetWindow(),
         UrgentPointer = 0,
         Options = new TcpOptions(new TcpOptionMaximumSegmentSize((ushort)MSS), new TcpOptionWindowScale(RoutingTable.connParams[guid].windowScale)),
     };
     PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer);
     SendPacket(builder.Build(DateTime.Now));
 }
コード例 #10
0
ファイル: TapWorker.cs プロジェクト: SortByte/Network-Manager
 public void SendData(Guid guid, int payloadLength)
 {
     EthernetLayer ethernetLayer = new EthernetLayer
     {
         Source = ownHardwareAddress,
         Destination = ifHardwareAddress,
         EtherType = EthernetType.None,
     };
     IpV4Layer ipV4Layer = new IpV4Layer
     {
         Source = RoutingTable.connParams[guid].remoteIp,
         CurrentDestination = ifProtocolAddress,
         Fragmentation = IpV4Fragmentation.None,
         HeaderChecksum = null, // Will be filled automatically.
         Identification = ipID,
         Options = IpV4Options.None,
         Protocol = IpV4Protocol.Tcp,
         Ttl = 128,
         TypeOfService = 0,
     };
     TcpLayer tcpLayer = new TcpLayer
     {
         SourcePort = RoutingTable.connParams[guid].remotePort,
         DestinationPort = RoutingTable.connParams[guid].localPort,
         Checksum = null, // Will be filled automatically.
         SequenceNumber = RoutingTable.connParams[guid].seq,
         AcknowledgmentNumber = RoutingTable.connParams[guid].ack,
         ControlBits = TcpControlBits.Acknowledgment,
         Window = RoutingTable.connParams[guid].GetWindow(),
         UrgentPointer = 0,
         Options = TcpOptions.None,
     };
     PayloadLayer payloadLayer = new PayloadLayer
     {
         Data = new Datagram(RoutingTable.connParams[guid].receivingBuffer.Take(payloadLength).ToArray()),
     };
     PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, payloadLayer);
     SendPacket(builder.Build(DateTime.Now));
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: 1foxman1/Network-Bridge
        /// <summary>
        /// This function build an TCP over IPv4 over Ethernet with payload packet.
        /// </summary>
        private static Packet BuildTcpPacket(MacAddress SourceMac, MacAddress DestinationMac, IpV4Layer ipV4Layer, TcpLayer tcpLayer, PayloadLayer payloadLayer)
        {
            EthernetLayer ethernetLayer =
                new EthernetLayer
                {
                    Source = SourceMac,
                    Destination = DestinationMac,
                    EtherType = EthernetType.None, // Will be filled automatically.
                };

            //IpV4Layer ipV4Layer =
            //    new IpV4Layer
            //    {
            //        Source = SourceIp,
            //        CurrentDestination = DestinatinIp,
            //        Fragmentation = IpV4Fragmentation.None,
            //        HeaderChecksum = null, // Will be filled automatically.
            //        Identification = 123,
            //        Options = IpV4Options.None,
            //        Protocol = null, // Will be filled automatically.
            //        Ttl = 100,
            //        TypeOfService = 0,
            //    };

            //TcpLayer tcpLayer =
            //    new TcpLayer
            //    {
            //        SourcePort = 4050,
            //        DestinationPort = 25,
            //        Checksum = null, // Will be filled automatically.
            //        SequenceNumber = 100,
            //        AcknowledgmentNumber = 50,
            //        ControlBits = TcpControlBits.Acknowledgment,
            //        Window = 100,
            //        UrgentPointer = 0,
            //        Options = TcpOptions.None,
            //    };

            //PayloadLayer payloadLayer =
            //    new PayloadLayer
            //    {
            //        Data = new Datagram(Encoding.ASCII.GetBytes("hello world")),
            //    };

            PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, payloadLayer);

            return builder.Build(DateTime.Now);
        }
コード例 #12
0
        private static void CreateRandomTcpPayload(Random random, TcpLayer tcpLayer, List<ILayer> layers)
        {
            if (random.NextBool(20))
            {
                // Finish with payload.
                PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100));
                layers.Add(payloadLayer);
                return;
            }

            HttpLayer httpLayer = random.NextHttpLayer();
            layers.Add(httpLayer);
            if (httpLayer.IsRequest)
                tcpLayer.DestinationPort = 80;
            else
                tcpLayer.SourcePort = 80;

            if (random.NextBool())
                return;

            HttpLayer httpLayer2 = httpLayer.IsRequest ? (HttpLayer)random.NextHttpRequestLayer() : random.NextHttpResponseLayer();
            layers.Add(httpLayer2);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: benjojo/Discovery
        private static void preparePcap()
        {
            var source = new MacAddress(getClientMAC());
            var dest = new MacAddress(getRouterMAC());

            device = LivePacketDevice.AllLocalMachine[0];
            communicator = device.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000);

            EthernetLayer ethLayer = new EthernetLayer { Source = source, Destination = dest };
            ipLayer = new IpV4Layer { Source = new IpV4Address(LocalIPAddress()), Ttl = 128 };
            icmpLayer = new IcmpEchoLayer();
            icmpBuilder = new PacketBuilder(ethLayer, ipLayer, icmpLayer);

            TCPLayer = new TcpLayer();
            TCPBuilder = new PacketBuilder(ethLayer, ipLayer, TCPLayer);

            if (!TCPMode)
            {
                communicator.SetFilter("icmp[0] = 0");
            }
            else
            {
                //tcp[13] = 18
                communicator.SetFilter("tcp[13] = 18 and port " + TCPPort);
            }
        }
コード例 #14
0
ファイル: TcpLayer.cs プロジェクト: JackWangCUMT/WiFiSpy
 /// <summary>
 /// True iff the SequenceNumber, AcknowledgmentNumber, ControlBits, Window, UrgentPointer and Options fields are equal.
 /// </summary>
 private bool EqualFields(TcpLayer other)
 {
     return other != null &&
            SequenceNumber == other.SequenceNumber && AcknowledgmentNumber == other.AcknowledgmentNumber &&
            ControlBits == other.ControlBits &&
            Window == other.Window && UrgentPointer == other.UrgentPointer &&
            Options.Equals(other.Options);
 }
コード例 #15
0
ファイル: TcpStream.cs プロジェクト: labeuze/source
 private void CreateRequestReply()
 {
     if (_streamReply != null)
     {
         _streamReply.Close();
         byte[] data = _streamReply.ToArray();
         _streamReply = null;
         EthernetLayer ethernetLayer = new EthernetLayer { Source = _tcpConnection.Destination.MacAddress, Destination = _tcpConnection.Source.MacAddress };
         IpV4Layer ipV4Layer = new IpV4Layer
         {
             Source = _tcpConnection.Destination.IpAddress,
             CurrentDestination = _tcpConnection.Source.IpAddress,
             Fragmentation = IpV4Fragmentation.None,
             //HeaderChecksum = null, // Will be filled automatically.
             Identification = 123,
             Options = IpV4Options.None,
             //Protocol = null, // Will be filled automatically.
             Ttl = 100,
             TypeOfService = 0
         };
         TcpLayer tcpLayer = new TcpLayer()
         {
             SourcePort = _tcpConnection.Destination.Port,
             DestinationPort = _tcpConnection.Source.Port,
             //Checksum = null, // Will be filled automatically.
             SequenceNumber = 100,
             AcknowledgmentNumber = 50,
             ControlBits = TcpControlBits.Acknowledgment,
             Window = 100,
             UrgentPointer = 0,
             Options = TcpOptions.None
         };
         PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(data) };
         PacketBuilder packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, payloadLayer);
         if (PacketHandle != null)
             PacketHandle(TcpDirection.DestinationToSource, packetBuilder.Build(_replyTimestamp));
         _replyTimestamp = DateTime.MinValue;
     }
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: amitla/Pcap.Net
        /// <summary>
        /// This function build an HTTP over TCP over IPv4 over Ethernet packet.
        /// </summary>
        private static Packet BuildHttpPacket()
        {
            EthernetLayer ethernetLayer =
                new EthernetLayer
                    {
                        Source = new MacAddress("01:01:01:01:01:01"),
                        Destination = new MacAddress("02:02:02:02:02:02"),
                        EtherType = EthernetType.None, // Will be filled automatically.
                    };

            IpV4Layer ipV4Layer =
                new IpV4Layer
                    {
                        Source = new IpV4Address("1.2.3.4"),
                        CurrentDestination = new IpV4Address("11.22.33.44"),
                        Fragmentation = IpV4Fragmentation.None,
                        HeaderChecksum = null, // Will be filled automatically.
                        Identification = 123,
                        Options = IpV4Options.None,
                        Protocol = null, // Will be filled automatically.
                        Ttl = 100,
                        TypeOfService = 0,
                    };

            TcpLayer tcpLayer =
                new TcpLayer
                    {
                        SourcePort = 4050,
                        DestinationPort = 80,
                        Checksum = null, // Will be filled automatically.
                        SequenceNumber = 100,
                        AcknowledgmentNumber = 50,
                        ControlBits = TcpControlBits.Acknowledgment,
                        Window = 100,
                        UrgentPointer = 0,
                        Options = TcpOptions.None,
                    };

            HttpRequestLayer httpLayer =
                new HttpRequestLayer
                    {
                        Version = HttpVersion.Version11,
                        Header = new HttpHeader(new HttpContentLengthField(11)),
                        Body = new Datagram(Encoding.ASCII.GetBytes("hello world")),
                        Method = new HttpRequestMethod(HttpRequestKnownMethod.Get),
                        Uri = @"http://pcapdot.net/",
                    };

            PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, httpLayer);

            return builder.Build(DateTime.Now);
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: amitla/Pcap.Net
        /// <summary>
        /// This function build an TCP over IPv4 over Ethernet with payload packet.
        /// </summary>
        private static Packet BuildTcpPacket()
        {
            EthernetLayer ethernetLayer =
                new EthernetLayer
                    {
                        Source = new MacAddress("01:01:01:01:01:01"),
                        Destination = new MacAddress("02:02:02:02:02:02"),
                        EtherType = EthernetType.None, // Will be filled automatically.
                    };

            IpV4Layer ipV4Layer =
                new IpV4Layer
                    {
                        Source = new IpV4Address("1.2.3.4"),
                        CurrentDestination = new IpV4Address("11.22.33.44"),
                        Fragmentation = IpV4Fragmentation.None,
                        HeaderChecksum = null, // Will be filled automatically.
                        Identification = 123,
                        Options = IpV4Options.None,
                        Protocol = null, // Will be filled automatically.
                        Ttl = 100,
                        TypeOfService = 0,
                    };

            TcpLayer tcpLayer =
                new TcpLayer
                    {
                        SourcePort = 4050,
                        DestinationPort = 25,
                        Checksum = null, // Will be filled automatically.
                        SequenceNumber = 100,
                        AcknowledgmentNumber = 50,
                        ControlBits = TcpControlBits.Acknowledgment,
                        Window = 100,
                        UrgentPointer = 0,
                        Options = TcpOptions.None,
                    };

            PayloadLayer payloadLayer =
                new PayloadLayer
                    {
                        Data = new Datagram(Encoding.ASCII.GetBytes("hello world")),
                    };

            PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, payloadLayer);

            return builder.Build(DateTime.Now);
        }
コード例 #18
0
ファイル: CAMOverflowSender.cs プロジェクト: bmuthoga/dipw
        private void InitializePackets()
        {
            //Fill with dummy data
            _ethernetLayer =
                new EthernetLayer
                {
                    Source = new MacAddress("01:01:01:01:01:01"),
                    Destination = new MacAddress("02:02:02:02:02:02"),
                    EtherType = EthernetType.None, // Will be filled automatically.
                };

            _ipV4Layer =
                new IpV4Layer
                {
                    Source = new IpV4Address("1.2.3.4"),
                    CurrentDestination = new IpV4Address("11.22.33.44"),
                    Fragmentation = IpV4Fragmentation.None,
                    HeaderChecksum = null, // Will be filled automatically.
                    Identification = 123,
                    Options = IpV4Options.None,
                    Protocol = null, // Will be filled automatically.
                    Ttl = 100,
                    TypeOfService = 0,
                };

            _tcpLayer =
                new TcpLayer
                {
                    SourcePort = 4050,
                    DestinationPort = 25,
                    Checksum = null, // Will be filled automatically.
                    SequenceNumber = 100,
                    AcknowledgmentNumber = 50,
                    ControlBits = TcpControlBits.Acknowledgment,
                    Window = 100,
                    UrgentPointer = 0,
                    Options = TcpOptions.None,
                };

            _payloadLayer =
                new PayloadLayer
                {
                    Data = new Datagram(Encoding.ASCII.GetBytes("CAM Flooding Packet")),
                };
        }