예제 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure that you would like to delete this frequent item?", "Delete Frequent Item", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                DataGridViewRow Row = grdMain.Rows[grdMain.SelectedRows[0].Index];

                long UID = Convert.ToInt32(Row.Cells[0].Value);

                FrequentItem FrequentItem = Repository.Find <FrequentItem>
                                                (s => s.UID == UID)
                                            .FirstOrDefault();

                Repository.Delete(FrequentItem);

                LoadGrid(PhishDataType.Undefined);
            }
        }
예제 #2
0
        public void FrequentItemCounter(PhishDataType Type,
                                        int FrequentItems_MinimumLength,
                                        int FrequentItems_Confidence)
        {
            List <string> Urls;

            List <String> UrlsCleaned = new List <string>();

            Dictionary <string, int> dictionary = new Dictionary <string, int>();

            Urls = Repository
                   .Find <Resource>(s => s.ItemType == Type)
                   .Select(a => a.Url)
                   .ToList();

            foreach (var record in Urls)
            {
                String result = Regex.Replace(record, @"\p{P}", " ");
                result = Regex.Replace(result, @"[\d-]", " ");
                result = result.Replace("=", " ");
                UrlsCleaned.Add(result);
            }

            foreach (var item in UrlsCleaned)
            {
                var line  = item.ToLower().Trim();
                var words = line.Split(' ');

                foreach (var word in words)
                {
                    if (String.IsNullOrEmpty(word) || word.Length < FrequentItems_MinimumLength)
                    {
                        continue;
                    }

                    if (!dictionary.ContainsKey(word))
                    {
                        dictionary.Add(word, 1);
                    }
                    else
                    {
                        dictionary[word] = dictionary[word] + 1;
                    }
                }
            }

            List <FrequentItem> FrequentItems = Repository
                                                .Find <FrequentItem>(s => s.ItemType == Type)
                                                .ToList();

            List <FrequentItem> NewFrequentItems = new List <FrequentItem>();

            List <FrequentItem> UpdateFrequentItems = new List <FrequentItem>();

            foreach (var item in dictionary)
            {
                if (item.Value < FrequentItems_Confidence)
                {
                    continue;
                }

                if (FrequentItems.Any(s => s.Term == item.Key))
                {
                    FrequentItem UItem = FrequentItems.Where(s => s.Term == item.Key).FirstOrDefault();
                    UItem.MinimumFrequency = FrequentItems_MinimumLength;
                    UItem.Frequency        = item.Value;
                    UItem.ItemType         = Type;
                    UpdateFrequentItems.Add(UItem);
                }
                else
                {
                    FrequentItem UItem = new FrequentItem();
                    UItem.Term             = item.Key;
                    UItem.ItemType         = Type;
                    UItem.MinimumFrequency = FrequentItems_MinimumLength;
                    UItem.Frequency        = item.Value;
                    NewFrequentItems.Add(UItem);
                }
            }

            Repository.AddMultiple(NewFrequentItems);
            Repository.UpdateMultiple(UpdateFrequentItems);
        }
예제 #3
0
        public void FrequentItemDetection(string Url)
        {
            //Cleaning URL
            Regex  rgx         = new Regex("[^a-zA-Z0-9 -]");
            String StrippedUrl = rgx.Replace(Url, " ");
            var    SplitUrl    = StrippedUrl.Split(null).ToList();

            SplitUrl.RemoveAll(item => String.IsNullOrWhiteSpace(item) || String.IsNullOrEmpty(item));

            List <FrequentItem> PositiveFrequentItems = Repository
                                                        .Find <FrequentItem>(s => s.ItemType == PhishDataType.Positive)
                                                        .ToList();

            List <FrequentItem> NegativeFrequentItems = Repository
                                                        .Find <FrequentItem>(s => s.ItemType == PhishDataType.Negative)
                                                        .ToList();


            List <IgnoreRule> IgnoreRules = Repository
                                            .Find <IgnoreRule>(s => s.Type == IgnoreType.FrequentItem)
                                            .ToList();

            List <string> PositiveNonUnion = PositiveFrequentItems
                                             .Select(s => s.Term)
                                             .Intersect(SplitUrl)
                                             .Except(IgnoreRules.Select(x => x.Term))
                                             .ToList();

            List <string> UnionItems = NegativeFrequentItems
                                       .Select(s => s.Term)
                                       .Intersect(SplitUrl)
                                       .Except(IgnoreRules.Select(x => x.Term))
                                       .Except(PositiveNonUnion)
                                       .ToList();

            int  TotalRecords       = SplitUrl.Count - PositiveNonUnion.Count;
            int  ProbabilityCounter = 0;
            bool IsPhishing         = false;

            grdFreq.Rows.Clear();

            foreach (var item in UnionItems)
            {
                FrequentItem fitem = NegativeFrequentItems.Where(s => s.Term == item).FirstOrDefault();
                grdFreq.Rows.Add(item, Convert.ToString(fitem.Frequency));
                ProbabilityCounter += 1;// fitem.Frequency;
            }

            ProbabilityCounter = ProbabilityCounter * 100 / TotalRecords;

            // 50% probability
            if (ProbabilityCounter >= 50)
            {
                IsPhishing = true;
            }

            if (IsPhishing)
            {
                txtFreqM.Text = String.Format("Based on the testing performed, {0} is a phishing site according to the analysis shown below", Url);
                lblFreqPercentage.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                txtFreqM.Text = String.Format("Based on the testing performed, {0} is not a phishing site according to the analysis shown below", Url);
                lblFreqPercentage.ForeColor = System.Drawing.Color.Green;
            }

            lblFreqPercentage.Text = ProbabilityCounter.ToString() + " %";

            grpFrequent.Visible = true;
        }