Closed raashidbhatt closed 9 months ago
test case Invalid payload Dump 471204_27a1f7b4a5d468897a5e4ec62c0214da5023892c441439abb6fe3acfe28a9761
in file 7911e39e07995e3afb97ac0e5a4608c10c2e278bef29924ecc3924edfcc495ca
7911e39e07995e3afb97ac0e5a4608c10c2e278bef29924ecc3924edfcc495ca
Issue confirmed - thanks for the hashes. As you rightly point out, in this sample it is strange that code is left at the pointer to raw data. I think it's likely just the 'manual mapping' performed by the malware to load the image is doing a shoddy job by leaving behind a chunk of raw code in the virtual image.
In terms of improving IsPeImageRaw()
to better handle this, it was apparent that by testing the 'raw' boundary first the function handles this scenario badly. However, by swapping the order of precedence and testing the 'virtual' boundary first, the function will correctly assess this image as virtual and it is dumped correctly with hash 16b184148a8bc29cd9324b9d1e03c241da68b4f66d9de849baa3b90a4d2cd62c
.
The suggested method of checking relocations is in my view too computationally expensive a solution to deal with such a rare scenario as this particular sample and its quirk, particularly when swapping boundary precedence solves the issue. I have therefore opted for this solution in https://github.com/kevoreilly/capemon/commit/69fdd64e44f7fa03fafc20adcd00563f25d52fd8.
Thank you again for your feedback and for helping improve capemon.
Thank you !
The central pointer, where the image is mapped or the raw data is located in memory, is determined. The logic inside
IsPeImageRaw()
works fine but can fail in many scenarios.For example, in the case of Guloader (7911e39e07995e3afb97ac0e5a4608c10c2e278bef29924ecc3924edfcc495ca), after RtlDecompress, the buffer is mapped into memory. AllocationHandler adds the allocation to the monitor list: AllocationHandler: Adding allocation to tracked region list: 0x00410000, size: 0x5000. Thus, during Free or processExit when the list is processed, a dump is mistakenly taken as a Virtual Section boundary. Specifically, in the case of Guloader, in the first section of the PE file, there is a code buffer placed at the PointerToRawData of the first section (which is strange).
The fix:
I have written a small function that checks the presence of relocations in the buffer containing a valid PE. Based on the validity of the relocations, it determines if the buffer is virtually mapped or raw mapped. This function can be called inside IsPeImageRaw() before the boundary checks as a precedence.