Esempio n. 1
0
        public void MatchesOveralppingL33tPatterns()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var expected = new List <DictionaryMatch>
            {
                new DictionaryMatch()
                {
                    DictionaryName = "words",
                    i           = 0,
                    j           = 2,
                    MatchedWord = "aac",
                    Rank        = 1,
                    Reversed    = false,
                    L33t        = true,
                    Token       = "@a(",
                    L33tSubs    = new Dictionary <char, char>
                    {
                        { '@', 'a' },
                        { '(', 'c' },
                    },
                },
                new DictionaryMatch()
                {
                    DictionaryName = "words2",
                    i           = 2,
                    j           = 4,
                    MatchedWord = "cgo",
                    Rank        = 1,
                    Reversed    = false,
                    L33t        = true,
                    Token       = "(go",
                    L33tSubs    = new Dictionary <char, char>
                    {
                        { '(', 'c' },
                    },
                },
                new DictionaryMatch()
                {
                    DictionaryName = "words2",
                    i           = 5,
                    j           = 7,
                    MatchedWord = "cgo",
                    Rank        = 1,
                    Reversed    = false,
                    L33t        = true,
                    Token       = "{G0",
                    L33tSubs    = new Dictionary <char, char>
                    {
                        { '{', 'c' }, { '0', 'o' },
                    },
                },
            };
            var result = matcher.MatchPassword("@a(go{G0");

            result.Should().BeEquivalentTo(expected);
        }
Esempio n. 2
0
        public void DictionaryMatch(string word, int count)
        {
            var dm   = new DictionaryMatcher("test", "test_dictionary.txt");
            var leet = new L33tMatcher(dm);

            leet.MatchPassword(word).Should().HaveCount(count);
        }
Esempio n. 3
0
        public void EnumerateL33tSubsGetsTheSetOfSubstitutionsForAPassword()
        {
            L33tMatcher.L33tTable = TestL33tTable;

            var actual = L33tMatcher.EnumerateSubtitutions(new ReadOnlyDictionary <char, char[]>(new Dictionary <char, char[]>()));

            actual.Single().Should().BeEmpty();

            actual = L33tMatcher.EnumerateSubtitutions(new ReadOnlyDictionary <char, char[]>(new Dictionary <char, char[]>
            {
                { 'a', new[] { '@' } },
            }));
            var expected = new List <Dictionary <char, char> >()
            {
                new Dictionary <char, char>()
                {
                    { '@', 'a' },
                },
            };

            actual.Should().BeEquivalentTo(expected);

            actual = L33tMatcher.EnumerateSubtitutions(new ReadOnlyDictionary <char, char[]>(new Dictionary <char, char[]>
            {
                { 'a', new[] { '@', '4' } },
            }));
            expected = new List <Dictionary <char, char> >()
            {
                new Dictionary <char, char>()
                {
                    { '@', 'a' },
                },
                new Dictionary <char, char>()
                {
                    { '4', 'a' },
                },
            };
            actual.Should().BeEquivalentTo(expected);

            actual = L33tMatcher.EnumerateSubtitutions(new ReadOnlyDictionary <char, char[]>(new Dictionary <char, char[]>
            {
                { 'a', new[] { '@', '4' } },
                { 'c', new[] { '(' } },
            }));
            expected = new List <Dictionary <char, char> >()
            {
                new Dictionary <char, char>()
                {
                    { '@', 'a' },
                    { '(', 'c' },
                },
                new Dictionary <char, char>()
                {
                    { '4', 'a' },
                    { '(', 'c' },
                },
            };
            actual.Should().BeEquivalentTo(expected);
        }
Esempio n. 4
0
        /// <summary>
        /// Get instances of pattern matchers, adding in per-password matchers on userInputs (and userInputs with l33t substitutions)
        /// </summary>
        /// <param name="userInputs">Enumerable of user information</param>
        /// <returns>Enumerable of matchers to use</returns>
        public IEnumerable <IMatcher> CreateMatchers(IEnumerable <string> userInputs)
        {
            var userInputDict = new DictionaryMatcher("user_inputs", userInputs);
            var leetUser      = new L33tMatcher(userInputDict);

            return(matchers.Union(new List <IMatcher> {
                userInputDict, leetUser
            }));
        }
Esempio n. 5
0
        public void DoesNotMatchWithSubsetsOfPossibleL33tCombinations()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var result = matcher.MatchPassword("4sdf0");

            result.Should().BeEmpty();
        }
Esempio n. 6
0
        public void DoesNotMatchWhenMultipleSubstitutionsAreNeededForTheSameLetter()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var result = matcher.MatchPassword("p4@ssword");

            result.Should().BeEmpty();
        }
Esempio n. 7
0
        public void DoesNotMatchSingleCharacterL33tedWords()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var result = matcher.MatchPassword("4 1 @");

            result.Should().BeEmpty();
        }
Esempio n. 8
0
        public void DoesNotMatchNonL33tWords()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var result = matcher.MatchPassword("password");

            result.Should().BeEmpty();
        }
Esempio n. 9
0
        public void DoesNotMatchEmptyString()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var result = matcher.MatchPassword(string.Empty);

            result.Should().BeEmpty();
        }
        public void L33tTest()
        {
            var l = new L33tMatcher(new DictionaryMatcher("test", new List <string> {
                "password"
            }));

            l.MatchPassword("password");
            l.MatchPassword("p@ssword");
            l.MatchPassword("p1ssword");
            l.MatchPassword("p1!ssword");
            l.MatchPassword("p1!ssw0rd");
            l.MatchPassword("p1!ssw0rd|");
        }
        public void DictionaryTest()
        {
            var dm = new DictionaryMatcher("test", "test_dictionary.txt");

            var res = dm.MatchPassword("NotInDictionary");

            Assert.AreEqual(0, res.Count());

            res = dm.MatchPassword("choreography");
            Assert.AreEqual(1, res.Count());

            res = dm.MatchPassword("ChOrEograPHy");
            Assert.AreEqual(1, res.Count());


            var leet = new L33tMatcher(dm);

            res = leet.MatchPassword("3mu");
            Assert.AreEqual(1, res.Count());

            res = leet.MatchPassword("3mupr4nce|egume");
        }
Esempio n. 12
0
        public void RelevantL33tTableReducesSubstitutions()
        {
            L33tMatcher.L33tTable = TestL33tTable;

            var actual = L33tMatcher.RelevantL33tSubtable(string.Empty);

            actual.Should().BeEmpty();

            actual = L33tMatcher.RelevantL33tSubtable("abcdefgo123578!#$&*)]}>");
            actual.Should().BeEmpty();

            actual = L33tMatcher.RelevantL33tSubtable("a");
            actual.Should().BeEmpty();

            var expected = new Dictionary <char, char[]>
            {
                { 'a', new[] { '4' } },
            };

            actual = L33tMatcher.RelevantL33tSubtable("4");
            actual.Should().BeEquivalentTo(expected);
        }
Esempio n. 13
0
        public void MatchesCommonL33tSubstitutions()
        {
            L33tMatcher.L33tTable = TestL33tTable;
            var matcher = new L33tMatcher(new List <IMatcher> {
                TestDictionary1, TestDictionary2
            });

            var expected = new List <DictionaryMatch>
            {
                new DictionaryMatch()
                {
                    DictionaryName = "words",
                    i           = 0,
                    j           = 7,
                    MatchedWord = "password",
                    Rank        = 3,
                    Reversed    = false,
                    L33t        = true,
                    Token       = "p4ssword",
                    L33tSubs    = new Dictionary <char, char>
                    {
                        { '4', 'a' },
                    },
                },
            };
            var result = matcher.MatchPassword("p4ssword");

            result.Should().BeEquivalentTo(expected);

            expected = new List <DictionaryMatch>
            {
                new DictionaryMatch()
                {
                    DictionaryName = "words",
                    i           = 0,
                    j           = 7,
                    MatchedWord = "password",
                    Rank        = 3,
                    Reversed    = false,
                    L33t        = true,
                    Token       = "p@ssw0rd",
                    L33tSubs    = new Dictionary <char, char>
                    {
                        { '@', 'a' }, { '0', 'o' },
                    },
                },
            };
            result = matcher.MatchPassword("p@ssw0rd");
            result.Should().BeEquivalentTo(expected);

            expected = new List <DictionaryMatch>
            {
                new DictionaryMatch()
                {
                    DictionaryName = "words2",
                    i           = 5,
                    j           = 7,
                    MatchedWord = "cgo",
                    Rank        = 1,
                    Reversed    = false,
                    L33t        = true,
                    Token       = "{G0",
                    L33tSubs    = new Dictionary <char, char>
                    {
                        { '{', 'c' }, { '0', 'o' },
                    },
                },
            };
            result = matcher.MatchPassword("aSdfO{G0asDfO");
            result.Should().BeEquivalentTo(expected);
        }