Skip to content

Commit

Permalink
manage all str as unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroZ committed Feb 16, 2018
1 parent 61379c6 commit 8e74c9f
Show file tree
Hide file tree
Showing 52 changed files with 157 additions and 218 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ laZagne.exe browsers

* Launch only a specific software script
```
laZagne.exe browsers -f (for Firefox)
laZagne.exe browsers -firefox
```

* Write all passwords found into a file (-oN for Normal txt, -oJ for Json, -oA for All)
Expand Down
10 changes: 5 additions & 5 deletions Windows/laZagne.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ def write_in_file(result):
prettyJson = json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
with open(os.path.join(constant.folder_name, constant.file_name_results + '.json'), 'a+b') as f:
f.write(prettyJson.decode('unicode-escape').encode('UTF-8'))
constant.st.do_print('[+] File written: {file}'.format(file=os.path.join(constant.folder_name, constant.file_name_results + '.json')))
constant.st.do_print(u'[+] File written: {file}'.format(file=os.path.join(constant.folder_name, constant.file_name_results + '.json')))
except Exception as e:
print_debug('ERROR', 'Error writing the output file: {error}'.format(error=e))
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))

if constant.output == 'txt' or constant.output == 'all':
try:
with open(os.path.join(constant.folder_name, constant.file_name_results + '.txt'), 'a+b') as f:
a = parseJsonResultToBuffer(result)
f.write(a.encode("UTF-8"))
constant.st.write_footer()
constant.st.do_print('[+] File written: {file}'.format(file=os.path.join(constant.folder_name, constant.file_name_results + '.txt')))
constant.st.do_print(u'[+] File written: {file}'.format(file=os.path.join(constant.folder_name, constant.file_name_results + '.txt')))
except Exception as e:
print_debug('ERROR', 'Error writing the output file: {error}'.format(error=e))
print_debug('ERROR', u'Error writing the output file: {error}'.format(error=e))


# Get user list to retrieve their passwords
Expand Down Expand Up @@ -233,7 +233,7 @@ def clean_temporary_files():
for h in constant.hives:
try:
os.remove(constant.hives[h])
print_debug('DEBUG', 'Temporary file removed: {filename}'.format(filename=constant.hives[h]))
print_debug('DEBUG', u'Temporary file removed: {filename}'.format(filename=constant.hives[h]))
except:
pass

Expand Down
10 changes: 5 additions & 5 deletions Windows/lazagne/config/changePrivileges.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def ListSids():
CloseHandle(hToken)
CloseHandle(hProcess)
except Exception as e:
print_debug('ERROR', str(e))
print_debug('ERROR', u'{error}'.format(error=e))

return list(sids)

Expand All @@ -117,14 +117,14 @@ def getSidToken(token_sid):
if hToken:
OpenProcessToken(hProcess, tokenprivs, byref(hToken))
if hToken:
print_debug('INFO', 'Using PID: ' + str(sid[0]))
print_debug('INFO', u'Using PID: ' + str(sid[0]))
CloseHandle(hProcess)
return hToken

# CloseHandle(hToken)
CloseHandle(hProcess)
except Exception, e :
print_debug('ERROR', str(e))
print_debug('ERROR', u'{error}'.format(error=e))
break
return False

Expand All @@ -139,13 +139,13 @@ def getSidToken(token_sid):
if hToken:
if GetTokenSid( hToken ) == token_sid:
print
print_debug('INFO', 'Using PID: ' + str(pid))
print_debug('INFO', u'Using PID: ' + str(pid))
CloseHandle(hProcess)
return hToken
CloseHandle(hToken)
CloseHandle(hProcess)
except Exception, e :
print_debug('ERROR', str(e))
print_debug('ERROR', u'{error}'.format(error=e))

return False

Expand Down
2 changes: 1 addition & 1 deletion Windows/lazagne/config/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class constant():
folder_name = '.'
file_name_results = 'credentials_{current_time}'.format(current_time=date) # the extention is added depending on the user output choice
MAX_HELP_POSITION = 27
CURRENT_VERSION = '2.3.2'
CURRENT_VERSION = '2.3.3'
output = None
file_logger = None

Expand Down
4 changes: 2 additions & 2 deletions Windows/lazagne/config/dpapi/DPAPI/Core/masterkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ def try_credential(self, userSID, password):
if not mk.decrypted:
mk.decryptWithKey(self.system.machine)
if mk.decrypted:
print_debug('INFO', '{password} ok for masterkey {masterkey}'.format(password=password, masterkey=mk.guid))
print_debug('INFO', u'{password} ok for masterkey {masterkey}'.format(password=password, masterkey=mk.guid))
self.passwords.add(password)
n += 1
else:
print_debug('INFO', '{password} not ok for masterkey {masterkey}'.format(password=password, masterkey=mk.guid))
print_debug('INFO', u'{password} not ok for masterkey {masterkey}'.format(password=password, masterkey=mk.guid))

return n

Expand Down
12 changes: 6 additions & 6 deletions Windows/lazagne/config/dpapi/creddec.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def decrypt_credential_block(mkp, credential_block):


def helper_dec_err(err_value):
msg = ''
msg = u''
if err_value == 1:
msg = '[-] MasterKey not found for blob.'
msg = u'[-] MasterKey not found for blob.'
elif err_value == 2:
msg = '[-] Unable to decrypt blob.'
msg = u'[-] Unable to decrypt blob.'
else:
msg = '[-] Decryption error.'
msg = u'[-] Decryption error.'
return msg

def decrypt_user_cred(umkp=None, cred_file=None):
Expand Down Expand Up @@ -85,8 +85,8 @@ def decrypt_user_cred(umkp=None, cred_file=None):

# system type
elif cred_dec.header.unk_type == 2:
return False, 'System credential type'
return False, u'System credential type'

else:
return False, 'Unknown CREDENTIAL type, please report.\nCreds: {creds}'.format(creds=cred_dec)
return False, u'Unknown CREDENTIAL type, please report.\nCreds: {creds}'.format(creds=cred_dec)

2 changes: 1 addition & 1 deletion Windows/lazagne/config/dpapi/preferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def display_masterkey(Preferred):
GUID = struct.unpack("<LHH", GUID1)
GUID2 = struct.unpack(">HLH", GUID2)

return "%s-%s-%s-%s-%s%s" % (format(GUID[0], 'x'), format(GUID[1], 'x'), format(GUID[2], 'x'), format(GUID2[0], 'x'), format(GUID2[1], 'x'), format(GUID2[2], 'x'))
return u"%s-%s-%s-%s-%s%s" % (format(GUID[0], 'x'), format(GUID[1], 'x'), format(GUID[2], 'x'), format(GUID2[0], 'x'), format(GUID2[1], 'x'), format(GUID2[2], 'x'))

28 changes: 20 additions & 8 deletions Windows/lazagne/config/dpapi_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ def __init__(self, password=None, pwdhash=None):

# Preferred file contains the GUID of the last mastekey created
self.last_masterkey_file = os.path.join(masterkeydir, preferred_mk_guid)

# Be sure the preferred mk guid exists, otherwise take the one which have a similar name (sometimes an error occured retreiving the guid)
if not os.path.exists(self.last_masterkey_file):
for folder in os.listdir(masterkeydir):
if folder.startswith(preferred_mk_guid[:6]):
self.last_masterkey_file = os.path.join(masterkeydir, folder)

if os.path.exists(self.last_masterkey_file):
print_debug('DEBUG', 'Last masterkey created: {masterkefile}'.format(masterkefile=self.last_masterkey_file))
print_debug('DEBUG', u'Last masterkey created: {masterkefile}'.format(masterkefile=self.last_masterkey_file))
self.preferred_umkp = masterkey.MasterKeyPool()
self.preferred_umkp.addMasterKey(open(self.last_masterkey_file, 'rb').read())

Expand All @@ -51,11 +58,16 @@ def __init__(self, password=None, pwdhash=None):
self.umkp.addCredhistFile(self.sid, credhist)

if password:
if self.umkp.try_credential(self.sid, str(password)):
if self.try_credential(password):
self.dpapi_ok = True
else:
print_debug('DEBUG', 'Password not correct: {password}'.format(password=password))
print_debug('DEBUG', u'Password not correct: {password}'.format(password=password))

def try_credential(self, password):
try:
return self.umkp.try_credential(self.sid, password)
except:
return False

def check_credentials(self, passwords):
# the password is tested if possible only on the last masterkey file created by the system (visible on the preferred file) to avoid false positive
Expand All @@ -66,9 +78,9 @@ def check_credentials(self, passwords):

if self.umkp:
for password in passwords:
print_debug('INFO', 'Check password: {password}'.format(password=password))
if self.umkp.try_credential(self.sid, str(password)):
print_debug('INFO', 'User password found: {password}\n'.format(password=password))
print_debug('INFO', u'Check password: {password}'.format(password=password))
if self.try_credential(password):
print_debug('INFO', u'User password found: {password}\n'.format(password=password))
self.dpapi_ok = True
return password

Expand All @@ -80,9 +92,9 @@ def decrypt_cred(self, cred_file):
if ok:
return msg
else:
print_debug('DEBUG', msg)
print_debug('DEBUG', u'{msg}'.format(msg=msg))
else:
print_debug('INFO', 'Passwords have not been retrieved. User password seems to be wrong ')
print_debug('INFO', u'Passwords have not been retrieved. User password seems to be wrong ')

return False

Expand Down
58 changes: 0 additions & 58 deletions Windows/lazagne/config/header.py

This file was deleted.

Loading

0 comments on commit 8e74c9f

Please sign in to comment.