Skip to content

Commit

Permalink
fix UnicodeError (thanks to @byehack)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroZ committed Mar 3, 2020
1 parent ddbfb51 commit ff260de
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Windows/lazagne/config/DPAPI/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def parse(self, data):
self.mkversion = data.eat("L")
self.mkguid = b"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % data.eat("L2H8B")
self.flags = data.eat("L")
self.description = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8")
self.description = data.eat_length_and_string("L").replace(b"\x00", b"")
self.cipherAlgo = crypto.CryptoAlgo(data.eat("L"))
self.keyLen = data.eat("L")
self.salt = data.eat_length_and_string("L")
Expand Down
12 changes: 6 additions & 6 deletions Windows/lazagne/config/DPAPI/credfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def parse(self, data):
if self.header_size > 0:
self.header = CredentialDecryptedHeader()
self.header.parse(data.eat_sub(self.header_size - 4))
self.domain = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.unk_string1 = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.unk_string2 = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.unk_string3 = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.username = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.password = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.domain = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.unk_string1 = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.unk_string2 = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.unk_string3 = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.username = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.password = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode


class CredFile(DataStruct):
Expand Down
2 changes: 1 addition & 1 deletion Windows/lazagne/config/DPAPI/masterkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(self, raw=None):
def parse(self, data):
self.version = data.eat("L")
data.eat("2L")
self.guid = data.eat("72s").decode("UTF-16LE").encode("utf-8")
self.guid = data.eat("72s").replace(b"\x00", b"")
data.eat("2L")
self.policy = data.eat("L")
self.masterkeyLen = data.eat("Q")
Expand Down
24 changes: 12 additions & 12 deletions Windows/lazagne/config/DPAPI/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, raw=None):
def parse(self, data):
self.version = data.eat("L")
self.guid = "%0x-%0x-%0x-%0x%0x-%0x%0x%0x%0x%0x%0x" % data.eat("L2H8B") # data.eat("16s")
self.description = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.description = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.unknown1 = data.eat("L")
self.unknown2 = data.eat("L")
self.unknown3 = data.eat("L")
Expand Down Expand Up @@ -200,7 +200,7 @@ def parse(self, data):
self.last_update = data.eat("Q")
self.vcrd_unknown_2 = data.eat("L")
self.vcrd_unknown_3 = data.eat("L")
self.description = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8") # Unicode
self.description = data.eat_length_and_string("L").replace(b"\x00", b"") # Unicode
self.attributes_array_size = data.eat("L")
# 12 is the size of the VAULT_ATTRIBUTE_MAP_ENTRY
self.attributes_num = self.attributes_array_size // 12
Expand Down Expand Up @@ -232,7 +232,7 @@ def parse(self, data):
self.schema_guid = "%0x-%0x-%0x-%0x%0x-%0x%0x%0x%0x%0x%0x" % data.eat("L2H8B")
self.vault_vsch_unknown_1 = data.eat("L")
self.count = data.eat("L")
self.schema_name = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.schema_name = data.eat_length_and_string("L").replace(b"\x00", b"")


class VaultAttributeItem(object):
Expand Down Expand Up @@ -260,7 +260,7 @@ def parse(self, data):
self.attribute_item.append(
VaultAttributeItem(
id_=data.eat("L"),
item=data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8")
item=data.eat_length_and_string("L").replace(b"\x00", b"")
)
)

Expand Down Expand Up @@ -301,9 +301,9 @@ def parse(self, data):
if self.sid_len > 0:
self.sid = data.eat_sub(self.sid_len)
self.id_resource = data.eat("L")
self.resource = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.resource = data.eat_length_and_string("L").replace(b"\x00", b"")
self.id_password = data.eat("L")
self.authenticator = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00') # Password
self.authenticator = data.eat_length_and_string("L").replace(b"\x00", b"") # Password
self.id_pin = data.eat("L")
self.pin = data.eat_length_and_string("L")

Expand All @@ -329,11 +329,11 @@ def parse(self, data):
self.count = data.eat("L")
self.vault_schema_web_password_unknown1 = data.eat("L")
self.id_identity = data.eat("L")
self.identity = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.identity = data.eat_length_and_string("L").replace(b"\x00", b"")
self.id_resource = data.eat("L")
self.resource = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.resource = data.eat_length_and_string("L").replace(b"\x00", b"")
self.id_authenticator = data.eat("L")
self.authenticator = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.authenticator = data.eat_length_and_string("L").replace(b"\x00", b"")


class VaultSchemaActiveSync(DataStruct):
Expand All @@ -357,11 +357,11 @@ def parse(self, data):
self.count = data.eat("L")
self.vault_schema_activesync_unknown1 = data.eat("L")
self.id_identity = data.eat("L")
self.identity = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.identity = data.eat_length_and_string("L").replace(b"\x00", b"")
self.id_resource = data.eat("L")
self.resource = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00\x00')
self.resource = data.eat_length_and_string("L").replace(b"\x00", b"")
self.id_authenticator = data.eat("L")
self.authenticator = data.eat_length_and_string("L").decode("UTF-16LE").encode("utf-8").rstrip(b'\x00').encode('hex')
self.authenticator = data.eat_length_and_string("L").replace(b"\x00", b"").rstrip(b'\x00').encode('hex')


# Vault Schema Dict
Expand Down
2 changes: 1 addition & 1 deletion Windows/lazagne/softwares/windows/credman.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run(self):
pwd_found.append({
'URL': c.TargetName,
'Login': c.UserName,
'Password': c.CredentialBlob[:c.CredentialBlobSize.real].decode("UTF-16")
'Password': c.CredentialBlob[:c.CredentialBlobSize.real].replace(b"\x00", b"")
})

CredFree(creds)
Expand Down

0 comments on commit ff260de

Please sign in to comment.