Ejemplo n.º 1
0
        public async Task <List <string> > GenerateDomainBlacklist(DomainBlacklist domainBlacklist)
        {
            var allNames = new List <string>();

            try
            {
                var local = ParseBlacklist(domainBlacklist.LocalRules.Select(l => l.Rule).ToList(), true);
                allNames.AddUnique(local);

                foreach (var remoteRule in domainBlacklist.RemoteRules)
                {
                    var r = await FetchRemoteList(remoteRule.Rule).ConfigureAwait(false);

                    if (r != null)
                    {
                        var remote = ParseBlacklist(r);
                        allNames.AddUnique(remote);
                    }
                }

                return(allNames);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        private async Task ReadForwardingRulesFromFile(string readFromPath = "")
        {
            try
            {
                var file = _forwardingRulesFile;
                if (!string.IsNullOrEmpty(readFromPath))
                {
                    file = readFromPath;
                }

                if (string.IsNullOrEmpty(file))
                {
                    return;
                }

                if (!File.Exists(file))
                {
                    return;
                }
                var lines = await DomainBlacklist.ReadAllLinesAsync(file);

                if (lines.Length > 0)
                {
                    var tmpRules = new List <Rule>();
                    foreach (var line in lines)
                    {
                        if (line.StartsWith("#"))
                        {
                            continue;
                        }
                        var tmp = line.ToLower().Trim();
                        if (string.IsNullOrEmpty(tmp))
                        {
                            continue;
                        }
                        var lineParts = tmp.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (lineParts.Length != 2)
                        {
                            continue;
                        }
                        var rule = new Rule
                        {
                            Key   = lineParts[0].Trim(),
                            Value = lineParts[1].Trim()
                        };

                        tmpRules.Add(rule);
                    }

                    ForwardingRules.Clear();
                    var orderedTmpRules = tmpRules.OrderBy(r => r.Key);
                    ForwardingRules = new BindableCollection <Rule>(orderedTmpRules);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Ejemplo n.º 3
0
        public async void BlockQueryLogEntry()
        {
            try
            {
                if (_selectedQueryLogLine == null)
                {
                    return;
                }
                if (MainViewModel.Instance.DomainBlacklistViewModel == null)
                {
                    return;
                }
                var dialogSettings = new MetroDialogSettings
                {
                    DefaultText           = _selectedQueryLogLine.Remote.ToLower(),
                    AffirmativeButtonText = LocalizationEx.GetUiString("add", Thread.CurrentThread.CurrentCulture),
                    NegativeButtonText    = LocalizationEx.GetUiString("cancel", Thread.CurrentThread.CurrentCulture),
                    ColorScheme           = MetroDialogColorScheme.Theme
                };

                var metroWindow = Application.Current.Windows.OfType <MetroWindow>().FirstOrDefault();
                //TODO: translate
                var dialogResult = await metroWindow.ShowInputAsync(LocalizationEx.GetUiString("message_title_new_blacklist_rule", Thread.CurrentThread.CurrentCulture),
                                                                    "Rule:", dialogSettings);

                if (string.IsNullOrEmpty(dialogResult))
                {
                    return;
                }
                var newCustomRule = dialogResult.ToLower().Trim();
                var parsed        = DomainBlacklist.ParseBlacklist(newCustomRule, true);
                var enumerable    = parsed as string[] ?? parsed.ToArray();
                if (enumerable.Length != 1)
                {
                    return;
                }
                MainViewModel.Instance.DomainBlacklistViewModel.DomainBlacklistRules.Add(enumerable[0]);
                MainViewModel.Instance.DomainBlacklistViewModel.SaveBlacklistRulesToFile();
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Ejemplo n.º 4
0
 private void LoadDomainBlacklist()
 {
     try
     {
         DomainBlacklist = new DomainBlacklist();
         var domainBlacklistFilePath = Path.Combine("data", Global.DomainBlacklistConfigFile);
         if (!File.Exists(domainBlacklistFilePath))
         {
             return;
         }
         using (var domainBlacklistReader = new StreamReader(domainBlacklistFilePath))
         {
             var deserializer    = new DeserializerBuilder().WithNamingConvention(new PascalCaseNamingConvention()).Build();
             var domainBlacklist = deserializer.Deserialize <DomainBlacklist>(domainBlacklistReader);
             DomainBlacklist = domainBlacklist ?? new DomainBlacklist();
         }
     }
     catch (Exception)
     {
     }
 }
        public async void BuildTest()
        {
	        var whitelist = new List<string>
	        {
		        "a-msedge.net",
		        "amazon.com",
		        "appsflyer.com",
		        "azurewebsites.net",
		        "cdnetworks.com",
		        "cloudapp.net",
		        "edgekey.net",
		        "elasticbeanstalk.com",
		        "github.com",
		        "github.io",
		        "invalid",
		        "j.mp",
		        "l-msedge.net",
		        "lan",
		        "localdomain",
		        "microsoft.com",
		        "msedge.net",
		        "nsatc.net",
		        "ovh.net",
		        "pusher.com",
		        "pusherapp.com",
		        "spotify.com",
		        "tagcommander.com",
		        "tracker.debian.org",
		        "windows.net"
			};

			var blacklists = new List<string>
	        {
				"file:Testfiles/domains-blacklist-local-additions.txt",
		        "http://osint.bambenekconsulting.com/feeds/c2-dommasterlist.txt",
		        "http://hosts-file.net/.%5Cad_servers.txt",
		        "http://mirror1.malwaredomains.com/files/justdomains",
		        "http://ransomwaretracker.abuse.ch/downloads/RW_DOMBL.txt",
		        "http://www.malwaredomainlist.com/mdlcsv.php?inactive=off",
		        "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt",
		        "https://easylist-downloads.adblockplus.org/easylist_noelemhide.txt",
		        "https://easylist-downloads.adblockplus.org/easylistchina.txt",
		        "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
		        "https://pgl.yoyo.org/adservers/serverlist.php",
		        "https://raw.githubusercontent.com/Dawsey21/Lists/master/adblock-list.txt",
		        "https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt",
		        "https://raw.githubusercontent.com/liamja/Prebake/master/obtrusive.txt",
		        "https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt",
		        "https://s3.amazonaws.com/lists.disconnect.me/simple_malware.txt",
		        "https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
		        "https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt",
		        "http://sysctl.org/cameleon/hosts",
		        "https://raw.githubusercontent.com/azet12/KADhosts/master/KADhosts.txt",
		        "https://raw.githubusercontent.com/marktron/fakenews/master/fakenews",
		        "http://mirror1.malwaredomains.com/files/dynamic_dns.txt",
		        "https://raw.githubusercontent.com/Clefspeare13/pornhosts/master/0.0.0.0/hosts",
		        "https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/pornography-hosts",
		        "http://securemecca.com/Downloads/hosts.txt",
		        "https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/gambling-hosts",
		        "https://raw.githubusercontent.com/Sinfonietta/hostfiles/master/social-hosts"
			};

			var result = await DomainBlacklist.Build(blacklists, whitelist);
			Assert.NotNull(result);
			Assert.Contains("eth0.me", result);
		}