static void Main(string[] args) { Console.WriteLine("Hello."); monitor m1 = new monitor(); scan s1 = new scan(); dbwork db = new dbwork(); string dbaddress=null; try { dbaddress = db.getdbparam("config.txt").GetValue(1).ToString(); } catch (System.IO.FileNotFoundException) { Console.WriteLine("Config file is not found"); Console.ReadKey(); return; } try { db.tableexist(dbaddress, "hosts"); } catch (InvalidOperationException) { Console.WriteLine("You have no AccessDatabaseEngine. Contact your administrator."); Console.ReadKey(); return; } Console.WriteLine("Database file at "+dbaddress+"\n"); if (args.Length == 0) { m1.checknow(); } else { if (args[0] == "scantd") { s1.scannow(); return; } if (args[0] == "deltd") { Console.WriteLine("Now table forscan delete"); try { db.droptdforscandb(dbaddress, "forscan"); } catch (System.Data.OleDb.OleDbException) { Console.WriteLine("Can not delete"); return; } Console.WriteLine("Complite.\nWrite new cfg"); db.setdbparam("config.txt", 2, "scanstopnow"); Console.WriteLine("Done\nGood bye."); Thread.Sleep(3000); return; } if (args[0] == "check") { m1.checknow(); return; } } }
static void Main(string[] args) { Console.WriteLine("Hello."); monitor m1 = new monitor(); scan s1 = new scan(); dbwork db = new dbwork(); string dbaddress = null; try { dbaddress = db.getdbparam("config.txt").GetValue(1).ToString(); } catch (System.IO.FileNotFoundException) { Console.WriteLine("Config file is not found"); Console.ReadKey(); return; } try { db.tableexist(dbaddress, "hosts"); } catch (InvalidOperationException) { Console.WriteLine("You have no AccessDatabaseEngine. Contact your administrator."); Console.ReadKey(); return; } Console.WriteLine("Database file at " + dbaddress + "\n"); if (args.Length == 0) { m1.checknow(); } else { if (args[0] == "scantd") { s1.scannow(); return; } if (args[0] == "deltd") { Console.WriteLine("Now table forscan delete"); try { db.droptdforscandb(dbaddress, "forscan"); } catch (System.Data.OleDb.OleDbException) { Console.WriteLine("Can not delete"); return; } Console.WriteLine("Complite.\nWrite new cfg"); db.setdbparam("config.txt", 2, "scanstopnow"); Console.WriteLine("Done\nGood bye."); Thread.Sleep(3000); return; } if (args[0] == "check") { m1.checknow(); return; } } }
public static void attackLog(scan s) { StreamWriter wr = null; try { wr = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "AttacksDB.txt", true); wr.WriteLine(DateTime.Now.ToString() + ": " + "Attacke Name : {0} , Time : {1} , Attacker HardwareAddress : {2} , Attacker ip address : {3} ", s.Attack_data[0], s.Attack_data[3], s.Attack_data[2], s.Attack_data[1]); wr.Flush(); wr.Close(); } catch (Exception) { throw; } }
static void device_OnPacketArrival(object sender, CaptureEventArgs e) { // check router // ado a = new ado(); // DataTable dt = a.selectname("Router", Hinter.Replace("'", "")); scan s = new scan(); if (RunArp == true) { s.ScanAttack(e, Hinter, Rip); } if (RunDhcp == true) { s.ScanDhcp(e, Hinter); } if (s.Attack == true) { for (int i = 0; i < 3; i++) { System.Media.SystemSounds.Hand.Play(); Console.WriteLine("********************* You Have Been Attacked **************************"); Console.WriteLine(Environment.NewLine); Console.WriteLine("Attack Name : {0} , Time : {1} , Attacker HardwareAddress : {2} , Attacker ip address : {3} ", s.Attack_data[0], s.Attack_data[3], s.Attack_data[2], s.Attack_data[1]); Console.WriteLine(Environment.NewLine); if (s.Attack_data[0] == "arp spofing") { Console.WriteLine("Old data {0} {1} {2} {3} ", s.Attack_data[4], s.Attack_data[5], s.Attack_data[6], s.Attack_data[7]); } System.Media.SystemSounds.Hand.Play(); } // Save to DB log.attackLog(s); } //throw new NotImplementedException(); var txt = File.ReadAllLines("ports.port"); var tcp = (from t in txt where t.Contains("tcp") select t).ToArray(); //var comments = (from t in txt where t.StartsWith("#") select t).ToArray(); /* foreach (var item in tcp) * { * int inte = Array.IndexOf(tcp,item); * string cm = txt[inte+1]; * * string r = item.Replace("tcp", ""); * int p = Convert.ToInt16(r); * * if (cm.StartsWith("#")) * { * * scanTCP(e, p, cm); * } * else * { * string commend = "You Are Using insecur Protocol"; * scanTCP(e, p, commend); * } * * * * * }*/ /* var udp = (from t in txt where t.Contains("udp") select t).ToArray(); * foreach (var item in udp) * { * // comment * int inte = Array.IndexOf(udp, item); * * string cm = txt[inte + 1]; * * string r = item.Replace("udp", ""); * int p = Convert.ToInt16(r); * //scanUDP(e, p); * if (cm.StartsWith("#")) * { * * scanUDP(e, p, cm); * throw new Exception(""); * } * else * { * string commend = "You Are Using insecur Protocol"; * scanUDP(e, p, commend); * } * }*/ if (scan == true) { foreach (var item in txt) { //tcp if (item.Contains("tcp")) { int inte = Array.IndexOf(txt, item); string cm = txt[inte + 1]; string r = item.Replace("tcp", ""); int p = Convert.ToInt16(r); if (cm.StartsWith("#")) { scanTCP(e, p, cm); // throw new Exception(""); } else { string commend = "You Are using non - encrypted Clear Text Protocol Pleas Use secure Protocol"; scanTCP(e, p, commend); } } // udp if (item.Contains("udp")) { // comment int inte = Array.IndexOf(txt, item); string cm = txt[inte + 1]; string r = item.Replace("udp", ""); int p = Convert.ToInt16(r); if (cm.StartsWith("#")) { scanUDP(e, p, cm); // if you need error use this commend // throw new Exception(""); } else { string commend = "You Are using non-encrypted Clear Text Protocol Pleas Use secure Protocol"; scanUDP(e, p, commend); } } } } }
static void device_OnPacketArrival(object sender, CaptureEventArgs e) { scan s = new scan(); if (RunArp == true) { s.ScanAttack(e, Hinter, Rip); } if (RunDhcp == true) { s.ScanDhcp(e, Hinter); } if (s.Attack == true) { for (int i = 0; i < 3; i++) { System.Media.SystemSounds.Hand.Play(); Console.WriteLine("********************* You Have Been Attacked **************************"); Console.WriteLine(Environment.NewLine); Console.WriteLine("Attack Name : {0} , Time : {1} , Attacker HardwareAddress : {2} , Attacker ip address : {3} ", s.Attack_data[0], s.Attack_data[3], s.Attack_data[2], s.Attack_data[1]); Console.WriteLine(Environment.NewLine); Console.WriteLine("Old data {0} {1} {2} {3} ", s.Attack_data[4], s.Attack_data[5], s.Attack_data[6], s.Attack_data[7]); System.Media.SystemSounds.Hand.Play(); } log.attackLog(s); } var txt = File.ReadAllLines("ports.port"); var tcp = (from t in txt where t.Contains("tcp") select t).ToArray(); if (scan == true) { foreach (var item in txt) { if (item.Contains("tcp")) { int inte = Array.IndexOf(txt, item); string cm = txt[inte + 1]; string r = item.Replace("tcp", ""); int p = Convert.ToInt16(r); if (cm.StartsWith("#")) { scanTCP(e, p, cm); } else { string commend = "您正在使用非加密的明文协议请求使用安全协议"; scanTCP(e, p, commend); } } if (item.Contains("udp")) { int inte = Array.IndexOf(txt, item); string cm = txt[inte + 1]; string r = item.Replace("udp", ""); int p = Convert.ToInt16(r); if (cm.StartsWith("#")) { scanUDP(e, p, cm); } else { string commend = "您正在使用非加密的明文协议请求使用安全协议"; scanUDP(e, p, commend); } } } } }