Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta_pe: fix rich header length check for hash calculation #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions laikaboss/modules/meta_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def parseRich(self, pe):

result['Rich Header Values'] = data
result['Checksum'] = pe.RICH_HEADER.checksum
result['Hashes'] = self.richHeaderHashes(pe)
hashes = self.richHeaderHashes(pe)
if hashes:
result['Hashes'] = hashes

return result

Expand All @@ -253,17 +255,15 @@ def richHeaderHashes(pe):
"""
Returns hashes of the Rich PE header
"""
rich_data = pe.get_data(0x80, 0x80)
data = list(struct.unpack('<32I', rich_data))
checksum = data[1]
rich_end = data.index(0x68636952)
md5 = hashlib.md5()
sha1 = hashlib.sha1()
sha256 = hashlib.sha256()
for i in range(rich_end):
md5.update(struct.pack('<I', (data[i] ^ checksum)))
sha1.update(struct.pack('<I', (data[i] ^ checksum)))
sha256.update(struct.pack('<I', (data[i] ^ checksum)))
rich = pe.parse_rich_header()
if not rich:
return None
clear_data = rich.get('clear_data', None)
if not clear_data:
return None
md5 = hashlib.md5(clear_data)
sha1 = hashlib.sha1(clear_data)
sha256 = hashlib.sha256(clear_data)
data = {
'MD5': md5.hexdigest(),
'SHA1': sha1.hexdigest(),
Expand Down