public Switch(WinPcapDevice dev1, WinPcapDevice dev2) { this.dev1 = dev1; this.dev2 = dev2; dev1.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival1); ////dev1.Open(DeviceMode.Normal, 1000); dev1.Open(OpenFlags.Promiscuous | OpenFlags.NoCaptureLocal, 10); dev1.StartCapture(); dev2.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival1); ////dev2.Open(DeviceMode.Normal, 1000); dev2.Open(OpenFlags.Promiscuous | OpenFlags.NoCaptureLocal, 10); dev2.StartCapture(); Thread t1 = new Thread(() => timer()); t2 = new Thread(() => sendPacketLLDP(dev1, '1')); t3 = new Thread(() => sendPacketLLDP(dev2, '2')); t4 = new Thread(() => lldpTime()); t1.Start(); t2.Start(); t3.Start(); t4.Start(); }
private void btAccept_Click(object sender, EventArgs e) { this.DialogResult = System.Windows.Forms.DialogResult.OK; this.device = (WinPcapDevice)dgvInterfaces.SelectedRows[0].Tag; this.Close(); SaveSettingsInterface(); }
public SlaacMITM(WinPcapDevice device, IList <Data.Attack> attacks) { this.device = device; this.attacks = attacks; invalidMac = PhysicalAddress.Parse("00-00-00-00-00-00"); }
static void Main(string[] args) { var devices = CaptureDeviceList.Instance; device = (WinPcapDevice)devices[0]; device.Open(); //Generate a random packet Packet bytes = CreateMalwarePacket(); string byteString = ""; byte[] bytesP = bytes.Bytes; foreach (byte b in bytesP) { byteString += Convert.ToString(b, 2); } Thread t = new Thread(new ParameterizedThreadStart(SendPacket)); t.Start(bytes); while (true) { Thread.Sleep(1000); } t.Abort(); Thread.Sleep(1000); device.Close(); Console.WriteLine("-- Device closed."); Console.Write("Hit 'Enter' to exit..."); Console.ReadLine(); }
private void lbxWinPcapDeviceListI_SelectionChanged(object sender, SelectionChangedEventArgs e) { gbxDevInfoI.Visibility = Visibility.Visible; devo = lbxWinPcapDeviceListI.SelectedItem as WinPcapDevice; gbxDevInfo.DataContext = devo; lbxAdressesI.ItemsSource = devo.Addresses; }
/// <summary> /// Starts the target manager thread. /// </summary> public void Start() { Messages.Trace("starting communications manager"); // get the packet capture device CaptureDeviceList devices = CaptureDeviceList.Instance; capDevice = devices[Program.interfaceToUse]; Messages.Trace("using [" + capDevice.Description + "] for network capture"); capDevice.OnPacketArrival += capDevice_OnPacketArrival; if (capDevice is WinPcapDevice) { WinPcapDevice winPcap = capDevice as WinPcapDevice; winPcap.Open(OpenFlags.Promiscuous | OpenFlags.NoCaptureLocal | OpenFlags.MaxResponsiveness, readTimeoutMilliseconds); } else if (capDevice is LibPcapLiveDevice) { LibPcapLiveDevice livePcapDevice = capDevice as LibPcapLiveDevice; livePcapDevice.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds); } else { throw new InvalidOperationException("unknown device type of " + capDevice.GetType().ToString()); } capDevice.StartCapture(); // start loop runThread = true; commMgrThread.Start(); }
private TcpSynPortScanner(string hostName) { timeout = 5000; localIp = NetworkUtils.GetLocalHostIP(); localPort = (ushort)new Random().Next(20000, 50000); device = NetworkUtils.GetActiveDevice(localIp); localMacAddress = device.Interface.MacAddress; destinationIp = NetworkUtils.ResolveHostName(hostName); var tryCount = 8; while (--tryCount > 0) { destinationMacAddress = NetworkUtils.GetMacAddress(destinationIp); if (!Equals(destinationMacAddress, new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 }))) { break; } Thread.Sleep(500 / tryCount); } if (destinationMacAddress == null) { throw new Exception("Destination MAC can't be null"); } device.Open(DeviceMode.Promiscuous, 100); ConfigureWinPcapDevice(); }
public static string getGAtWatWayMac(WinPcapDevice dev) { RawCapture packet; // Capture packets using GetNextPacket() while ((packet = dev.GetNextPacket()) != null) { var mypacket = Packet.ParsePacket(packet.LinkLayerType, packet.Data); var arp = (ARPPacket)mypacket.Extract(typeof(ARPPacket)); if (arp != null) { // get arp rep if (arp.Operation == ARPOperation.Response) { if (arp.SenderProtocolAddress.Address == dev.Interface.GatewayAddress.Address) { return(arp.SenderHardwareAddress.ToString()); } } } } return(""); }
private void toolBtn_StartCapture_Click(object sender, EventArgs e) { if (deviceIndex == -1) { MessageBox.Show("请选择要拦截封包的网卡!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } WinPcapDeviceList device = WinPcapDeviceList.Instance; CaptureDevice = device[deviceIndex]; backgroundThread = new Thread(BackgroundThread); BackgroundThreadStop = true; backgroundThread.IsBackground = true; backgroundThread.Name = "CapturePackets"; backgroundThread.Start(); CaptureDevice.Open(); if (this.filterRules != "") { CaptureDevice.Filter = this.filterRules; } else { CaptureDevice.Filter = "port 8484"; } CaptureDevice.OnPacketArrival += captureDevice_OnPacketArrival; CaptureDevice.StartCapture(); toolBtn_StartCapture.Enabled = false; toolBtn_StopCapture.Enabled = true; toolBtn_SetAdapter.Enabled = false; }
// start listening on a device (combobox index) public void StartDevice(int deviceIndex) { Started = true; DeviceInfo = DeviceInfoList[deviceIndex]; Device = WinPcapDeviceList.Instance[deviceIndex]; Sniffer = new Sniffer(DeviceInfo); ARPTools = new ARPTools(DeviceInfo); NDTools = new NDTools(DeviceInfo); SSLStrip = new SSLStrip(); Scanner = new Scanner(DeviceInfo); Sniffer.SnifferResult += new SnifferResultHandler(sniffer_OnSnifferResult); Scanner.ScannerResponse += new ScannerResponseReceived(scanner_OnResponse); Scanner.ScanComplete += new ScannerEventHandler(scanner_OnScanComplete); Scanner.HostnameResolved += new ScannerHostnameResolvedHandler(scanner_HostnameResolved); SSLStrip.SSLStripped += new SSLStripHandler(SSLStrip_OnSSLStripped); // open device, set filters & events, start capturing Device.Open(DeviceMode.Promiscuous, 1); Device.Filter = "(arp || ip || ip6)"; Device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival); Device.StartCapture(); }
private void button1_Click(object sender, EventArgs e) { WinPcapDevice PcapDevice = WinPcapDeviceList.Instance[comboBox1.SelectedIndex]; ARP req = new ARP((LibPcapLiveDevice)CaptureDeviceList.Instance[comboBox1.SelectedIndex]); Console.Out.WriteLine(PcapDevice.Addresses[1]); req.Timeout = new System.TimeSpan(1200000); IPAddress target = null; IPAddress.TryParse(networkText.Text, out target); int retry = 5; string hostMacAddress = null; while (retry > 1 && hostMacAddress == null) { try { hostMacAddress = req.Resolve(target).ToString(); } catch { } retry -= 1; } try { Console.Out.WriteLine(hostMacAddress.ToString()); } catch { } }
public Router(WinPcapDevice dev, SynchronizedCollection <Data.Attack> attacks, SynchronizedCollection <string> slaacReqs) { this.device = dev; this.localPhysicalAddress = device.MacAddress; this.attacks = attacks; //this.slaacReqs = slaacReqs; this.dnsHijacking = new DNSHijacking(dev, attacks); }
public static void Online() { device = WinPcapDeviceList.Instance[1]; device.OnPacketArrival += Device_OnPacketArrival; device.Open(DeviceMode.Normal); captureFileWriter = new CaptureFileWriterDevice("test.pcap"); device.StartCapture(); }
void b_Click(object sender, EventArgs e) { WinPcapDevice device = (WinPcapDevice)((Button)sender).Tag; Form2 form = new Form2(); form.Run(device); form.Show(this); }
public void Run(WinPcapDevice device) { comm = device; device.Open(OpenFlags.Promiscuous, 1, null); comm.Filter = ("arp"); comm.NonBlockingMode = true; lDev.Text = device.Description; }
private void btnSelect_Click(object sender, EventArgs e) { if (cmdAdapters.SelectedItem != null) { Device = _devices[cmdAdapters.SelectedIndex]; DialogResult = DialogResult.OK; Close(); } }
public IPAddress GetIPv4FromDevice(WinPcapDevice device) { foreach (PcapAddress address in ((WinPcapDevice)device).Addresses.Where(A => A.Addr.ipAddress != null && A.Addr.ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)) { return(address.Addr.ipAddress); } return(null); }
private void lbxWinPcapDeviceList_SelectionChanged(object sender, SelectionChangedEventArgs e) { gbxDevInfo.Visibility = Visibility.Visible; WinPcapDevice dev = lbxWinPcapDeviceList.SelectedItem as WinPcapDevice; gbxDevInfo.DataContext = dev; lbxAdresses.ItemsSource = dev.Addresses; gridCapture.Visibility = Visibility.Visible; }
public Sockaddr GetNetmaskFromIP(WinPcapDevice device, IPAddress ipAddress) { foreach (PcapAddress address in device.Addresses.Where(A => A.Addr.ipAddress.Equals(ipAddress))) { return(address.Netmask); } return(null); }
private void button1_Click(object sender, EventArgs e) { PressedYes = true; if (dataListView1.SelectedIndex != -1) { SelectedDevice = _captureDevices[dataListView1.SelectedIndex]; } Close(); }
private void chooseComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (chooseComboBox.SelectedIndex > -1) { startButton.Enabled = true; startToolStrip.Enabled = true; dev = devs[chooseComboBox.SelectedIndex]; } }
/// <summary> /// NetworkInterface constructor accepting a "WinPcapDevice" used for setting appropriate values. /// </summary> /// <param name="device">WinPcapDevice to be used for this interface</param> public NetworkInterface(WinPcapDevice device) : this() { PcapDevice = device; PcapInterface = PcapDevice.Interface; Name = device.Interface.FriendlyName; HardwareName = device.Interface.Description; ParseIPv4Addresses(); }
private void initData() { _device_stat = (WinPcapDevice)Globals.Device; _device = Globals.Device; //packetList.LoadingRow += new EventHandler<C1.WPF.DataGrid.DataGridRowEventArgs>(packetList_loadingRow); packetList.ItemsSource = packetSimpInfos; serviceStackDBHelper = ServiceStackDBHelper.getInstance(); serviceStackDBHelper.ConductBefore(); getPackets(); }
/// <summary> /// A variation to original "Transmit" method accepting "null" queues. /// </summary> public static void TransmitAll(this SendQueue sendQueue, WinPcapDevice device) { if (sendQueue == null) { return; } sendQueue.Transmit(device, SendQueueTransmitModes.Normal); sendQueue.Dispose(); }
public Device(ICaptureDevice icd) { WinPcapDevice win = (WinPcapDevice)icd; this._interface = icd; this._mac = win.MacAddress; this._ip = win.Addresses[0].Addr.ipAddress; this._mask = win.Addresses[0].Netmask.ipAddress; this._net = SoftRouter.GetNetIpAddress(_ip, _mask); this._name = win.Interface.FriendlyName + " " + icd.Description.Split('\'')[1]; }
public void Shutdown() { if (device != null) { device.StopCapture(); device.Close(); device.OnPacketArrival -= arrivalEventHandler; device.OnCaptureStopped -= captureStoppedEventHandler; device = null; } }
// Return the first IPv4 address found for the device private PcapAddress GetIPV4SockAddr(WinPcapDevice device) { foreach (PcapAddress address in device.Addresses) { if (address.Addr.sa_family == AF_INET) { return(address); } } return(null); }
public PasiveScan(WinPcapDevice device, SynchronizedCollection <Data.Attack> attacks, IList <Data.Neighbor> neighbors, SynchronizedCollection <string> slaacReqs) { this.device = device; this.localPhysicalAddress = device.MacAddress; this.attacks = attacks; this.neighbors = neighbors; this.route = new Router(device, attacks, slaacReqs); this.pasivePortScan = new PasivePortScanner(neighbors); /* Ataques pasivos */ this.DHCPACKInjection = new DHCPACKInjection(device, attacks); this.DHCPIpv6 = new DHCPIpv6(device, attacks); }
private void StartCapture(int itemIndex) { packetId = 0; device = CaptureDeviceList.Instance[itemIndex] as WinPcapDevice; arrivalEventHandler = new PacketArrivalEventHandler(OnPacketArrival); device.OnPacketArrival += arrivalEventHandler; captureStoppedEventHandler = new CaptureStoppedEventHandler(OnCaptureStopped); device.OnCaptureStopped += captureStoppedEventHandler; device.Open(OpenFlags.MaxResponsiveness, 1000); device.KernelBufferSize = 104857600; device.Filter = "ip and tcp"; device.StartCapture(); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (_device == null) { // Retrieve the device list CaptureDeviceList devices = CaptureDeviceList.Instance; // If no devices were found print an error if (devices.Count < 1) { return; } List <WinPcapDevice> captureDevices = devices.Where(d => d is WinPcapDevice).Cast <WinPcapDevice>().ToList(); var interfacePicker = new InterfacePicker(captureDevices); interfacePicker.ShowDialog(); if (!interfacePicker.PressedYes) { return; } if (interfacePicker.SelectedDevice == null) { return; } // Print out the available network devices _device = interfacePicker.SelectedDevice; // Register our handler function to the // 'packet arrival' event _device.OnPacketArrival += device_OnPacketArrival; } UpdateStatus("Recording from " + _device.Interface.FriendlyName); // Open the device for capturing var readTimeoutMilliseconds = 1000; _device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds); // Start the capturing process _device.StartCapture(); }