예제 #1
0
            public void Test_ConstructorWithCorruptBuffer()
            {
                //buffer is way too short for frame. We are just checking it doesn't throw
                byte[] corruptBuffer            = new byte[] { 0x01 };
                ReassociationRequestFrame frame = new ReassociationRequestFrame(new ByteArraySegment(corruptBuffer));

                Assert.IsFalse(frame.FCSValid);
            }
예제 #2
0
            public void Test_Constructor_ConstructWithValues()
            {
                InformationElement ssidInfoElement = new InformationElement(InformationElement.ElementId.ServiceSetIdentity,
                                                                            new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });
                InformationElement vendorElement = new InformationElement(InformationElement.ElementId.VendorSpecific,
                                                                          new Byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 });


                ReassociationRequestFrame frame = new ReassociationRequestFrame(PhysicalAddress.Parse("111111111111"),
                                                                                PhysicalAddress.Parse("222222222222"),
                                                                                PhysicalAddress.Parse("333333333333"),
                                                                                new InformationElementList()
                {
                    ssidInfoElement, vendorElement
                });

                frame.FrameControl.ToDS          = false;
                frame.FrameControl.FromDS        = true;
                frame.FrameControl.MoreFragments = true;

                frame.Duration.Field = 0x1234;

                frame.SequenceControl.SequenceNumber = 0x77;
                frame.SequenceControl.FragmentNumber = 0x1;

                frame.CapabilityInformation.Privacy        = true;
                frame.CapabilityInformation.ChannelAgility = true;

                frame.UpdateFrameCheckSequence();
                UInt32 fcs = frame.FrameCheckSequence;

                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas   = new ByteArraySegment(bytes);

                //create a new frame that should be identical to the original
                ReassociationRequestFrame recreatedFrame = MacFrame.ParsePacket(bas) as ReassociationRequestFrame;

                recreatedFrame.UpdateFrameCheckSequence();

                Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementReassociationRequest, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse(recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue(recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue(recreatedFrame.FrameControl.MoreFragments);

                Assert.AreEqual(0x77, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual(0x1, recreatedFrame.SequenceControl.FragmentNumber);

                Assert.IsTrue(recreatedFrame.CapabilityInformation.Privacy);
                Assert.IsTrue(recreatedFrame.CapabilityInformation.ChannelAgility);

                Assert.AreEqual("111111111111", recreatedFrame.SourceAddress.ToString().ToUpper());
                Assert.AreEqual("222222222222", recreatedFrame.DestinationAddress.ToString().ToUpper());
                Assert.AreEqual("333333333333", recreatedFrame.BssId.ToString().ToUpper());

                Assert.AreEqual(fcs, recreatedFrame.FrameCheckSequence);
            }
예제 #3
0
            public void Test_Constructor()
            {
                var dev = new CaptureFileReaderDevice("../../CaptureFiles/80211_reassociation_request_frame.pcap");

                dev.Open();
                var rawCapture = dev.GetNextPacket();

                dev.Close();

                Packet p = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data);
                ReassociationRequestFrame frame = (ReassociationRequestFrame)p.PayloadPacket;

                Assert.AreEqual(0, frame.FrameControl.ProtocolVersion);
                Assert.AreEqual(FrameControlField.FrameSubTypes.ManagementReassociationRequest, frame.FrameControl.SubType);
                Assert.IsFalse(frame.FrameControl.ToDS);
                Assert.IsFalse(frame.FrameControl.FromDS);
                Assert.IsFalse(frame.FrameControl.MoreFragments);
                Assert.IsFalse(frame.FrameControl.Retry);
                Assert.IsFalse(frame.FrameControl.PowerManagement);
                Assert.IsFalse(frame.FrameControl.MoreData);
                Assert.IsFalse(frame.FrameControl.Wep);
                Assert.IsFalse(frame.FrameControl.Order);
                Assert.AreEqual(314, frame.Duration.Field);  //this need expanding on in the future
                Assert.AreEqual("0026F23E46C1", frame.DestinationAddress.ToString().ToUpper());
                Assert.AreEqual("7CC5376C970A", frame.SourceAddress.ToString().ToUpper());
                Assert.AreEqual("0026F23E46C1", frame.BssId.ToString().ToUpper());
                Assert.AreEqual(0, frame.SequenceControl.FragmentNumber);
                Assert.AreEqual(2729, frame.SequenceControl.SequenceNumber);
                Assert.IsTrue(frame.CapabilityInformation.IsEss);
                Assert.IsFalse(frame.CapabilityInformation.IsIbss);
                Assert.IsFalse(frame.CapabilityInformation.CfPollable);
                Assert.IsFalse(frame.CapabilityInformation.CfPollRequest);
                Assert.IsTrue(frame.CapabilityInformation.Privacy);
                Assert.IsTrue(frame.CapabilityInformation.ShortPreamble);
                Assert.IsFalse(frame.CapabilityInformation.Pbcc);
                Assert.IsFalse(frame.CapabilityInformation.ChannelAgility);
                Assert.IsTrue(frame.CapabilityInformation.ShortTimeSlot);
                Assert.IsFalse(frame.CapabilityInformation.DssOfdm);
                Assert.AreEqual(0x0a, frame.ListenInterval);
                Assert.AreEqual(0xFCBB7306, frame.FrameCheckSequence);
                Assert.AreEqual(4, frame.InformationElements.Count);
                Assert.AreEqual(74, frame.FrameSize);
            }
예제 #4
0
            /// <summary>
            /// Parses the <see cref="Kavprot.Packets.Utils.ByteArraySegment"/> into a MacFrame.
            /// </summary>
            /// <returns>
            /// The parsed MacFrame or null if it could not be parsed.
            /// </returns>
            /// <param name='bas'>
            /// The bytes of the packet. bas.Offset should point to the first byte in the mac frame.
            /// </param>
            /// <remarks>If the provided bytes contain the FCS then call <see cref="MacFrame.ParsePacketWithFcs"/> instead. The presence of the
            /// FCS is usually determined by configuration of the device used to capture the packets.</remarks>
            public static MacFrame ParsePacket(ByteArraySegment bas)
            {
                if (bas.Length < MacFields.FrameControlLength)
                {
                    //there isn't enough data to even try and work out what type of packet it is
                    return(null);
                }
                //this is a bit ugly as we will end up parsing the framecontrol field twice, once here and once
                //inside the packet constructor. Could create the framecontrol and pass it to the packet but I think that is equally ugly
                FrameControlField frameControl = new FrameControlField(
                    EndianBitConverter.Big.ToUInt16(bas.Bytes, bas.Offset));

                MacFrame macFrame = null;

                switch (frameControl.SubType)
                {
                case FrameControlField.FrameSubTypes.ManagementAssociationRequest:
                {
                    macFrame = new AssociationRequestFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementAssociationResponse:
                {
                    macFrame = new AssociationResponseFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementReassociationRequest:
                {
                    macFrame = new ReassociationRequestFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementReassociationResponse:
                {
                    macFrame = new AssociationResponseFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementProbeRequest:
                {
                    macFrame = new ProbeRequestFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementProbeResponse:
                {
                    macFrame = new ProbeResponseFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementReserved0:
                    break; //TODO

                case FrameControlField.FrameSubTypes.ManagementReserved1:
                    break; //TODO

                case FrameControlField.FrameSubTypes.ManagementBeacon:
                {
                    macFrame = new BeaconFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementATIM:
                    break; //TODO

                case FrameControlField.FrameSubTypes.ManagementDisassociation:
                {
                    macFrame = new DisassociationFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementAuthentication:
                {
                    macFrame = new AuthenticationFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementDeauthentication:
                {
                    macFrame = new DeauthenticationFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementAction:
                {
                    macFrame = new ActionFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ManagementReserved3:
                    break; //TODO

                case FrameControlField.FrameSubTypes.ControlBlockAcknowledgmentRequest:
                {
                    macFrame = new BlockAcknowledgmentRequestFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ControlBlockAcknowledgment:
                {
                    macFrame = new BlockAcknowledgmentFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ControlPSPoll:
                    break; //TODO

                case FrameControlField.FrameSubTypes.ControlRTS:
                {
                    macFrame = new RtsFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ControlCTS:
                {
                    macFrame = new CtsFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ControlACK:
                {
                    macFrame = new AckFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ControlCFEnd:
                {
                    macFrame = new ContentionFreeEndFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.ControlCFEndCFACK:
                    break; //TODO

                case FrameControlField.FrameSubTypes.Data:
                case FrameControlField.FrameSubTypes.DataCFACK:
                case FrameControlField.FrameSubTypes.DataCFPoll:
                case FrameControlField.FrameSubTypes.DataCFAckCFPoll:
                {
                    macFrame = new DataDataFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.DataNullFunctionNoData:
                case FrameControlField.FrameSubTypes.DataCFAckNoData:
                case FrameControlField.FrameSubTypes.DataCFPollNoData:
                case FrameControlField.FrameSubTypes.DataCFAckCFPollNoData:
                {
                    macFrame = new NullDataFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.QosData:
                case FrameControlField.FrameSubTypes.QosDataAndCFAck:
                case FrameControlField.FrameSubTypes.QosDataAndCFPoll:
                case FrameControlField.FrameSubTypes.QosDataAndCFAckAndCFPoll:
                {
                    macFrame = new QosDataFrame(bas);
                    break;
                }

                case FrameControlField.FrameSubTypes.QosNullData:
                case FrameControlField.FrameSubTypes.QosCFAck:
                case FrameControlField.FrameSubTypes.QosCFPoll:
                case FrameControlField.FrameSubTypes.QosCFAckAndCFPoll:
                {
                    macFrame = new QosNullDataFrame(bas);
                    break;
                }

                default:
                    //this is an unsupported (and unknown) packet type
                    break;
                }

                return(macFrame);
            }
            public void Test_Constructor_ConstructWithValues ()
            {
                InformationElement ssidInfoElement = new InformationElement (InformationElement.ElementId.ServiceSetIdentity, 
                                                                           new Byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f });
                InformationElement vendorElement = new InformationElement (InformationElement.ElementId.VendorSpecific,
                                                                           new Byte[] {0x01, 0x02, 0x03, 0x04, 0x05});
                
                
                ReassociationRequestFrame frame = new ReassociationRequestFrame (PhysicalAddress.Parse ("111111111111"),
                                                                                 PhysicalAddress.Parse ("222222222222"),
                                                                                 PhysicalAddress.Parse ("333333333333"),
                                                                                 new InformationElementList (){ssidInfoElement, vendorElement});
                
                frame.FrameControl.ToDS = false;
                frame.FrameControl.FromDS = true;
                frame.FrameControl.MoreFragments = true;
                
                frame.Duration.Field = 0x1234;
                
                frame.SequenceControl.SequenceNumber = 0x77;
                frame.SequenceControl.FragmentNumber = 0x1;
                
                frame.CapabilityInformation.Privacy = true;
                frame.CapabilityInformation.ChannelAgility = true;
                
                frame.UpdateFrameCheckSequence ();
                UInt32 fcs = frame.FrameCheckSequence;
                
                //serialize the frame into a byte buffer
                var bytes = frame.Bytes;
                var bas = new ByteArraySegment (bytes);

                //create a new frame that should be identical to the original
                ReassociationRequestFrame recreatedFrame = MacFrame.ParsePacket (bas) as ReassociationRequestFrame;
                recreatedFrame.UpdateFrameCheckSequence ();
                
                Assert.AreEqual (FrameControlField.FrameSubTypes.ManagementReassociationRequest, recreatedFrame.FrameControl.SubType);
                Assert.IsFalse (recreatedFrame.FrameControl.ToDS);
                Assert.IsTrue (recreatedFrame.FrameControl.FromDS);
                Assert.IsTrue (recreatedFrame.FrameControl.MoreFragments);
                
                Assert.AreEqual (0x77, recreatedFrame.SequenceControl.SequenceNumber);
                Assert.AreEqual (0x1, recreatedFrame.SequenceControl.FragmentNumber);
                
                Assert.IsTrue (recreatedFrame.CapabilityInformation.Privacy);
                Assert.IsTrue (recreatedFrame.CapabilityInformation.ChannelAgility);
                
                Assert.AreEqual ("111111111111", recreatedFrame.SourceAddress.ToString ().ToUpper ());
                Assert.AreEqual ("222222222222", recreatedFrame.DestinationAddress.ToString ().ToUpper ());
                Assert.AreEqual ("333333333333", recreatedFrame.BssId.ToString ().ToUpper ());
                
                Assert.AreEqual (fcs, recreatedFrame.FrameCheckSequence);
            }
			public void Test_ConstructorWithCorruptBuffer ()
			{
				//buffer is way too short for frame. We are just checking it doesn't throw
				byte[] corruptBuffer = new byte[]{0x01};
				ReassociationRequestFrame frame = new ReassociationRequestFrame(new ByteArraySegment(corruptBuffer));
				Assert.IsFalse(frame.FCSValid);
			}