Пример #1
0
 def test_empty_add_case_chain(self):
     chain = model.Chain()
     
     basewords = ['hello', 'world']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=basewords)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.AddNode()
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['Hello', 'World']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     self.assertEqual(len(basewords), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     
     rules = chain.get_rules()
     self.assert_hashcat_result(sorted(truth_words), rules, basewords=basewords)
     self.assertTrue(chain.check_hashcat_compatible())
 
     self.assertEqual(':c\n', rules)
Пример #2
0
 def test_substitution_hashcat_chain(self):
     chain = model.Chain()
     
     basewords = ['hello', 'world']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=basewords)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode()
     attr = model.SubstitutionAttr(type_='All', checked_vals=['l -> i', 'o -> 0'], all_together=True)
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['heii0', 'w0rid']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     # Substitution counts are over-estimated due to de-duplication
     self.assertEqual(2, chain.count_words())
     # Byte counts for multi-character replacements are estimated as if
     # they were single-character
     self.assertEqual(12, chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 
     rules = chain.get_rules()
     self.assert_hashcat_result(truth_words, rules, basewords)
     self.assertTrue(chain.check_hashcat_compatible())
     self.assertEqual('sliso0\n', rules)
Пример #3
0
 def test_nothing_mutator_chain(self):
     chain = model.Chain()
     
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     attr = model.NothingMutatorAttr()
     node.add_attr(attr)
     
     chain.add_node(node)
     
     truth_words = ['Test1', 'test1',
                    'Test word 2', 'test word 2',
                    'THIRDTESTWORD', 'Thirdtestword']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     self.assertEqual(6, chain.count_words())
     self.assertEqual(64, chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 
     rules = chain.get_rules()
     self.assert_hashcat_result(truth_words, rules)
     self.assertTrue('c\n:\n', rules)
Пример #4
0
    def test_append_nothing_chain(self):
        chain = model.Chain()
        
        basewords = ['heLlo', 'worLd']
        node = model.BaseNode(is_root=True)
        attr = model.StringListAttr(strings=basewords)
        node.add_attr(attr)
        chain.add_node(node)
        
        node = model.AddNode(prepend=False)
        node.add_attr(model.StringListAttr(strings=['A', 'B']))
        node.add_attr(model.NothingAdderAttr())
        chain.add_node(node)
        
        truth_words = ['heLlo', 'heLloA', 'heLloB', 'worLd', 'worLdA', 'worLdB']
        result = list(chain.get_words())
        self.assertEqual(sorted(result), sorted(truth_words))
        self.assertEqual(len(result), chain.count_words())
    
        rules = chain.get_rules()
        self.assert_hashcat_result(truth_words, rules, basewords)
        self.assertTrue(chain.check_hashcat_compatible())
        rules_truth = '''$A
$B
:
'''
        self.assertEqual(rules_truth, rules)
Пример #5
0
 def test_parallel_mutator_chain(self):
     chain = model.Chain()
     
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     attr = model.CaseAttr(type_='Toggle', idx=3)
     node.add_attr(attr)
     
     chain.add_node(node)
     
     truth_words = ['Test1', 'tesT1',
                    'Test word 2', 'tesT word 2',
                    'THIrDTESTWORD', 'Thirdtestword']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     self.assertEqual(6, chain.count_words())
     self.assertEqual(64, chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
Пример #6
0
 def test_long_hashcat_chain(self):
     chain = model.Chain()
     
     strings = ['heLlo', 'worLd']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=strings)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     node.add_attr(model.CaseAttr(type_='First', case='Uppercase'))
Пример #7
0
 def test_chain(self):
     chain = model.Chain()
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
 
     node.add_attr(attr)
     chain.add_node(node)
     
     result = list(chain.get_words())
     self.assertEqual(self.test_words, result)
     self.assertEqual(len(result), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
Пример #8
0
    def test_nothing_basenode_chain(self):
        chain = model.Chain()
    
        node = model.BaseNode(is_root=True)
        attr = model.NothingAdderAttr()
        node.add_attr(attr)
        chain.add_node(node)

        node = model.AddNode(prepend=True)
        range_ = [5, 10]
        attr = model.RangeAttr(start=range_[0], end=range_[1])
        node.add_attr(attr)
        chain.add_node(node)
        
        result = list(chain.get_words())
        truth = list(map(str, range(*range_)))
        self.assertEqual(sorted(result), sorted(truth))
        self.assertEqual(len(result), chain.count_words())
        self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
        self.assertTrue(chain.check_hashcat_compatible())
Пример #9
0
 def test_empty_mutate_chain(self):
     chain = model.Chain()
     
     basewords = ['hello', 'world']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=basewords)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode()
     chain.add_node(node)
     
     result = list(chain.get_words())
     self.assertEqual(sorted(basewords), sorted(result))
     self.assertEqual(len(basewords), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     
     rules = chain.get_rules()
     self.assert_hashcat_result(sorted(basewords), rules, basewords=basewords)
     self.assertTrue(chain.check_hashcat_compatible())
 
     self.assertEqual(':\n', rules)
Пример #10
0
    def test_add_chain(self):
        chain = model.Chain()
        
        basewords = ['heLlo', 'worLd']
        node = model.BaseNode(is_root=True)
        attr = model.StringListAttr(strings=basewords)
        node.add_attr(attr)
        chain.add_node(node)
        
        node = model.AddNode(prepend=False)
        node.add_attr(model.FileAttr(path=self.test_words_path))
        chain.add_node(node)
        
        node = model.AddNode(prepend=False)
        node.add_attr(model.StringListAttr(strings=['A', 'B']))
        node.add_attr(model.NothingAdderAttr())
        chain.add_node(node)
        
        truth_words = ['heLlotest1A', 'heLlotest1B', 'heLlotest1', 'heLlotest word 2A', 'heLlotest word 2B', 'heLlotest word 2', 'heLloTHIRDTESTWORDA', 'heLloTHIRDTESTWORDB', 'heLloTHIRDTESTWORD', 'worLdtest1A', 'worLdtest1B', 'worLdtest1', 'worLdtest word 2A', 'worLdtest word 2B', 'worLdtest word 2', 'worLdTHIRDTESTWORDA', 'worLdTHIRDTESTWORDB', 'worLdTHIRDTESTWORD']
        result = list(chain.get_words())
        self.assertEqual(sorted(result), sorted(truth_words))
        self.assertEqual(len(result), chain.count_words())
    
        rules = chain.get_rules()
        self.assert_hashcat_result(truth_words, rules, basewords)
        self.assertTrue(chain.check_hashcat_compatible())
    
        rules_truth = '''$t$e$s$t$1$A
$t$e$s$t$ $w$o$r$d$ $2$A
$T$H$I$R$D$T$E$S$T$W$O$R$D$A
$t$e$s$t$1$B
$t$e$s$t$ $w$o$r$d$ $2$B
$T$H$I$R$D$T$E$S$T$W$O$R$D$B
$t$e$s$t$1:
$t$e$s$t$ $w$o$r$d$ $2:
$T$H$I$R$D$T$E$S$T$W$O$R$D:
'''
        self.assertEqual(rules_truth, rules)
Пример #11
0
 def test_substitution_mutator_chain(self):
     chain = model.Chain()
     
     basewords = ['hello', 'world']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=basewords)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode()
     attr = model.SubstitutionAttr(type_='First', checked_vals=['l -> i', 'l -> 1'], all_together=False)
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['he1lo', 'heilo', 'wor1d', 'worid']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     # Substitution counts are over-estimated due to de-duplication
     self.assertEqual(2, chain.count_words())
     # Byte counts for multi-character replacements are estimated as if
     # they were single-character
     self.assertEqual(16, chain.count_bytes())
     self.assertFalse(chain.check_hashcat_compatible())
Пример #12
0
 def test_case_hashcat_chain(self):
     chain = model.Chain()
     
     strings = ['heLlo', 'worLd', 'hi']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=strings)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     node.add_attr(model.CaseAttr(type_='Toggle', idx=3))
     chain.add_node(node)
     
     truth_words = ['heLLo', 'hi', 'world']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(set(result)))
     #self.assertEqual(9, chain.count_words())
     #self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
 
     rules = chain.get_rules()
     self.assert_hashcat_result(truth_words, rules, basewords=strings)
     self.assertTrue(chain.check_hashcat_compatible())
     self.assertEqual('T3\n', rules)
Пример #13
0
 def test_serial_mutator_chain(self):
     chain = model.Chain()
     
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     attr = model.CaseAttr(type_='Toggle', idx=3)
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['TesT1', 'TesT word 2', 'ThiRdtestword']
     result = list(chain.get_words())
     self.assertEqual(truth_words, result)
     self.assertEqual(len(result), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())