added pw cracking
This commit is contained in:
1 parent
3205ab2311
commit
b98f53e956
14 files changed
+615
-302
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import hashlib
|
||||
import tempfile
|
||||
import unittest
|
||||
from glob import glob
|
||||
from pathlib import Path
|
||||
|
||||
from collectionparser.crack import crack
|
||||
from collectionparser.parser import Processor
|
||||
|
||||
|
||||
class CrackTest(unittest.TestCase):
|
||||
|
||||
def test_hash_saved_by_processor(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
src = Path(tmp) / 'in.txt'
|
||||
src.write_text('[email protected]:5f4dcc3b5aa765d61d8327deb882cf99\n[email protected]:plainpw\n',
|
||||
encoding='utf8')
|
||||
processor = Processor(str(Path(tmp) / 's.txt'), str(Path(tmp) / 'f.txt'),
|
||||
str(Path(tmp) / 'h.txt'))
|
||||
processor.process(src)
|
||||
hashes = ''.join(Path(p).read_text(encoding='utf8')
|
||||
for p in glob(str(Path(tmp) / 'h.txt.part.*')))
|
||||
success = ''.join(Path(p).read_text(encoding='utf8')
|
||||
for p in glob(str(Path(tmp) / 's.txt.part.*')))
|
||||
self.assertEqual('[email protected]:5f4dcc3b5aa765d61d8327deb882cf99\n', hashes)
|
||||
self.assertEqual('[email protected]:plainpw\n', success)
|
||||
|
||||
def test_crack_md5_and_sha1(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
hashes = Path(tmp) / 'hashes.txt'
|
||||
hashes.write_bytes(
|
||||
b'[email protected]:' + hashlib.md5(b'hunter2').hexdigest().encode() + b'\n'
|
||||
b'[email protected]:' + hashlib.sha1(b'secret').hexdigest().encode() + b'\n'
|
||||
b'[email protected]:not-a-hash\n')
|
||||
wordlist = Path(tmp) / 'words.txt'
|
||||
wordlist.write_bytes(b'foo\nhunter2\nbar\nsecret\n')
|
||||
out = Path(tmp) / 'cracked.txt'
|
||||
total = crack(str(hashes), str(out), wordlists=[str(wordlist)], workers=2)
|
||||
self.assertEqual(2, total)
|
||||
self.assertEqual({b'[email protected]:hunter2', b'[email protected]:secret'},
|
||||
set(out.read_bytes().splitlines()))
|
||||
|
||||
def test_crack_from_plaintext_passwords(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
hashes = Path(tmp) / 'hashes.txt'
|
||||
hashes.write_bytes(b'[email protected]:' + hashlib.md5(b'reused').hexdigest().encode() + b'\n')
|
||||
empty = Path(tmp) / 'empty.txt'
|
||||
empty.write_bytes(b'')
|
||||
plaintext = Path(tmp) / 'plain.txt'
|
||||
plaintext.write_bytes(b'[email protected]:reused\n')
|
||||
out = Path(tmp) / 'cracked.txt'
|
||||
total = crack(str(hashes), str(out), wordlists=[str(empty)],
|
||||
passwords_from=[str(plaintext)], workers=1)
|
||||
self.assertEqual(1, total)
|
||||
self.assertEqual([b'[email protected]:reused'], out.read_bytes().splitlines())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -3,6 +3,7 @@ from time import time
|
||||
|
||||
from collectionparser.parser import parseline as p
|
||||
from collectionparser.splitter import get_output_file
|
||||
from collectionparser.utils import PasswordType
|
||||
|
||||
|
||||
class ParserTest(unittest.TestCase):
|
||||
@@ -97,7 +98,10 @@ class ParserTest(unittest.TestCase):
|
||||
|
||||
self.assertIsNone(p('300396 matelymaly [email protected] 222.155.173.78 '
|
||||
'3d2c5414a041f518b03b750e62e4ebc3:Nhc'))
|
||||
self.assertIsNone(p('05-02-2012;5721869;[email protected]:f02368945726d5fc2a14eb576f7276c0'))
|
||||
# 32-char hex is a hash, not junk: kept (typed) so `crack` can attack it.
|
||||
hashed = p('05-02-2012;5721869;[email protected]:f02368945726d5fc2a14eb576f7276c0')
|
||||
self.assertIsNotNone(hashed)
|
||||
self.assertEqual(PasswordType.MD5, hashed[2])
|
||||
self.assertIsNotNone(p('[email protected]::g1u3ck'))
|
||||
self.assertIsNotNone(p('[email protected]:[email protected]:2904198'))
|
||||
self.assertIsNotNone(p('sanda [email protected]:vasafultv'))
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from collectionparser.utils import RingDictionary
|
||||
|
||||
|
||||
class UtilsTest(unittest.TestCase):
|
||||
|
||||
def test_ring_dictionary_1(self):
|
||||
rd = RingDictionary(max_num_keys=3)
|
||||
rd['a'] = 2
|
||||
self.assertListEqual(sorted(rd.d), ['a'])
|
||||
self.assertListEqual(sorted(rd.k), ['a'])
|
||||
rd['b'] = 2
|
||||
self.assertListEqual(sorted(rd.d), ['a', 'b'])
|
||||
self.assertListEqual(sorted(rd.k), ['a', 'b'])
|
||||
rd['c'] = 2
|
||||
self.assertListEqual(sorted(rd.d), ['a', 'b', 'c'])
|
||||
self.assertListEqual(sorted(rd.k), ['a', 'b', 'c'])
|
||||
rd['d'] = 2
|
||||
self.assertListEqual(sorted(rd.d), ['b', 'c', 'd'])
|
||||
self.assertListEqual(sorted(rd.k), ['b', 'c', 'd'])
|
||||
|
||||
rd = RingDictionary(max_num_keys=1)
|
||||
rd['c'] = 1
|
||||
rd['c'] = 2
|
||||
rd['c'] = 3
|
||||
self.assertListEqual(sorted(rd.d), ['c'])
|
||||
self.assertListEqual(sorted(rd.k), ['c'])
|
||||
|
||||
rd['d'] = 3
|
||||
self.assertListEqual(sorted(rd.d), ['d'])
|
||||
self.assertListEqual(sorted(rd.k), ['d'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user