summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2017-03-06 14:16:49 +0100
committerRahiel Kasim <rahielkasim@gmail.com>2017-03-06 14:16:49 +0100
commit6d129c5073dde1ba8009a32882bc916eb23827cf (patch)
tree0339449939f6a0ee5effc343e5b60eaaa8367af8
parent4b86684805a940b804de1659485de730aa198363 (diff)
16: Rainbow Table Hash Chain
-rw-r--r--16-rainbow-table-hash-chain.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/16-rainbow-table-hash-chain.py b/16-rainbow-table-hash-chain.py
new file mode 100644
index 0000000..f51ca09
--- /dev/null
+++ b/16-rainbow-table-hash-chain.py
@@ -0,0 +1,33 @@
+from hashlib import sha256
+from os.path import expanduser
+
+from tqdm import trange
+
+# Reading: https://en.wikipedia.org/wiki/Rainbow_table
+
+with open(expanduser("~/Documents/rockyou.txt"), "rb") as f:
+ rockyou = f.readlines()
+
+
+def password_hash(pw: bytes) -> str:
+ val = b""
+ for _ in range(50000):
+ val = sha256(val + pw).digest()
+ return val.hex()
+
+def reverse(password_hash: str, column_number: int) -> bytes:
+ num_val = int(password_hash, 16)
+ line_number = (num_val + column_number) % len(rockyou)
+ password = rockyou[line_number][:-1] # excluding the newline
+ return password
+
+
+target_hash = "27ce84a6075b583086d9fc0c856f1da5d9a853507faffd7d70833c1b7accb156"
+
+h = password_hash(b"bambino")
+for i in trange(200):
+ password = reverse(h, i)
+ h = password_hash(password)
+ if h == target_hash:
+ print("Password found: {}".format(password.decode("utf-8")))
+ break