Пример #1
0
        /// <summary>
        /// Provides the description from the system for the inputted device
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public String ProvideCaptureDeviceDescription(LivePacketDevice device = null)
        {
            // if the device is valid
            if (device != null)
            {
                return(LivePacketDeviceExtensions.GetNetworkInterface((LivePacketDevice)device).Description);
            }

            return("No available Description.");
        }
Пример #2
0
        /// <summary>
        /// Sends a command through selected network device on layer 1
        /// </summary>
        /// <param name="cmd">command object</param>
        /// <param name="destinationMAC">the Manufacturer Device's MAC address</param>
        static void PacketSender(command cmd, string destinationMAC)
        {
            Console.WriteLine("Select which device to send packet through");
            // Retrieve the device list from the local machine
            IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }
            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];

                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                {
                    Console.WriteLine(" (" + device.Description + ")");
                }
                else
                {
                    Console.WriteLine(" (No description available)");
                }
            }

            int deviceIndex = 0;

            do
            {
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + ") to send through:");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the device
            using (PacketCommunicator communicator =
                       selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                                   // 65536 guarantees that the whole packet will be captured on all the link layers
                                           PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                           1000))                                  // read timeout
            {
                int    commandId    = db.commands.Where(c => c.Value.commandName.ToLower() == cmd.commandName.ToLower()).Select(c => c.Key).FirstOrDefault();
                Packet packetToSend = BuildEthernetPacket(LivePacketDeviceExtensions.GetMacAddress(allDevices[deviceIndex - 1]).ToString(), destinationMAC, utilities.CreateCommandBytesForSending(commandId, cmd.arguments));
                communicator.SendPacket(packetToSend);
            }
        }
Пример #3
0
        static void notifySpoof(LivePacketDevice selectedDevice, string notifyString, string sourceIP, ushort sourcePort, string destIP, ushort destPort)
        {
            byte[] temp = System.Text.Encoding.ASCII.GetBytes(notifyString);



            EthernetLayer ethernetLayer = new EthernetLayer
            {
                Source      = LivePacketDeviceExtensions.GetMacAddress(selectedDevice),
                Destination = new MacAddress("01:00:5E:7F:FF:FA"),
                EtherType   = EthernetType.None,
            };

            IpV4Layer ipV4Layer = new IpV4Layer
            {
                Source             = new IpV4Address(sourceIP),
                CurrentDestination = new IpV4Address(destIP),
                Fragmentation      = IpV4Fragmentation.None,
                HeaderChecksum     = null,

                Identification = 1,
                Options        = IpV4Options.None,
                Protocol       = null,
                Ttl            = 64,
                TypeOfService  = 0,
            };

            UdpLayer udpLayer = new UdpLayer
            {
                SourcePort             = sourcePort,
                DestinationPort        = destPort,
                Checksum               = null,
                CalculateChecksumValue = true,
            };

            PayloadLayer payloadLayer = new PayloadLayer
            {
                Data = new Datagram(temp),
            };

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

            using (PacketCommunicator communicator = selectedDevice.Open(69559, PacketDeviceOpenAttributes.Promiscuous, 1000)) // read timeout
            {
                communicator.SendPacket(builder.Build(DateTime.Now));
            }
        }
Пример #4
0
        /*
         * Function that will list network interface descriptions in the combo box drop down
         *
         */
        private void ListNetworkInterfaces(int numTries = 5)
        {
            //Detect all interfaces
            allLivePacketDevices = LivePacketDevice.AllLocalMachine;
            string descript = "";

            string inactiveFormat = "{0,27} | {1}";   // format for interfaces that are not currently active
            string activeFormat   = "* {0,17} | {1}"; // format for interfaces that are actively transmitting packets
            string Format         = inactiveFormat;

            //Try the allotted number of times if no interfaces detected
            if (allLivePacketDevices.Count == 0)
            {
                if (numTries > 0)
                {
                    ListNetworkInterfaces(--numTries);
                }
            }

            // Describe each network interface
            for (int i = 0; i < allLivePacketDevices.Count; ++i)
            {
                // Determine the network interface for this interface
                LivePacketDevice livePacketDevice = allLivePacketDevices[i];
                NetworkInterface nic = LivePacketDeviceExtensions.GetNetworkInterface(livePacketDevice);

                string address = "";
                // Query system for description
                descript = nic.Description;

                if (nic != null)
                {
                    // Gather the unique ip properties of this interface
                    IPInterfaceProperties ipprops = nic.GetIPProperties();
                    UnicastIPAddressInformationCollection unicast = ipprops.UnicastAddresses;

                    string lpdAddr = "";
                    string nicAddr = "";

                    // search the interfaces IP addresses for it's IPv4 address
                    foreach (UnicastIPAddressInformation uni in unicast)
                    {
                        nicAddr = uni.Address.ToString();

                        foreach (DeviceAddress addr in livePacketDevice.Addresses)
                        {
                            if (!addr.Address.ToString().Contains("Internet6"))
                            {
                                string[] ipv4addy = addr.Address.ToString().Split();
                                lpdAddr = ipv4addy[1];
                            }

                            if (nicAddr == lpdAddr)
                            {
                                address = nicAddr;
                                //needs tuning so active device will be default shown


                                // Format the description according to activity level
                                Format = inactiveFormat;
                                if (nic.OperationalStatus == OperationalStatus.Up)
                                {
                                    Format = activeFormat;
                                    //  ++activeIndex;
                                }
                            }
                        }
                    }
                }

                descript = String.Format(Format, address, descript);
                cmbInterfaces.Items.Add(descript);
            }
        }
Пример #5
0
 public void GetNetworkInterfaceNullTest()
 {
     Assert.IsNotNull(LivePacketDeviceExtensions.GetNetworkInterface(null));
     Assert.Fail();
 }
Пример #6
0
        static void PacketListener()
        {
            // Retrieve the device list from the local machine
            IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }
            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];

                Console.Write((i + 1) + ". " + device.Name);
                if (device.Description != null)
                {
                    Console.WriteLine(" (" + device.Description + ")");
                }
                else
                {
                    Console.WriteLine(" (No description available)");
                }
            }

            int deviceIndex = 0;

            do
            {
                Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the device
            using (PacketCommunicator communicator =
                       selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                                   // 65536 guarantees that the whole packet will be captured on all the link layers
                                           PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                           1000))                                  // read timeout
            {
                Console.WriteLine("Listening on " + selectedDevice.Description + " with MAC address of " + LivePacketDeviceExtensions.GetMacAddress(allDevices[deviceIndex - 1]) + "...");

                // start the capture
                communicator.ReceivePackets(0, PacketHandler);
            }
        }