Exemplo n.º 1
0
        private static Boolean performLookup(HttpContext current)
        {
            //GateKeeperModule.log.Debug("Beginning lookup");

            // start the clock
            DateTime _start = DateTime.Now;

            // Use test IP if configured
            string ip    = (!string.IsNullOrEmpty(GateKeeperModule.config.HttpBLTestIPAddress)) ? GateKeeperModule.config.HttpBLTestIPAddress : current.Request.UserHostAddress;
            string query = string.Format("{0}.{1}.{2}", GateKeeperModule.config.HttpBLKeyCode, GateKeeperModule.flipIPAddress(ip), "dnsbl.httpbl.org");
            // perform the lookup
            string lookup = GateKeeperModule.DnsLookup(query, GateKeeperModule.config.HttpBLTimeout);

            // stop the clock
            TimeSpan executiontime = DateTime.Now.Subtract(_start);

            //GateKeeperModule.log.DebugFormat("Lookup completion time in ms [{0}]", executiontime.Milliseconds.ToString());


            // check if we recieved something back
            if (string.IsNullOrEmpty(lookup))
            {
                //GateKeeperModule.log.Debug("Lookup returned no matching domain");
                return(false);
            }

            // Split out response
            Regex parse = new Regex("(?<status>\\d+)\\.(?<days>\\d+)\\.(?<threat>\\d+)\\.(?<type>\\d+)", RegexOptions.Compiled);
            Match match = parse.Match(lookup);

            // Match found, load the lookup values
            int lastactivity = int.Parse(match.Groups["days"].Value);
            int threatscore  = int.Parse(match.Groups["threat"].Value);
            int visitortype  = int.Parse(match.Groups["type"].Value);

            // See if threatscore is greater than threshold set by user
            if (threatscore >= GateKeeperModule.config.ThreatScoreThreshold)
            {
                //GateKeeperModule.log.Debug("Requestor IP address equal to or above threatscore threshold");
                if (GateKeeperModule.config.EnableHttpBLLogging)
                {
                    AddHttp(current, threatscore, visitortype, lastactivity);
                }

                // Check if only check and no deny
                if (!GateKeeperModule.config.DenyHttpBLSuspect)
                {
                    //GateKeeperModule.log.Debug("Skipping deny as per config settings");
                    return(false);
                }

                // Deny access to suspected spammer
                return(true);
            }
            else
            {
                //GateKeeperModule.log.Debug("Requestor IP address below threatscore threshold");
                return(false);
            }
        }
        /// <summary>
        /// Raises the <see cref="E:Load"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            SPContext.Current.Web.AllowUnsafeUpdates = true;
            if (!String.IsNullOrEmpty(Request.QueryString["guid"]) && !IsPostBack)
            {
                WebSiteControllerRule rule = WebSiteControllerConfig.GetRule(this.Page.Request.QueryString["guid"]);
            }
            //TODO Button Dialog Update
            else
            {
                try
                {
                    GateKeeperModule module = new GateKeeperModule();
                    Uri url = new Uri(this.Page.Request.QueryString["Source"].ToString());

                    if (WebSiteControllerConfig.IsPageControlled(url, module.RuleType))
                    {
                        System.Collections.Generic.List <WebSiteControllerRule> rules = WebSiteControllerConfig.GetRulesForPage(SPContext.Current.Site.WebApplication, url, module.RuleType);
                        WebSiteControllerRule rule = rules[rules.Count - 1];
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            SPContext.Current.Web.AllowUnsafeUpdates = false;
        }
Exemplo n.º 3
0
        public GateKeeperSettings Load()
        {
            GateKeeperSettings config = null;
            GateKeeperModule   module = new GateKeeperModule();

            HttpContext current = HttpContext.Current;
            HttpRequest request = current.Request;

            string currUrl  = current.Request.Url.ToString();
            string basePath = currUrl.Substring(0, currUrl.IndexOf(current.Request.Url.Host) + current.Request.Url.Host.Length);
            Uri    url      = new Uri(basePath);

            List <WebSiteControllerRule> rules = WebSiteControllerConfig.GetRulesForSiteCollection(url, module.RuleType);

            foreach (WebSiteControllerRule rule in rules)
            {
                //string props = rule.Properties.ToString();

                if (rule.Properties.ContainsKey("GateKeeper"))
                {
                    if (config == null)
                    {
                        try
                        {
                            string gateconfig = rule.Properties["GateKeeper"].ToString();
                            config       = new JavaScriptSerializer().Deserialize <GateKeeperSettings>(Encryption.Decrypt(gateconfig));
                            config._guid = rule.Id;
                            break;
                        }
                        catch (Exception ex)
                        {
                            ex.ToString();
                            //throw;
                        }
                    }
                }
            }
            if (config != null)
            {
                return(config);
            }
            else
            {
                return(new GateKeeperSettings());
            }
        }
Exemplo n.º 4
0
        private static Boolean performLookup(HttpContext current)
        {
            //GateKeeperModule.log.Debug("Beginning lookup");

            // start the clock
            DateTime _start = DateTime.Now;

            // Use test IP if configured
            string ip    = (!string.IsNullOrEmpty(GateKeeperModule.config.ProxyBLTestIPAddress)) ? GateKeeperModule.config.ProxyBLTestIPAddress : current.Request.UserHostAddress;
            string query = string.Format("{0}.{1}", GateKeeperModule.flipIPAddress(ip), "dnsbl.proxybl.org");
            // perform the lookup
            string lookup = GateKeeperModule.DnsLookup(query, GateKeeperModule.config.ProxyBLTimeout);

            // stop the clock
            TimeSpan executiontime = DateTime.Now.Subtract(_start);

            //GateKeeperModule.log.DebugFormat("Lookup completion time in ms [{0}]", executiontime.Milliseconds.ToString());

            // check if we recieved something back
            if (string.IsNullOrEmpty(lookup))
            {
                //GateKeeperModule.log.Debug("Lookup returned no matching domain");
                return(false);
            }

            //GateKeeperModule.log.Debug("Requestor IP address found in lookup");
            if (GateKeeperModule.config.EnableProxyBLLogging)
            {
                AddProxy(current);
            }

            if (!GateKeeperModule.config.DenyProxyBLSuspect)
            {
                //GateKeeperModule.log.Debug("Skipping deny as per config settings");
                return(false);
            }

            // Deny access to suspected spammer
            return(true);
        }
Exemplo n.º 5
0
        private void CreateWorkItem(SPWeb web)//, HttpStatusCode code)
        {
            Guid siteId = web.Site.ID;
            Guid webId  = web.ID;

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append("/;");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            string value = new JavaScriptSerializer().Serialize(this);

            builder.Append(String.Format("{0}:{1};", "GateKeeper", Encryption.Encrypt(value)));
            //builder.Append(value);

            string full = builder.ToString();

            GateKeeperModule         mod  = new GateKeeperModule();
            IWebSiteControllerModule imod = null;  //WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);

            while (imod == null)
            {
                try
                {
                    imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                System.Threading.Thread.Sleep(1000);
            }

            Guid itemGuid = _guid;
            int  item     = 0;

            if (itemGuid.Equals(Guid.Empty))
            {
                itemGuid = mod.Id;
                item     = -1;
            }
            else
            {
                item = 2;
            }

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        itemGuid,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });
        }