Skip to content

Commit

Permalink
WIP py3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroZ committed Apr 2, 2019
1 parent ce1b46b commit b4b6f6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Windows/lazagne/config/DPAPI/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from lazagne.config.crypto.pyaes.aes import AESModeOfOperationCBC, AESModeOfOperationECB
from lazagne.config.crypto.pyDes import triple_des, des, ECB, CBC
from lazagne.config.winstructure import char_to_int
from lazagne.config.write_output import encode, decode


try:
xrange
Expand Down Expand Up @@ -313,9 +315,9 @@ def pbkdf2(passphrase, salt, keylen, iterations, digest='sha1'):
derived = hmac.new(passphrase, U, digestmod=lambda: hashlib.new(digest)).digest()
for r in xrange(iterations - 1):
actual = hmac.new(passphrase, derived, digestmod=lambda: hashlib.new(digest)).digest()
derived = ''.join([chr(char_to_int(x) ^ char_to_int(y)) for (x, y) in zip(derived, actual)])
buff += derived
return buff[:keylen]
derived = encode(''.join([chr(char_to_int(x) ^ char_to_int(y)) for (x, y) in zip(derived, actual)]))
buff += decode(derived)
return buff[:int(keylen)]


def derivePwdHash(pwdhash, sid, digest='sha1'):
Expand All @@ -331,9 +333,9 @@ def dataDecrypt(cipherAlgo, hashAlgo, raw, encKey, iv, rounds):
"""
hname = {"HMAC": "sha1"}.get(hashAlgo.name, hashAlgo.name)
derived = pbkdf2(encKey, iv, cipherAlgo.keyLength + cipherAlgo.ivLength, rounds, hname)
key, iv = derived[:cipherAlgo.keyLength], derived[cipherAlgo.keyLength:]
key = key[:cipherAlgo.keyLength]
iv = iv[:cipherAlgo.ivLength]
key, iv = encode(derived[:int(cipherAlgo.keyLength)]), encode(derived[int(cipherAlgo.keyLength):])
key = key[:int(cipherAlgo.keyLength)]
iv = iv[:int(cipherAlgo.ivLength)]

if "AES" in cipherAlgo.name:
cipher = AESModeOfOperationCBC(key, iv=iv)
Expand Down
18 changes: 18 additions & 0 deletions Windows/lazagne/config/write_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,21 @@ def write_in_file(result):
)
except Exception as e:
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))


def encode(string):
if sys.version_info > (3, 0):
# Python 3
return string.encode()
else:
# Python 2
return string


def decode(string):
if sys.version_info > (3, 0):
# Python 3
return string.decode()
else:
# Python 2
return string

0 comments on commit b4b6f6a

Please sign in to comment.