public static BlackListResult CheckUrlHash(string hashedUrl) { SQLiteConnection conn = WDB; BlackListResult blackListResult = BlackListResult.NotFound; using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = string.Format("SELECT blacklistid FROM {0} WHERE hash MATCH '{1}';", FileFormat.GetTable(hashedUrl), hashedUrl); object result = cmd.ExecuteScalar(); if (result == null) { blackListResult = BlackListResult.NotFound; } else { int blackListId = Convert.ToInt32(result); int phishingId = 1; if (blackListId == phishingId) { blackListResult = BlackListResult.PhishingAttack; } else if (blackListId == 3) { blackListResult = BlackListResult.PornAttack; } else { blackListResult = BlackListResult.MalwareAttack; } } } return(blackListResult); }
static void Main(String[] args) { RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret); //自定义 api 地址方式 // RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api); Blacklist blackList = rongCloud.User.blackList; /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/user/black.html#add * 添加用户到黑名单方法 */ UserModel blackUser = new UserModel() { Id = "hdsjGB88" }; UserModel[] blacklist = { blackUser }; UserModel user = new UserModel() { Id = "hdsjGB89", Blacklist = blacklist } ; Result userAddBlacklistResult = (Result)blackList.Add(user); Console.WriteLine("addBlacklist: " + userAddBlacklistResult.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/user/black.html#getList * 获取某用户的黑名单列表方法 */ UserModel user2 = new UserModel() { Id = "hdsjGB89" }; BlackListResult result = blackList.GetList(user2); Console.WriteLine("query blacklist: " + result.ToString()); /** * * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/user/black.html#remove * 从黑名单中移除用户方法 */ Result removeResult = blackList.Remove(user); Console.WriteLine("remove blacklist: " + removeResult.ToString()); Console.ReadLine(); }
public static BlackListResult CheckUrl(string url) { try { using (SQLiteCommand cmd = new SQLiteCommand(VDB.WDB)) { //holds the list of urls strings to use List <string> lookups; //generate the urls to test for this url lookups = GenerateUrlList(url); lookups.Add(url); //search foreach (string lookup in lookups) { if (!Checked.Contains(lookup)) { string hash = CreateMd5(lookup); BlackListResult result = CheckUrlHash(hash, cmd); if (result != BlackListResult.NotFound) { return(result); } else { //Checked.Add(lookup); } } } } } catch (Exception ex) { AntiCrash.LogException(ex); return(BlackListResult.NotFound); } finally { } return(BlackListResult.NotFound); }
/** * 获取response信息 * * @param path 路径 (获取校验文件路径) * @param method 校验方法(需要校验的方法) * @param response 返回信息 * * @return String **/ public static String GetResponseByCode(String path, String method, String response) { JObject api = null; try { JObject obj = (JObject)JToken.Parse(response); String code = obj.GetValue("code").ToString(); api = FromPath(path + API_JSON_NAME); Dictionary <String, Dictionary <String, String> > messages = GetMessages(((JObject)((JObject)api.GetValue(method)).GetValue("response")).GetValue("fail")); String text = response; if (code.Equals("200")) { if (path.Contains("blacklist") && method.Equals("getList")) { UserList userList = JsonConvert.DeserializeObject <UserList>(response); List <UserModel> users = new List <UserModel>(); foreach (String id in userList.getUsers()) { UserModel tmpUser = new UserModel { Id = id }; users.Add(tmpUser); } UserModel[] members = users.ToArray(); BlackListResult blacklist = new BlackListResult(userList.getCode(), null, members); text = blacklist.ToString(); } else if (path.Contains("whitelist/user") && method.Equals("getList")) { UserList userList = JsonConvert.DeserializeObject <UserList>(response); //User[] members = {}; List <UserModel> users = new List <UserModel>(); foreach (String id in userList.getUsers()) { users.Add(new UserModel() { Id = id }); } UserModel[] members = users.ToArray(); WhiteListResult whitelist = new WhiteListResult(userList.getCode(), null, members); text = whitelist.ToString(); } else if (path.Contains("chatroom") || path.Contains("group")) { text = response.Replace("users", "members"); if (text.Contains("whitlistMsgType")) { text = text.Replace("whitlistMsgType", "objNames"); } if (path.Contains("gag") || path.Contains("block")) { text = text.Replace("userId", "id"); } } else if (path.Contains("user")) { if (path.Contains("block") || path.Contains("blacklist")) { text = response.Replace("userId", "id"); } } else if (path.Contains("sensitiveword")) { text = response.Replace("word", "keyword"); if (text.Contains("keywords")) { text = text.Replace("keywords", "words"); } text = text.Replace("replaceWord", "replace"); } else { text = response; } return(text); } else { foreach (var item in messages) { if (code.Equals(item.Key)) { text = JsonConvert.SerializeObject(item.Value); //text = StringUtils.replace(text,"msg","errorMessage"); text = text.Replace("errorMessage", "msg"); return(text); } } text = response.Replace("errorMessage", "msg"); if (path.Contains("chatroom")) { text = text.Replace("users", "members"); //对于 聊天室保活成功返回的code是0 更改统一返回200 if (path.Contains("keepalive") && "0".Equals(code)) { text = text.Replace("chatroomIds", "chatrooms"); text = text.Replace("0", "200"); } } return(text); } } catch (Exception e) { Console.WriteLine("-------------" + e.Message); } return(response); }
public WebProtectionEventArgs(BlackListResult result, string url, string useragent) { _infected = result; _url = url; _ua = useragent; }
public void AddBlackListTest() { // 创建第一个volunteer Random tempnum = new Random(); int studentnum = tempnum.Next(000, 999); Guid uid = Guid.NewGuid(); string name = uid.ToString(); Volunteer v1 = new Volunteer() { //Id = 000, StudentNum = studentnum, Mobile = "1234567890-", Name = name, Email = "*****@*****.**", Class = "AddTestClass", Room = "AddTestRoom" }; volunteerhelper.AddVolunteer(v1); v1 = database.Volunteers.Single(b => b.StudentNum == v1.StudentNum); // 创建一个adder Guid temp = Guid.NewGuid(); string appusername = temp.ToString(); Random rnd = new Random(); int usertempnum = rnd.Next(000, 999); int usernum = usertempnum; AppUser adder = new AppUser() { AccountName = appusername, StudentNum = usernum, Mobile = "1234567890", Email = "*****@*****.**" }; identityhelper.CreateUser(adder, "23457890-", AppRoleEnum.OrgnizationMember, OrganizationEnum.TestOnly); adder = database.Users.Single(a => a.AccountName == adder.AccountName); // 创建一个org Organization org = identityhelper.CreateOrFindOrganization(OrganizationEnum.TestOnly); // 创建一个pro Guid prouid = Guid.NewGuid(); string proname = uid.ToString(); Project pro = new Project() { Name = proname, Place = "testplace", Organization = org }; projectmanagerhelper.CreatNewProject(org, System.DateTime.Now, pro.Name, pro.Place, "", 70); pro = database.Projects.Single(p => p.Name == pro.Name); // 添加第一条黑名单记录 BlackListRecord testaddrecord1 = new BlackListRecord { //Id = 1234567890, Volunteer = database.Volunteers.Single(b => b.StudentNum == v1.StudentNum), Adder = database.Users.Single(b => b.StudentNum == adder.StudentNum), Status = BlackListRecordStatus.Enabled, Organization = org, EndTime = new DateTime(2090, 2, 11), AddTime = System.DateTime.Now, Project = database.Projects.Single(b => b.Name == pro.Name) }; BlackListResult result = helper.AddBlackListRecord(testaddrecord1); if (!result.Succeeded) { Assert.Fail("返回错误结果!请检查后重试"); } var actual = helper.FindBlackList(v1); if (actual == null) { Assert.Fail("记录添加失败!数据库无此记录!"); } // 测试ExistingRecord BlackListRecord testaddrecord3 = new BlackListRecord { //Id = 0987654321 Volunteer = v1, Adder = adder, Status = BlackListRecordStatus.Enabled, Organization = org, EndTime = new DateTime(2090, 2, 11), AddTime = System.DateTime.Now, Project = pro }; BlackListResult existingrecordresult = helper.AddBlackListRecord(testaddrecord3); //Assert.AreEqual(existingrecordresult, BlackListResult.AddBlackListRecordErrorEnum.ExistingRecord, "检验existingrecord失败!"); if (!BlackListResult.AreSame(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.ExistingRecord), existingrecordresult)) { Assert.Fail(); } // 测试WrongTime BlackListRecord testaddrecord4 = new BlackListRecord { EndTime = new DateTime(2017, 2, 1), AddTime = System.DateTime.Now }; var wrongtimeresult = helper.AddBlackListRecord(testaddrecord4); //Assert.AreEqual(wrongtimeresult, BlackListResult.AddBlackListRecordErrorEnum.WrongTime, "测试wrongtime失败!"); if (!BlackListResult.AreSame(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.WrongTime), wrongtimeresult)) { Assert.Fail(); } // 测试Nullrecord BlackListRecord testaddrecord5 = new BlackListRecord(); var nullrecordresult = helper.AddBlackListRecord(testaddrecord5); //Assert.AreEqual(nullrecordresult, BlackListResult.AddBlackListRecordErrorEnum.NullRecord, "测试nullrecord失败!"); if (!BlackListResult.AreSame(BlackListResult.Error(BlackListResult.AddBlackListRecordErrorEnum.NullRecord), nullrecordresult)) { Assert.Fail(); } //清空数据库 DeleteOrgnization(org); // 清空org 同时清空了blacklistrecord和org下的project,users volunteerhelper.DeleteVolunteer(v1.StudentNum); }
public void EditBlackListTest() { //添加新的记录 //创建volunteer v Random tempnum = new Random(); int studentnum = tempnum.Next(000, 999); Guid uid = Guid.NewGuid(); string name = uid.ToString(); Volunteer v = new Volunteer() { //Id = 000, StudentNum = studentnum, Mobile = "1234567890-", Name = name, Email = "*****@*****.**", Class = "AddTestClass", Room = "AddTestRoom" }; volunteerhelper.AddVolunteer(v); v = database.Volunteers.Single(b => b.StudentNum == v.StudentNum); //创建adder Guid temp = Guid.NewGuid(); string appusername = temp.ToString(); Random rnd = new Random(); int usertempnum = rnd.Next(000, 999); int usernum = usertempnum; AppUser adder = new AppUser() { AccountName = appusername, StudentNum = usernum, Mobile = "1234567890", Email = "*****@*****.**" }; identityhelper.CreateUser(adder, "23457890-", AppRoleEnum.OrgnizationMember, OrganizationEnum.TestOnly); Organization org = identityhelper.CreateOrFindOrganization(OrganizationEnum.TestOnly); //创建pro Guid prouid = Guid.NewGuid(); string proname = uid.ToString(); Project pro = new Project() { Name = proname, Place = "testplace", Organization = org }; projectmanagerhelper.CreatNewProject(org, System.DateTime.Now, pro.Name, pro.Place, "", 20); //创建blacklistrecord BlackListRecord blacklistrecord = new BlackListRecord { // Id = 1234567890, Volunteer = database.Volunteers.Single(b => b.StudentNum == v.StudentNum), Adder = database.Users.Single(b => b.StudentNum == adder.StudentNum), Status = BlackListRecordStatus.Enabled, Organization = org, EndTime = new DateTime(2090, 2, 11), AddTime = System.DateTime.Now, Project = database.Projects.Single(b => b.Name == pro.Name) }; helper.AddBlackListRecord(blacklistrecord); var tempblacklist = helper.FindBlackList(v); BlackListRecord blacklist = tempblacklist.First(); // 测试 EmptyId var tempendtime = new DateTime(2020, 2, 11); //BlackListResult testresult = helper.EditBlackListRecord(blacklistrecord.UID , tempendtime, BlackListRecordStatus.Enabled); //if ( testresult.Succeeded ) //{ // Assert.Fail("返回结果异常!"); //} //测试EditRecord BlackListResult result = helper.EditBlackListRecord("", blacklist.UID, tempendtime, BlackListRecordStatus.Enabled); blacklist = helper.FindBlackList(v).First(); var actual = helper.FindBlackListByEndTime(blacklist.AddTime, tempendtime); var actualendtime = actual.First(); if (!result.Succeeded) { Assert.Fail("结果返回异常!"); } else if (actualendtime.EndTime != tempendtime) { Assert.Fail("edit方法失败!"); } //清空数据库 DeleteOrgnization(org); // 清空org 同时清空了blacklistrecord和org下的project,users volunteerhelper.DeleteVolunteer(v.StudentNum); }
static bool SafeBrowse(Session session) { // WBSD if (SettingsManager.WebAgentSmartDetection) { foreach (string word in Blockers) { if (session.fullUrl.Contains(word)) { if (SettingsManager.BlockUrls) { KavprotVoice.SpeakAsync("This url contains a blocked word."); session.utilCreateResponseAndBypassServer(); session.responseBodyBytes = Encoding.ASCII.GetBytes(KAVE.Properties.Resources.ErrorPageHead + string.Format(KAVE.Properties.Resources.Title, "Kavprot smart security Blocked a Malware Attack !!!") + KAVE.Properties.Resources.Ressources + string.Format(KAVE.Properties.Resources.Bodytitle, "Kavprot smart security Blocked a Malware Attack !!!") + string.Format(KAVE.Properties.Resources.Body, KAVE.Properties.Resources.MalwareMessage)); session.oResponse.headers = Parser.ParseResponse("HTTP/1.1 200 OK\r\nKPAVWebProxyTemplate: True\r\nContent-Length: 165000"); return(true); } } } } // filter data if (SettingsManager.ParentalControl) { BlackListResult result = CheckUrl(session.fullUrl); if (result == BlackListResult.MalwareAttack) { if (SettingsManager.BlockUrls) { KavprotVoice.SpeakAsync("A malware website access was blocked."); session.utilCreateResponseAndBypassServer(); session.responseBodyBytes = Encoding.ASCII.GetBytes(KAVE.Properties.Resources.ErrorPageHead + string.Format(KAVE.Properties.Resources.Title, "Kavprot smart security Blocked a Malware Attack !!!") + KAVE.Properties.Resources.Ressources + string.Format(KAVE.Properties.Resources.Bodytitle, "Kavprot smart security Blocked a Malware Attack !!!") + string.Format(KAVE.Properties.Resources.Body, KAVE.Properties.Resources.MalwareMessage)); session.oResponse.headers = Parser.ParseResponse("HTTP/1.1 200 OK\r\nKPAVWebProxyTemplate: True\r\nContent-Length: 165000"); return(true); } } else if (result == BlackListResult.PhishingAttack) { if (SettingsManager.BlockUrls) { KavprotVoice.SpeakAsync("A phishing website access was blocked"); session.utilCreateResponseAndBypassServer(); session.responseBodyBytes = Encoding.ASCII.GetBytes(KAVE.Properties.Resources.ErrorPageHead + string.Format(KAVE.Properties.Resources.Title, "Kavprot smart security Blocked a Phishing Attack !!!") + KAVE.Properties.Resources.Ressources + string.Format(KAVE.Properties.Resources.Bodytitle, "Kavprot smart security Blocked a Phishing Attack !!!") + string.Format(KAVE.Properties.Resources.Body, KAVE.Properties.Resources.PhishMessage)); session.oResponse.headers = Parser.ParseResponse("HTTP/1.1 200 OK\r\nKPAVWebProxyTemplate: True\r\nContent-Length: 165000"); return(true); } } else if (result == BlackListResult.PornAttack) { if (SettingsManager.BlockUrls) { KavprotVoice.SpeakAsync("A pornographic website access was blocked"); session.utilCreateResponseAndBypassServer(); session.responseBodyBytes = Encoding.ASCII.GetBytes(KAVE.Properties.Resources.ErrorPageHead + string.Format(KAVE.Properties.Resources.Title, "Kavprot smart security Blocked a P**n Attack !!!") + KAVE.Properties.Resources.Ressources + string.Format(KAVE.Properties.Resources.Bodytitle, "Kavprot smart security Blocked a P**n Attack !!!") + string.Format(KAVE.Properties.Resources.Body, KAVE.Properties.Resources.PornMSG)); session.oResponse.headers = Parser.ParseResponse("HTTP/1.1 200 OK\r\nKPAVWebProxyTemplate: True\r\nContent-Length: 165000"); return(true); } } else if (result == BlackListResult.Undetermined) { if (SettingsManager.BlockUrls) { KavprotVoice.SpeakAsync("Kavprot blocked this website for unknown reason"); session.utilCreateResponseAndBypassServer(); session.responseBodyBytes = Encoding.ASCII.GetBytes(KAVE.Properties.Resources.ErrorPageHead + string.Format(KAVE.Properties.Resources.Title, "Kavprot smart security Proxy Error") + KAVE.Properties.Resources.Ressources + string.Format(KAVE.Properties.Resources.Bodytitle, "Kavprot smart securityProxy ERROR") + string.Format(KAVE.Properties.Resources.Body, KAVE.Properties.Resources.UnderterminedMSG)); session.oResponse.headers = Parser.ParseResponse("HTTP/1.1 200 OK\r\nKPAVWebProxyTemplate: True\r\nContent-Length: 165000"); return(true); } } } return(false); }