static void Main(string[] args) { // Console.BackgroundColor = ConsoleColor.Red; // Console.ForegroundColor = ConsoleColor.Yellow; Console.Title = "Catch"; Console.WriteLine(@" /$$$$$$ /$$ /$$ /$$__ $$ | $$ | $$ | $$ \__/ /$$$$$$ /$$$$$$ /$$$$$$$| $$$$$$$ | $$ |____ $$|_ $$_/ /$$_____/| $$__ $$ | $$ /$$$$$$$ | $$ | $$ | $$ \ $$ | $$ $$ /$$__ $$ | $$ /$$| $$ | $$ | $$ | $$$$$$/| $$$$$$$ | $$$$/| $$$$$$$| $$ | $$ \______/ \_______/ \___/ \_______/|__/ |__/ "); Console.WriteLine(" Welcome To catch is Host Based Intrusion Detection Systems"); Console.WriteLine(" Catch Mitm Attack and Clear Text Protocols"); Console.WriteLine(" Forged by @mr_128bit using SharpPcap and PacketDotNet"); Console.WriteLine(" Copyright 2017 abdurhman Ibrahim ([email protected])"); Console.WriteLine(" VERSION:1.0"); Console.WriteLine(Environment.NewLine); // chick if data Excet if (!File.Exists("data.sqlite")) { ado o = new ado(); o.creatDB(); } if (!File.Exists("ports.port")) { create_file(); } //======================================== // Print SharpPcap version // string ver = SharpPcap.Version.VersionString; // Console.WriteLine("SharpPcap {0}\n", ver); // Retrieve the device list try { var devic = WinPcapDeviceList.Instance; } catch (Exception) { Console.WriteLine("No interfaces found! Make sure libpcap/WinPcap is properly installed on the local machine."); Thread.Sleep(5000); return; } var devices = WinPcapDeviceList.Instance; // If no devices were found print an error if (devices.Count < 1) { Console.WriteLine("No devices were found on this machine please make sure you have installed a winpcap"); return; } Console.WriteLine("The following devices are available on this machine Please choose one:"); Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine(); int i = 0; // Print out the available devices //if (true) // { // Console.WriteLine("No interfaces found! Make sure libpcap/WinPcap is properly installed on the local machine."); // / // } foreach (var dev in devices) { Console.WriteLine("{0}) {1}", i, dev.Description); Console.WriteLine(Environment.NewLine); i++; } Console.WriteLine(); Console.Write("------ Please choose a device : "); i = int.Parse(Console.ReadLine()); devIndex = i; if (devices.Count < i) { Console.WriteLine("------{0} is incorrect : ", i.ToString()); Console.WriteLine("------ Please choose a device : "); i = int.Parse(Console.ReadLine()); if (devices.Count < i) { return; } // ; } var device = devices[i]; // Console.Write("-- Please Enter IP ADDRESS: "); // string MYIP = Console.ReadLine(); // IPAAA = MYIP.ToString(); device.Open(DeviceMode.Promiscuous, 1000); // pc Data Console.WriteLine(Environment.NewLine); Console.WriteLine("Interface : {0}", device.Description); // var devg = CaptureDeviceList.Instance[devIndex]; //devg.Open(DeviceMode.Promiscuous, 1000); Hip = device.Addresses[1].Addr.ToString(); Hmac = device.MacAddress.ToString(); if (device.Interface.GatewayAddress == null) { Console.WriteLine("You don't have GatewayAddress"); Console.ReadKey(); return; } Hdefullt = device.Interface.GatewayAddress.ToString(); Hinter = device.Description.Replace("'", ""); Console.WriteLine(Environment.NewLine); Console.WriteLine("IP Address : {0}", device.Addresses[1].Addr); Console.WriteLine(Environment.NewLine); Console.WriteLine("MAC Address : {0}", device.MacAddress.ToString()); Console.WriteLine(Environment.NewLine); Console.WriteLine("Defult Gatway : {0}", device.Interface.GatewayAddress); Console.WriteLine(Environment.NewLine); Console.WriteLine("__________________________Router_______________________________"); Console.WriteLine("Router IP Address : {0}", device.Interface.GatewayAddress.ToString()); string gat = device.Interface.GatewayAddress.ToString(); string myip = device.Addresses[1].Addr.ToString(); if (string.IsNullOrEmpty(gat) != null) { EthernetPacket eth = Protect_Arp(device.MacAddress.ToString(), "FFFFFFFFFFFF", myip, gat); device.SendPacket(eth); } Thread th = new Thread(() => { device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival); }); th.Start(); Rmac = getGAtWatWayMac(device); if (string.IsNullOrEmpty(Rmac)) { Console.WriteLine("You are Not connected to Router Try Agin"); Console.ReadKey(); return; } Console.WriteLine("Router MAC Address : {0}", Rmac); Rip = device.Interface.GatewayAddress.ToString(); device.StartCapture(); //------------------------Softwer Stard----------------------------- //====Start IPS -help You See All commend Console.WriteLine(Environment.NewLine); // Inserting data First Check if Excit // add pc ado a = new ado(); if (a.checkpc(Hip, Hmac, Hinter).Rows.Count > 0) { } else { Data d = new Data() { date = DateTime.Now.ToString(), inter = Hinter, name = "Pc", ip = Hip, mac = Hmac }; a.insert(d); } if (a.selectname("Router", Hinter).Rows.Count > 0) { int id = 0; DataTable dt = a.selectname("Router", Hinter); foreach (DataRow item in dt.Rows) { string ip = item[4].ToString(); string mac = item[3].ToString(); string Time = item[5].ToString(); id = Convert.ToInt32(item[0]); if (mac == Rmac) { //Console.WriteLine("Mac {0}", mac); // Console.WriteLine("Rmac {0}", Rmac); } else { cheeck(new ado(), ip, mac, Time, id); } } } else { Data d = new Data() { inter = Hinter, date = DateTime.Now.ToString(), ip = Rip, mac = Rmac, name = "Router" }; a.insert(d); } Runcmd(); // Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine(Environment.NewLine); Console.Title = "入侵检测系统"; Console.WriteLine(@""); Console.WriteLine(@"计算机1621 "); Console.WriteLine(@"1630107137 陈灿婷"); Console.WriteLine(@"入侵检测系统的设计与实现"); Console.WriteLine(Environment.NewLine); if (!File.Exists("data.sqlite")) { ado o = new ado(); o.creatDB(); } if (!File.Exists("ports.port")) { create_file(); } try { var devic = WinPcapDeviceList.Instance; } catch (Exception) { Console.WriteLine("没有发现接口!确保在本地机器上正确安装libpcap /WinPcap."); Thread.Sleep(5000); return; } var devices = WinPcapDeviceList.Instance; if (devices.Count < 1) { Console.WriteLine("在这台机器上没有发现任何设备,请确认你已经安装了winpcap"); return; } Console.WriteLine("请选择一个选项*** :"); Console.WriteLine("********************************"); Console.WriteLine(); int i = 0; foreach (var dev in devices) { Console.WriteLine("{0}) {1}", i, dev.Description); Console.WriteLine(Environment.NewLine); i++; } Console.WriteLine(); Console.Write("***请选择一个选项***: "); i = int.Parse(Console.ReadLine()); devIndex = i; if (devices.Count < i) { Console.WriteLine("***{0} 是不正确的*** : ", i.ToString()); Console.WriteLine("***请选择一个选项*** : "); i = int.Parse(Console.ReadLine()); if (devices.Count < i) { return; } // ; } var device = devices[i]; device.Open(DeviceMode.Promiscuous, 1000); num = 0; foreach (var item in device.Addresses) { if (item.Addr.ipAddress != null) { if (item.Addr.ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { int inf = Array.IndexOf(device.Addresses.ToArray(), item); num = inf; } } } Console.WriteLine(Environment.NewLine); Console.WriteLine("界面 : {0}", device.Description); Hip = device.Addresses[num].Addr.ToString(); Hmac = device.MacAddress.ToString(); if (device.Interface.GatewayAddress == null) { Console.WriteLine("你没有GatewayAddress"); Console.ReadKey(); return; } gat = device.Interface.GatewayAddress.ToString(); Hdefullt = device.Interface.GatewayAddress.ToString(); Hinter = device.Description.Replace("'", ""); Console.WriteLine(Environment.NewLine); Console.WriteLine("IP Address : {0}", device.Addresses[num].Addr); Console.WriteLine(Environment.NewLine); Console.WriteLine("MAC Address : {0}", device.MacAddress.ToString()); if (IPAddress.Parse(gat).AddressFamily == AddressFamily.InterNetworkV6) { Console.WriteLine("Catch不能找到你的网关地址,请输入你的网关地址 : "); var g = Console.ReadLine(); gat = g; } Console.WriteLine(Environment.NewLine); Console.WriteLine("Defult Gatway : {0}", gat); Console.WriteLine(Environment.NewLine); Console.WriteLine("__________________________Router_______________________________"); Console.WriteLine("Router IP Address : {0}", gat); string myip = device.Addresses[num].Addr.ToString(); try { IPAddress address = IPAddress.Parse(gat); } catch (Exception ex) { Console.WriteLine(ex.Message + " " + gat); Thread.Sleep(3000); return; } if (string.IsNullOrEmpty(gat) != null) { EthernetPacket eth = Protect_Arp(device.MacAddress.ToString(), "FFFFFFFFFFFF", myip, gat); device.SendPacket(eth); } Thread th = new Thread(() => { device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival); }); th.Start(); Rmac = getGAtWatWayMac(device, gat); if (Rmac == "") { Console.WriteLine("您没有连接到路由器,重新尝试"); Console.ReadKey(); return; } Console.WriteLine("Router MAC Address : {0}", Rmac); Rip = gat; device.StartCapture(); Console.WriteLine(Environment.NewLine); ado a = new ado(); if (a.checkpc(Hip, Hmac, Hinter).Rows.Count > 0) { } else { Data d = new Data() { date = DateTime.Now.ToString(), inter = Hinter, name = "Pc", ip = Hip, mac = Hmac }; a.insert(d); } if (a.selectname("Router", Hinter).Rows.Count > 0) { int id = 0; DataTable dt = a.selectname("Router", Hinter); foreach (DataRow item in dt.Rows) { string ip = item[4].ToString(); string mac = item[3].ToString(); string Time = item[5].ToString(); id = Convert.ToInt32(item[0]); if (mac == Rmac) { } else { cheeck(new ado(), ip, mac, Time, id); } } } else { Data d = new Data() { inter = Hinter, date = DateTime.Now.ToString(), ip = Rip, mac = Rmac, name = "Router" }; a.insert(d); } Runcmd(); }