Update app.py
Browse files
app.py
CHANGED
|
@@ -1,95 +1,63 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import hashlib
|
| 3 |
-
import zlib
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def java_hash(s):
|
| 7 |
h = 0
|
| 8 |
for c in s:
|
| 9 |
h = (31 * h + ord(c)) & 0xFFFFFFFF
|
| 10 |
|
|
|
|
| 11 |
if h >= 0x80000000:
|
| 12 |
h -= 0x100000000
|
| 13 |
|
| 14 |
-
return
|
| 15 |
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
def adler32_hash(s):
|
| 22 |
-
return str(zlib.adler32(s.encode()))
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def djb2(s):
|
| 26 |
-
h = 5381
|
| 27 |
-
for c in s:
|
| 28 |
-
h = ((h << 5) + h) + ord(c)
|
| 29 |
-
return str(h & 0xFFFFFFFF)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def fnv1a(s):
|
| 33 |
-
h = 0x811c9dc5
|
| 34 |
-
for c in s:
|
| 35 |
-
h ^= ord(c)
|
| 36 |
-
h *= 0x01000193
|
| 37 |
-
h &= 0xFFFFFFFF
|
| 38 |
-
return str(h)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
def normalize_int(value):
|
| 42 |
try:
|
| 43 |
v = int(value)
|
| 44 |
|
| 45 |
signed = v if v < 0x80000000 else v - 0x100000000
|
| 46 |
unsigned = v & 0xFFFFFFFF
|
| 47 |
|
| 48 |
-
return {
|
| 49 |
-
except:
|
| 50 |
-
return {str(value).strip()}
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
def detect(hash_value):
|
| 54 |
-
candidates = []
|
| 55 |
-
|
| 56 |
-
if hash_value.startswith("$2"):
|
| 57 |
-
candidates.append("bcrypt")
|
| 58 |
-
|
| 59 |
-
try:
|
| 60 |
-
int(hash_value)
|
| 61 |
-
candidates += [
|
| 62 |
-
"java_hash",
|
| 63 |
-
"crc32",
|
| 64 |
-
"adler32",
|
| 65 |
-
"djb2",
|
| 66 |
-
"fnv1a"
|
| 67 |
-
]
|
| 68 |
except:
|
| 69 |
-
|
| 70 |
|
| 71 |
-
return list(dict.fromkeys(candidates))
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
def clean_wordlist(text):
|
| 75 |
return [
|
| 76 |
w.strip()
|
| 77 |
-
.replace("\r", "")
|
| 78 |
-
.replace("\n", "")
|
| 79 |
for w in text.splitlines()
|
| 80 |
if w.strip()
|
| 81 |
]
|
| 82 |
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
matches = []
|
| 86 |
|
| 87 |
-
targets =
|
| 88 |
|
| 89 |
for w in words:
|
| 90 |
try:
|
| 91 |
-
result =
|
| 92 |
|
|
|
|
| 93 |
if result in targets:
|
| 94 |
matches.append(w)
|
| 95 |
|
|
@@ -99,6 +67,10 @@ def try_match(func, target, words):
|
|
| 99 |
return matches
|
| 100 |
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
def analyze(hash_value, wordlist_text):
|
| 103 |
|
| 104 |
if wordlist_text.strip():
|
|
@@ -110,49 +82,25 @@ def analyze(hash_value, wordlist_text):
|
|
| 110 |
"test23"
|
| 111 |
]
|
| 112 |
|
| 113 |
-
|
| 114 |
-
matches = {}
|
| 115 |
|
| 116 |
-
|
| 117 |
-
m = try_match(java_hash, hash_value, wordlist)
|
| 118 |
-
if m:
|
| 119 |
-
matches["Java hashCode"] = m
|
| 120 |
-
|
| 121 |
-
if "crc32" in detected:
|
| 122 |
-
m = try_match(crc32_hash, hash_value, wordlist)
|
| 123 |
-
if m:
|
| 124 |
-
matches["CRC32"] = m
|
| 125 |
-
|
| 126 |
-
if "adler32" in detected:
|
| 127 |
-
m = try_match(adler32_hash, hash_value, wordlist)
|
| 128 |
-
if m:
|
| 129 |
-
matches["Adler32"] = m
|
| 130 |
-
|
| 131 |
-
if "djb2" in detected:
|
| 132 |
-
m = try_match(djb2, hash_value, wordlist)
|
| 133 |
-
if m:
|
| 134 |
-
matches["DJB2"] = m
|
| 135 |
-
|
| 136 |
-
if "fnv1a" in detected:
|
| 137 |
-
m = try_match(fnv1a, hash_value, wordlist)
|
| 138 |
-
if m:
|
| 139 |
-
matches["FNV1a"] = m
|
| 140 |
-
|
| 141 |
-
detected_out = "\n".join(detected) if detected else "Unknown"
|
| 142 |
|
| 143 |
if matches:
|
| 144 |
-
result_out = "
|
| 145 |
-
f"{k}: {v[:10]}" for k, v in matches.items()
|
| 146 |
-
)
|
| 147 |
else:
|
| 148 |
result_out = "No matches found (try larger wordlist)"
|
| 149 |
|
| 150 |
return detected_out, result_out
|
| 151 |
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
with gr.Blocks() as demo:
|
| 154 |
|
| 155 |
-
gr.Markdown("# 🔍
|
| 156 |
|
| 157 |
hash_input = gr.Textbox(label="Hash / Integer Value")
|
| 158 |
|
|
@@ -161,9 +109,9 @@ with gr.Blocks() as demo:
|
|
| 161 |
lines=10
|
| 162 |
)
|
| 163 |
|
| 164 |
-
run_btn = gr.Button("
|
| 165 |
|
| 166 |
-
detected_out = gr.Textbox(label="Detected
|
| 167 |
result_out = gr.Textbox(label="Recovered Matches")
|
| 168 |
|
| 169 |
run_btn.click(
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# -----------------------------
|
| 4 |
+
# JAVA HASHCODE
|
| 5 |
+
# -----------------------------
|
| 6 |
|
| 7 |
def java_hash(s):
|
| 8 |
h = 0
|
| 9 |
for c in s:
|
| 10 |
h = (31 * h + ord(c)) & 0xFFFFFFFF
|
| 11 |
|
| 12 |
+
# convert to signed 32-bit
|
| 13 |
if h >= 0x80000000:
|
| 14 |
h -= 0x100000000
|
| 15 |
|
| 16 |
+
return h
|
| 17 |
|
| 18 |
|
| 19 |
+
# -----------------------------
|
| 20 |
+
# NORMALIZATION (KEY FIX)
|
| 21 |
+
# -----------------------------
|
| 22 |
|
| 23 |
+
def normalize_java_target(value):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
try:
|
| 25 |
v = int(value)
|
| 26 |
|
| 27 |
signed = v if v < 0x80000000 else v - 0x100000000
|
| 28 |
unsigned = v & 0xFFFFFFFF
|
| 29 |
|
| 30 |
+
return {v, signed, unsigned}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
except:
|
| 32 |
+
return {value}
|
| 33 |
|
|
|
|
| 34 |
|
| 35 |
+
# -----------------------------
|
| 36 |
+
# CLEAN WORDLIST
|
| 37 |
+
# -----------------------------
|
| 38 |
|
| 39 |
def clean_wordlist(text):
|
| 40 |
return [
|
| 41 |
w.strip()
|
|
|
|
|
|
|
| 42 |
for w in text.splitlines()
|
| 43 |
if w.strip()
|
| 44 |
]
|
| 45 |
|
| 46 |
|
| 47 |
+
# -----------------------------
|
| 48 |
+
# CRACK ENGINE (JAVA ONLY)
|
| 49 |
+
# -----------------------------
|
| 50 |
+
|
| 51 |
+
def crack_java(target_hash, words):
|
| 52 |
matches = []
|
| 53 |
|
| 54 |
+
targets = normalize_java_target(target_hash)
|
| 55 |
|
| 56 |
for w in words:
|
| 57 |
try:
|
| 58 |
+
result = java_hash(w)
|
| 59 |
|
| 60 |
+
# compare ALL representations automatically
|
| 61 |
if result in targets:
|
| 62 |
matches.append(w)
|
| 63 |
|
|
|
|
| 67 |
return matches
|
| 68 |
|
| 69 |
|
| 70 |
+
# -----------------------------
|
| 71 |
+
# MAIN
|
| 72 |
+
# -----------------------------
|
| 73 |
+
|
| 74 |
def analyze(hash_value, wordlist_text):
|
| 75 |
|
| 76 |
if wordlist_text.strip():
|
|
|
|
| 82 |
"test23"
|
| 83 |
]
|
| 84 |
|
| 85 |
+
matches = crack_java(hash_value, wordlist)
|
|
|
|
| 86 |
|
| 87 |
+
detected_out = "Java String.hashCode() (detected by integer format)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
if matches:
|
| 90 |
+
result_out = f"Matches: {matches}"
|
|
|
|
|
|
|
| 91 |
else:
|
| 92 |
result_out = "No matches found (try larger wordlist)"
|
| 93 |
|
| 94 |
return detected_out, result_out
|
| 95 |
|
| 96 |
|
| 97 |
+
# -----------------------------
|
| 98 |
+
# UI
|
| 99 |
+
# -----------------------------
|
| 100 |
+
|
| 101 |
with gr.Blocks() as demo:
|
| 102 |
|
| 103 |
+
gr.Markdown("# 🔍 Java hashCode Reverser")
|
| 104 |
|
| 105 |
hash_input = gr.Textbox(label="Hash / Integer Value")
|
| 106 |
|
|
|
|
| 109 |
lines=10
|
| 110 |
)
|
| 111 |
|
| 112 |
+
run_btn = gr.Button("Crack")
|
| 113 |
|
| 114 |
+
detected_out = gr.Textbox(label="Detected Algorithm")
|
| 115 |
result_out = gr.Textbox(label="Recovered Matches")
|
| 116 |
|
| 117 |
run_btn.click(
|