Exemple #1
0
 def lm(password):
     return matching.l33t_match(password, tests_dict, test_table)
Exemple #2
0
 def lm(password):
     return matching.l33t_match(password, tests_dict, test_table)
Exemple #3
0
    def test_l33t_match(self):
        test_table = {
            "a": ["4", "@"],
            "c": ["(", "{", "[", "<"],
            "g": ["6", "9"],
            "o": ["0"]
        }
        tests_dict = {
            "words": {
                "aac": 1,
                "password": 3,
                "paassword": 4,
                "asdf0": 5
            },
            "words2": {
                "cgo": 1
            }
        }

        # Case
        pattern_list = [
            ["", {}],
            ["abcdefgo123578!#$&*)]}>", {}],
            ["a",     {}],
            ["4",     {"a": ["4"]}],
            ["4@",    {"a": ["4", "@"]}],
            ["4({60", {"a": ["4"], "c": ["(", "{"], "g": ["6"], "o": ["0"]}]
        ]
        for pw, expected in pattern_list:
            msg = "reduces l33t table to only the substitutions that a password might be employing"
            self.assertEqual(matching.relevant_l33t_subtable(pw, test_table), expected, msg)

        # Case
        pattern_list2 = [
            [{},                        [{}]],
            [{"a": ["@"]},                [{"@": "a"}]],
            [{"a": ["@", "4"]},            [{"@": "a"}, {"4": "a"}]],
            [{"a": ["@", "4"], "c": ["("]},  [{"@": "a", "(": "c"}, {"4": "a", "(": "c"}]]
        ]
        for table, subs in pattern_list2:
            msg = "enumerates the different sets of l33t substitutions a password might be using"
            self.assertEqual(matching.enumerate_l33t_subs(table), subs, msg)

        # Case
        def lm(password):
            return matching.l33t_match(password, tests_dict, test_table)
        self.assertEqual(lm(""), [], "doesn't match ''")
        self.assertEqual(lm("password"), [], "doesn't match pure dictionary words")

        # Case
        pattern_list3 = [
            # ["p4ssword",   "p4ssword", "password", "words",  3, [0, 7],  {"4": "a"}],
            ["p@ssw0rd",    "p@ssw0rd", "password", "words",  3, [0, 7],  {"@": "a", "0": "o"}],
            ["aSdfO{G0asDfO", "{G0",    "cgo",      "words2", 1, [5, 7], {"{": "c", "0": "o"}]
        ]
        for password, pattern, word, dictionary_name, rank, ij, sub in pattern_list3:
            msg = "matches against common l33t substitutions"
            self.check_matches(msg, lm(password), "dictionary", [pattern], [ij], {
                "l33t": [True],
                "sub": [sub],
                "matched_word": [word],
                "rank": [rank],
                "dictionary_name": [dictionary_name]
            })

        # Case
        matches = lm("@a(go{G0")
        msg = "matches against overlapping l33t patterns"
        self.check_matches(msg, matches, "dictionary", ["@a(", "(go", "{G0"], [[0, 2], [2, 4], [5, 7]], {
            "l33t": [True, True, True],
            "sub": [{"@": "a", "(": "c"}, {"(": "c"}, {"{": "c", "0": "o"}],
            "matched_word": ["aac", "cgo", "cgo"],
            "rank": [1, 1, 1],
            "dictionary_name": ["words", "words2", "words2"]
        })

        # Case
        msg = "doesn't match when multiple l33t substitutions are needed for the same letter"
        self.assertEqual(lm("p4@ssword"), [], msg)

        # Case
        msg = "doesn't match single-character l33ted words"
        matches = matching.l33t_match("4 1 @")
        self.assertEqual(matches, [], msg)
Exemple #4
0
    def test_l33t_match(self):
        test_table = {
            "a": ["4", "@"],
            "c": ["(", "{", "[", "<"],
            "g": ["6", "9"],
            "o": ["0"]
        }
        tests_dict = {
            "words": {
                "aac": 1,
                "password": 3,
                "paassword": 4,
                "asdf0": 5
            },
            "words2": {
                "cgo": 1
            }
        }

        # Case
        pattern_list = [
            ["", {}],
            ["abcdefgo123578!#$&*)]}>", {}],
            ["a",     {}],
            ["4",     {"a": ["4"]}],
            ["4@",    {"a": ["4", "@"]}],
            ["4({60", {"a": ["4"], "c": ["(", "{"], "g": ["6"], "o": ["0"]}]
        ]
        for pw, expected in pattern_list:
            msg = "reduces l33t table to only the substitutions that a password might be employing"
            self.assertEqual(matching.relevant_l33t_subtable(pw, test_table), expected, msg)

        # Case
        pattern_list2 = [
            [{},                        [{}]],
            [{"a": ["@"]},                [{"@": "a"}]],
            [{"a": ["@", "4"]},            [{"@": "a"}, {"4": "a"}]],
            [{"a": ["@", "4"], "c": ["("]},  [{"@": "a", "(": "c"}, {"4": "a", "(": "c"}]]
        ]
        for table, subs in pattern_list2:
            msg = "enumerates the different sets of l33t substitutions a password might be using"
            self.assertEqual(matching.enumerate_l33t_subs(table), subs, msg)

        # Case
        def lm(password):
            return matching.l33t_match(password, tests_dict, test_table)
        self.assertEqual(lm(""), [], "doesn't match ''")
        self.assertEqual(lm("password"), [], "doesn't match pure dictionary words")

        # Case
        pattern_list3 = [
            # ["p4ssword",   "p4ssword", "password", "words",  3, [0, 7],  {"4": "a"}],
            ["p@ssw0rd",    "p@ssw0rd", "password", "words",  3, [0, 7],  {"@": "a", "0": "o"}],
            ["aSdfO{G0asDfO", "{G0",    "cgo",      "words2", 1, [5, 7], {"{": "c", "0": "o"}]
        ]
        for password, pattern, word, dictionary_name, rank, ij, sub in pattern_list3:
            msg = "matches against common l33t substitutions"
            self.check_matches(msg, lm(password), "dictionary", [pattern], [ij], {
                "l33t": [True],
                "sub": [sub],
                "matched_word": [word],
                "rank": [rank],
                "dictionary_name": [dictionary_name]
            })

        # Case
        matches = lm("@a(go{G0")
        msg = "matches against overlapping l33t patterns"
        self.check_matches(msg, matches, "dictionary", ["@a(", "(go", "{G0"], [[0, 2], [2, 4], [5, 7]], {
            "l33t": [True, True, True],
            "sub": [{"@": "a", "(": "c"}, {"(": "c"}, {"{": "c", "0": "o"}],
            "matched_word": ["aac", "cgo", "cgo"],
            "rank": [1, 1, 1],
            "dictionary_name": ["words", "words2", "words2"]
        })

        # Case
        msg = "doesn't match when multiple l33t substitutions are needed for the same letter"
        self.assertEqual(lm("p4@ssword"), [], msg)

        # Case
        msg = "doesn't match single-character l33ted words"
        matches = matching.l33t_match("4 1 @")
        self.assertEqual(matches, [], msg)