Ejemplo n.º 1
0
        private void BeginSelectInf_Click(object sender, RoutedEventArgs e)
        {
            Devices = LibPcapLiveDeviceList.Instance;

            if (Devices.Count < 1)
            {
                Config_Message.Content = "No devices were found on this machine";
                return;
            }
            List <string> ConfigComBoxItems = new List <string>();
            int           i = 0;

            ConfigComBoxItems.Add("Select the interface here but me...");
            foreach (var dev in Devices)
            {
                if (dev.Interface.Addresses.Count == 0)
                {
                    ConfigComBoxItems.Add(i.ToString() + ":");
                }
                else
                {
                    ConfigComBoxItems.Add(i.ToString() + ":" + dev.Interface.FriendlyName + "@" + dev.Interface.Addresses[1].Addr);
                }
                i++;
            }
            ConfigComBox.ItemsSource   = ConfigComBoxItems;
            ConfigComBox.SelectedIndex = 0;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化获取网卡列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            richTextBox1.LoadFile("Law.rtf");

            try
            {
                devicesList = LibPcapLiveDeviceList.Instance;
                //显示网卡详细信息
                //for (int i = 0; i < devicesList.Count; i++)
                //{
                //    MessageBox.Show(devicesList[i].ToString());
                //}

                if (devicesList.Count < 1)
                {
                    throw new Exception("没有发现本机上的网络设备");
                }

                device = devicesList[0];

                combDevice.DataSource = devicesList;
            }
            catch
            {
                MessageBox.Show("你没有安装WinPcap,请在打开的网站中下载安装WinPacp后,重启本软件");
                System.Diagnostics.Process.Start("https://www.winpcap.org/");
            }//获取本机所有网卡
        }
Ejemplo n.º 3
0
        private void Start()
        {
            Debug.Assert(_devices == null);
            _devices = LibPcapLiveDeviceList.New();
            var interestingDevices = _devices.Where(IsInteresting);

            foreach (var device in interestingDevices)
            {
                device.OnPacketArrival += device_OnPacketArrival;

                try { device.Open(DeviceMode.Normal, 100); }
                catch (Exception e)
                {
                    Logger.Warn($"Failed to open device {device.Name}. {e.Message}");
                    continue;
                }
                device.Filter = _filter;

                /*
                 * if (BufferSize != null)
                 * {
                 *  try { device.KernelBufferSize = (uint) BufferSize.Value; }
                 *  catch (Exception e) { Logger.Warn($"Failed to set KernelBufferSize to {BufferSize.Value} on {device.Name}. {e.Message}"); }
                 * }
                 */
                device.StartCapture();
                Console.WriteLine("winpcap capture");
            }
        }
Ejemplo n.º 4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            deviceList = LibPcapLiveDeviceList.Instance;

            if (deviceList.Count < 1)
            {
                throw new Exception("没有发现本机上的网络设备");
            }

            foreach (var device in deviceList)
            {
                try
                {
                    arpTool = new ArpTool(device);
                    arpTool.ScanStopedEvent += delegate { this.Dispatcher.BeginInvoke(new Action(async delegate { tit.Text = "IP扫描完成"; await Task.Delay(3000); tit.Text = "请选择要攻击的IP"; sra.Text = "搜索"; })); };
                    arpTool.ResolvedEvent   += arpTool_ResolvedEvent;
                    tit.Text  = "网关IP: " + arpTool.GetwayIP + "  本地IP: " + arpTool.LocalIP;
                    stip.Text = clip.Text = arpTool.GetwayIP.ToString();
                    if (arpTool.GetwayIP.ToString() != "")
                    {
                        return;
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public PacketSniffer()
        {
            try
            {
                // Get list of all connected devices
                deviceList = LibPcapLiveDeviceList.Instance;
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(App.translation["sniffer.dllMissingText"], App.translation["sniffer.dllMissingCaption"], MessageBoxButton.OK, MessageBoxImage.Error);
            }



            if (deviceList == null)
            {
                noNetworkDevice = true;
                System.Windows.MessageBox.Show(App.translation["messageBox.noDeviceText"], App.translation["messageBox.noDeviceCaption"], MessageBoxButton.OK, MessageBoxImage.Error);
            }

            snifferWorker = new BackgroundWorker();

            snifferWorker = new BackgroundWorker();
            snifferWorker.WorkerReportsProgress      = true;
            snifferWorker.WorkerSupportsCancellation = true;
            snifferWorker.DoWork             += new DoWorkEventHandler(RunPacketSniffer);
            snifferWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerCompleted);

            ewh = new EventWaitHandle(false, EventResetMode.AutoReset);

            packetQueue = new Queue <DataPacket>();
        }
Ejemplo n.º 6
0
 public IpSnifferWinPcap(string filter)
 {
     _filter    = filter;
     BufferSize = 1 << 24;
     _devices   = LibPcapLiveDeviceList.New();
     //BasicTeraData.LogError(string.Join("\r\n",_devices.Select(x=>x.Description)),true,true);
     //check for winpcap installed if not - exception to fallback to rawsockets
     _devices = null;
 }
Ejemplo n.º 7
0
        protected override void OnStarting()
        {
            if (Target.IpAddress.Equals(Sender.IpAddress))
            {
                throw new Exception("Target and Sender can't be same");
            }

            _device = LibPcapLiveDeviceList.New()[Device.Name];
        }
Ejemplo n.º 8
0
        public void ListTest()
        {
            var dl = LibPcapLiveDeviceList.New();

            // test that we can look up devices by name
            foreach (var d in dl)
            {
                Assert.IsNotNull(dl[d.Name]);
            }
        }
Ejemplo n.º 9
0
        public static ICaptureDevice GetNcard(PhysicalAddress mac)
        {
            try
            {
                string osType = Environment.OSVersion.Platform.ToString();
                LibPcapLiveDeviceList allDev = LibPcapLiveDeviceList.Instance;
                LibPcapLiveDevice     device = allDev[0];
                _log.DebugFormat("Trying to get NIC by address {0}", mac.ToString());
                _log.Debug("List all device : ");
                foreach (LibPcapLiveDevice nCard in allDev)
                {
                    _log.DebugFormat("Name {0}. Address count :{1}", nCard.Name, nCard.Interface.Addresses.Count);
                    if (osType.ToUpper().Contains("WIN"))
                    {
                        //VLan enabled
                        if (nCard.Addresses.Count == 0)
                        {
                            device = nCard;
                            _log.Info("Get vlan nCard: " + device.Name);
                            break;
                        }

                        //VLan disabled
                        foreach (var addr in nCard.Addresses)
                        {
                            if (addr.Addr.hardwareAddress != null && mac.Equals(addr.Addr.hardwareAddress))
                            {
                                device = nCard;
                            }
                        }
                    }
                    else
                    {
                        if (!nCard.Name.Contains("."))
                        {
                            foreach (var addr in nCard.Addresses)
                            {
                                if (addr.Addr.hardwareAddress != null && mac.Equals(addr.Addr.hardwareAddress))
                                {
                                    device = nCard;
                                }
                            }
                        }
                    }
                }
                _log.DebugFormat("Get NIC : " + device.Name + " System is : " + osType);
                return(device);
            }
            catch (NullReferenceException ex)
            {
                Exception msg = new Exception("Can't Get Ncard");
                _log.Error("Have null ref, maybe macaddress in app.config incorrect Error is :" + ex.Message);
                throw msg;
            }
        }
Ejemplo n.º 10
0
        private void Finish()
        {
            Debug.Assert(_devices != null);
            foreach (var device in _devices.Where(device => device.Opened))
            {
                try { device.StopCapture(); }
                catch
                {
                    // ignored
                }

                //SharpPcap.PcapException: captureThread was aborted after 00:00:02 - it's normal when there is no traffic while stopping
                device.Close();
            }
            _devices = null;
        }
Ejemplo n.º 11
0
 private bool loadCaptureDeviceList()
 {
     try
     {
         capture_devices = LibPcapLiveDeviceList.Instance;
         if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
         {
             capture_devices_win = WinPcapDeviceList.Instance;
         }
     }
     catch (Exception)
     {
         xbs_messages.addInfoMessage("!! ERROR while getting Pcap capture device list.", xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
     }
     return(capture_devices.Count > 0);
 }
Ejemplo n.º 12
0
            // tbd: want to automatically open device, if only one is available?
            void init( )
            {
                listeners = new List<MessageReplyListener>();
                targetMAC = null;
                device = null;
                // Retrieve the device list
                devices = SharpPcap.LibPcap.LibPcapLiveDeviceList.Instance;

                // If no devices were found print an error
                if (devices.Count < 1)
                {
                    Console.WriteLine("No devices were found on this machine");
                    return;
                }

            }
Ejemplo n.º 13
0
        private void Interfaces_Load(object sender, EventArgs e)
        {
            LibPcapLiveDeviceList devices = LibPcapLiveDeviceList.Instance;

            foreach (LibPcapLiveDevice device in devices)
            {
                if (!device.Interface.Addresses.Exists(a => a != null && a.Addr != null && a.Addr.ipAddress != null))
                {
                    continue;
                }
                var devInterface = device.Interface;
                var friendlyName = devInterface.FriendlyName;
                var description  = devInterface.Description;

                interfaceList.Add(device);
                mInterfaceCombo.Items.Add(friendlyName);
            }
        }
Ejemplo n.º 14
0
        public void Start()
        {
            if (IsRunning)
            {
                return;
            }

            device = LibPcapLiveDeviceList.New()[Device.Name];

            device.Open(DeviceMode.Promiscuous, 50);

            device.Filter = "(ether dst " + device.MacAddress + ") and ip and " +
                            "(not dst " + NetUtils.GeIPv4Address(device) + ")";

            device.OnPacketArrival += OnPacketArrival;
            device.StartCapture();
            IsRunning = true;
        }
Ejemplo n.º 15
0
        private void PraisedSnifferForm_Load(object sender, EventArgs e)
        {
            LibPcapLiveDeviceList devices = LibPcapLiveDeviceList.Instance;

            foreach (var device in devices)
            {
                if (!device.Interface.Addresses.Exists(a => a != null && a.Addr != null && a.Addr.ipAddress != null))
                {
                    continue;
                }
                var devInterface = device.Interface;
                var friendlyName = devInterface.FriendlyName;
                var description  = devInterface.Description;

                interfaceList.Add(device);
                mInterfaces.Items.Add(friendlyName);
            }
            listPackets.Columns.Add("Item", 1);
            listPackets.Columns.Add("Origem", 200, HorizontalAlignment.Center);
            listPackets.Columns.Add("Destino", 200, HorizontalAlignment.Center);
            listPackets.Columns.Add("Protocolo", 70, HorizontalAlignment.Center);

            if (Properties.Settings.Default.DbFile == null || Properties.Settings.Default.DbFile == "")
            {
                if (MessageBox.Show("Nenhum arquivo de banco de dados foi carregado, deseja carrega-lo agora ?",
                                    "Carregar arquivo",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    LoadIp2l("");
                }
                else
                {
                    WarnIp2lNotLoadeded();
                }
            }
            else
            {
                LoadIp2l(Properties.Settings.Default.DbFile);
            }

            Focus();
        }
Ejemplo n.º 16
0
        private LibPcapHandler()
        {
            m_Instance   = this;
            m_DeviceName = NetworkUtils.GetInterfaceName();
            LibPcapLiveDeviceList devices = LibPcapLiveDeviceList.Instance;

            foreach (LibPcapLiveDevice dev in devices)
            {
                if (dev.Name.Equals(m_DeviceName))
                {
                    m_Device = dev;
                }
            }
            if (m_Device == null)
            {
                throw new Exception("No Device found");
            }
            m_Device.Open();
            m_Device.Close();
        }
Ejemplo n.º 17
0
        private void PraisedSnifferForm_Load(object sender, EventArgs e)
        {
            LibPcapLiveDeviceList devices = LibPcapLiveDeviceList.Instance;

            foreach (var device in devices)
            {
                if (!device.Interface.Addresses.Exists(a => a != null && a.Addr != null && a.Addr.ipAddress != null))
                {
                    continue;
                }
                var devInterface = device.Interface;
                var friendlyName = devInterface.FriendlyName;
                var description  = devInterface.Description;

                interfaceList.Add(device);
                mInterfaces.Items.Add(friendlyName);
            }
            listPackets.Columns.Add("Item", 1);
            listPackets.Columns.Add("Origem", 200, HorizontalAlignment.Center);
            listPackets.Columns.Add("Destino", 200, HorizontalAlignment.Center);
            listPackets.Columns.Add("Protocolo", 70, HorizontalAlignment.Center);
        }
Ejemplo n.º 18
0
 private bool loadCaptureDeviceList()
 {
     try
     {
         capture_devices = LibPcapLiveDeviceList.Instance;
             if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
                 capture_devices_win = WinPcapDeviceList.Instance;
     }
     catch (Exception)
     {
         xbs_messages.addInfoMessage("!! ERROR while getting Pcap capture device list.", xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
     }
     return (capture_devices.Count > 0);
 }