Skip to content

Commit

Permalink
Refactoring. Function Win32CryptUnprotectData returns bytes instead o…
Browse files Browse the repository at this point in the history
…f str.
  • Loading branch information
MyLoginOnGitHub committed Jan 3, 2020
1 parent 8baa73a commit b0c72ac
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Windows/lazagne/config/winstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,11 @@ def Win32CryptUnprotectData(cipherText, entropy=False, is_current_user=True, use
blobEntropy = DATA_BLOB(len(entropy), bufferEntropy)

if CryptUnprotectData(byref(blobIn), None, byref(blobEntropy), None, None, 0, byref(blobOut)):
decrypted = getData(blobOut).decode("utf-8")
decrypted = getData(blobOut)

else:
if CryptUnprotectData(byref(blobIn), None, None, None, None, 0, byref(blobOut)):
decrypted = getData(blobOut).decode("utf-8")
decrypted = getData(blobOut)

if not decrypted:
can_decrypt = True
Expand Down
5 changes: 3 additions & 2 deletions Windows/lazagne/softwares/browsers/chromium_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ def _export_credentials(self, db_path, is_yandex=False):
# Failed...
else:
# Decrypt the Password
password = Win32CryptUnprotectData(password, is_current_user=constant.is_current_user,
user_dpapi=constant.user_dpapi)
password_bytes = Win32CryptUnprotectData(password, is_current_user=constant.is_current_user,
user_dpapi=constant.user_dpapi)
password = password_bytes.decode("utf-8")

if not url and not login and not password:
continue
Expand Down
3 changes: 2 additions & 1 deletion Windows/lazagne/softwares/browsers/ie.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def history_from_regedit(self):
def decipher_password(self, cipher_text, u):
pwd_found = []
# deciper the password
pwd = win.Win32CryptUnprotectData(cipher_text, u, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
pwd_bytes = win.Win32CryptUnprotectData(cipher_text, u, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
pwd = pwd_bytes.decode("utf-8")
a = ''
if pwd:
for i in range(len(pwd)):
Expand Down
3 changes: 2 additions & 1 deletion Windows/lazagne/softwares/chats/skype.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_regkey(self):

# num = winreg.QueryInfoKey(hkey)[1]
k = winreg.EnumValue(hkey, 0)[1]
return win.Win32CryptUnprotectData(k, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
result_bytes = win.Win32CryptUnprotectData(k, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
return result_bytes.decode("utf-8")
except Exception as e:
self.debug(str(e))
return False
Expand Down
4 changes: 2 additions & 2 deletions Windows/lazagne/softwares/mails/outlook.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def retrieve_info(self, hkey, name_key):
k = winreg.EnumValue(hkey, x)
if 'password' in k[0].lower():
try:
password = win.Win32CryptUnprotectData(k[1][1:], is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
values[k[0]] = password
password_bytes = win.Win32CryptUnprotectData(k[1][1:], is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
values[k[0]] = password_bytes.decode("utf-8")
except Exception as e:
self.debug(str(e))
values[k[0]] = 'N/A'
Expand Down
4 changes: 2 additions & 2 deletions Windows/lazagne/softwares/svn/tortoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def run(self):
# encrypted the password
if result:
try:
password = Win32CryptUnprotectData(base64.b64decode(result), is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
password_bytes = Win32CryptUnprotectData(base64.b64decode(result), is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
pwd_found.append({
'URL': url,
'Login': username,
'Password': str(password)
'Password': password_bytes.decode("utf-8")
})
except Exception:
pass
Expand Down
4 changes: 2 additions & 2 deletions Windows/lazagne/softwares/sysadmin/cyberduck.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def run(self):
or elem.attrib['name'].startswith('sftp') or elem.attrib['name'].startswith('http') \
or elem.attrib['name'].startswith('https'):
encrypted_password = base64.b64decode(elem.attrib['value'])
password = Win32CryptUnprotectData(encrypted_password, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
password_bytes = Win32CryptUnprotectData(encrypted_password, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
pwd_found.append({
'URL': elem.attrib['name'],
'Password': password,
'Password': password_bytes.decode("utf-8"),
})
except Exception as e:
self.debug(str(e))
Expand Down
9 changes: 5 additions & 4 deletions Windows/lazagne/softwares/sysadmin/openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def check_openvpn_installed(self):
return False

def decrypt_password(self, encrypted_password, entropy):
return Win32CryptUnprotectData(encrypted_password,
entropy=entropy,
is_current_user=constant.is_current_user,
user_dpapi=constant.user_dpapi)
result_bytes = Win32CryptUnprotectData(encrypted_password,
entropy=entropy,
is_current_user=constant.is_current_user,
user_dpapi=constant.user_dpapi)
return result_bytes.decode("utf-8")

def get_credentials(self, key):
pwd_found = []
Expand Down
3 changes: 2 additions & 1 deletion Windows/lazagne/softwares/sysadmin/rdpmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self):
def decrypt_password(self, encrypted_password):
try:
decoded = base64.b64decode(encrypted_password)
password_decrypted = Win32CryptUnprotectData(decoded, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
password_decrypted_bytes = Win32CryptUnprotectData(decoded, is_current_user=constant.is_current_user, user_dpapi=constant.user_dpapi)
password_decrypted = password_decrypted_bytes.decode("utf-8")
password_decrypted = password_decrypted.replace('\x00', '')
except Exception:
password_decrypted = encrypted_password.replace('\x00', '')
Expand Down

0 comments on commit b0c72ac

Please sign in to comment.