-
Notifications
You must be signed in to change notification settings - Fork 525
DATA_DIRECTORY missing entries for malformed values of NumberOfRvaAndSizes #264
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
Comments
pefile seems to be doing the correct thing -- NumberOfRvaAndSizes can legitimately be less than 16, and in that case the bytes associated with the upper data directories might not be valid. For more info, see: https://stackoverflow.com/questions/43306896/image-optional-header-datadirectory-has-fixed-or-variable-size Can you give more information on the sample you are analyzing? |
I have quite the commodity sample here that does what I describe. The file with the following SHA-256 hash is an AgentTesla sample available from VT:
If has the I understand that dealing with malformed executables is a bit of a tough call; this issue & PR are just a suggestion, I can understand if pefile wants to not open this can of worms. |
It seems like all implementations of winnt.h (from the Windows 10 SDK, WINE, MinGW) define I know the various sources of documentation say that NumberOfRvaAndSizes should be used to avoid probing too far, but it is seeming like that differs from how the number of data directory entries is actually implemented (particularly given that there are samples that reduce NumberOfRvaAndSizes but still expect the later entries to be present). Looking at https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#optional-header-image-only, it mentions using the |
Notably, LIEF does parse this as I think it should be parsed. |
I noticed during malware analysis that
pefile
could better handle certain cases where the value ofNumberOfRvaAndSizes
has been reduced to hide the .NET directory information from certain parsers. Such a change can be detected by comparing theSizeOfOptionalHeader
field with the size of the optional header if the givenNumberOfRvaAndSizes
is assumed.To reproduce the problem, take any .NET binary and reduce the value of
NumberOfRvaAndSizes
with a hex editor to0x0000000E
, say. I took a copy ofRegAsm.exe
and patched it:The text was updated successfully, but these errors were encountered: