cuckoosandbox / monitor

The new Cuckoo Monitor.
GNU General Public License v3.0
334 stars 166 forks source link

Some exploit docs crash with or without monitor injection #21

Open jjo-sec opened 8 years ago

jjo-sec commented 8 years ago

VM: Win7SP1 x32, Office 2013 (also occurs in Office 2010 in Win7 and WinXP)

One Example: This is actually an rtf file that should be named as .doc ( I can share more samples privately if needed ): https://malwr.com/analysis/OTdkMGNiMjI4NjcxNDVhZjg5NzUzZGFiNjBmOTlmMzY/

These documents exploit CVE-2015-1641, so it is possible that something to do with the way the exploit works is causing this issue. The shellcode has some standard obfuscation and then walks the PEB and loaded DLLs to find what it is looking for.

I have managed to trace the crash issue down to inject-x86.exe - If i manually run inject-x86.exe --free --app and then open the doc, it crashes during the exploitation process. If i manually type in cmd prompt and open the doc, the exploitation process succeeds. The documents worked when using Cuckoo 1.X's method of CreateProcessA vs calling inject.exe's shellcode injection to spawn.

Exception seen when injected, possible false flag:

    stacktrace: bson_check_string+0x37 bson_check_field_name-0x2 @ 0x63beb240 bson_append_minkey+0x81 bson_append_string-0x8b @ 0x63bea270 bson_append_string_n+0x2e bson_append_symbol_n-0x2 @ 0x63bea3d1 log_string+0x8f log_wstring-0x5f @ 0x63bc4cc8 log_api+0x264 log_new_process-0xaf2 @ 0x63bc58c8 New_advapi32_RegEnumValueA@32+0x19a New_advapi32_RegEnumValueW@32-0x20 @ 0x63bcffd3 _MsoFDoSmartTagSecurityCheck@8+0x862 _MsoTelemetryLogControl@8-0x575d4 mso+0x66a4fb @ 0x201a4fb _MsoFDoSmartTagSecurityCheck@8+0x11a7 _MsoTelemetryLogControl@8-0x56c8f mso+0x66ae40 @ 0x201ae40 _MsoFDoSmartTagSecurityCheck@8+0x1106 _MsoTelemetryLogControl@8-0x56d30 mso+0x66ad9f @ 0x201ad9f DllGetLCID+0xa09ef ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x4aa7a1 wwlib+0x2f2ce5 @ 0x64c82ce5 DllGetLCID+0xa0951 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x4aa83f wwlib+0x2f2c47 @ 0x64c82c47 DllGetLCID+0x403e83 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x14730d wwlib+0x656179 @ 0x64fe6179 DllGetLCID+0x403e3f ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x147351 wwlib+0x656135 @ 0x64fe6135 DllGetLCID+0x403d8c ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x147404 wwlib+0x656082 @ 0x64fe6082 DllGetLCID+0x20b518 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x33fc78 wwlib+0x45d80e @ 0x64ded80e _MsoFreeCvsList@4+0x196d7 _MsoPwlfFromFlinfo@8-0x24bd49 mso+0x29a430 @ 0x1c4a430 _MsoDwWhichMessengerRunningEx@0+0x28b49 _MsoDestroyITFC@4-0x30b82 mso+0x23c1c9 @ 0x1bec1c9 DllRegisterServer+0x432b6 DllSetProperty-0x5b932 msxml6+0x68853 @ 0x719f8853 DllRegisterServer+0x4416a DllSetProperty-0x5aa7e msxml6+0x69707 @ 0x719f9707 DllRegisterServer+0x4416a DllSetProperty-0x5aa7e msxml6+0x69707 @ 0x719f9707 DllRegisterServer+0x4416a DllSetProperty-0x5aa7e msxml6+0x69707 @ 0x719f9707 DllRegisterServer+0x4416a DllSetProperty-0x5aa7e msxml6+0x69707 @ 0x719f9707 DllRegisterServer+0x41f32 DllSetProperty-0x5ccb6 msxml6+0x674cf @ 0x719f74cf DllRegisterServer+0x44b76 DllSetProperty-0x5a072 msxml6+0x6a113 @ 0x719fa113 DllRegisterServer+0x42b1e DllSetProperty-0x5c0ca msxml6+0x680bb @ 0x719f80bb _MsoDwWhichMessengerRunningEx@0+0x1f9a2 _MsoDestroyITFC@4-0x39d29 mso+0x233022 @ 0x1be3022 _MsoFreeCvsList@4+0x17de3 _MsoPwlfFromFlinfo@8-0x24d63d mso+0x298b3c @ 0x1c48b3c DllGetClassObject+0x39e36 DllGetLCID-0x21385d wwlib+0x3ea99 @ 0x649cea99 DllGetClassObject+0x36a0a DllGetLCID-0x216c89 wwlib+0x3b66d @ 0x649cb66d DllGetClassObject+0x3268d DllGetLCID-0x21b006 wwlib+0x372f0 @ 0x649c72f0 DllGetClassObject+0x32318 DllGetLCID-0x21b37b wwlib+0x36f7b @ 0x649c6f7b DllGetClassObject+0x30462 DllGetLCID-0x21d231 wwlib+0x350c5 @ 0x649c50c5 DllGetClassObject+0x2fc15 DllGetLCID-0x21da7e wwlib+0x34878 @ 0x649c4878 DllGetLCID+0xa2634 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x4a8b5c wwlib+0x2f492a @ 0x64c8492a DllGetLCID+0x94522 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x4b6c6e wwlib+0x2e6818 @ 0x64c76818 DllGetLCID+0x459c6b ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf1525 wwlib+0x6abf61 @ 0x6503bf61 DllGetLCID+0x4598d3 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf18bd wwlib+0x6abbc9 @ 0x6503bbc9 OleSetMenuDescriptor+0xef1 ReadStringStream-0x53e ole32+0x5eb44 @ 0x75a9eb44 OleLoad+0x112 OleDoAutoConvert-0x1d ole32+0x5f2af @ 0x75a9f2af OleLoad+0x37 OleDoAutoConvert-0xf8 ole32+0x5f1d4 @ 0x75a9f1d4 _MsoFPuncWch@4+0x5e641 _MsoGetFidCSSeqChkDll@0-0x1fcd6 mso+0xa3d608 @ 0x23ed608 DllGetLCID+0x459550 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf1c40 wwlib+0x6ab846 @ 0x6503b846 DllGetLCID+0x459457 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf1d39 wwlib+0x6ab74d @ 0x6503b74d DllGetLCID+0x458f19 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf2277 wwlib+0x6ab20f @ 0x6503b20f DllGetLCID+0x458d38 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf2458 wwlib+0x6ab02e @ 0x6503b02e DllGetLCID+0x45898d ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf2803 wwlib+0x6aac83 @ 0x6503ac83 DllGetLCID+0x45446a ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0xf6d26 wwlib+0x6a6760 @ 0x65036760 DllGetLCID+0x43ff23 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x10b26d wwlib+0x692219 @ 0x65022219 DllGetLCID+0x43e5c5 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x10cbcb wwlib+0x6908bb @ 0x650208bb DllGetLCID+0x43bf9f ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x10f1f1 wwlib+0x68e295 @ 0x6501e295 DllGetLCID+0x43b4fa ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x10fc96 wwlib+0x68d7f0 @ 0x6501d7f0 DllGetClassObject+0x233e1a DllGetLCID-0x19879 wwlib+0x238a7d @ 0x64bc8a7d DllGetClassObject+0x2fc15 DllGetLCID-0x21da7e wwlib+0x34878 @ 0x649c4878 DllGetLCID+0xa2634 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x4a8b5c wwlib+0x2f492a @ 0x64c8492a DllGetLCID+0x94522 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x4b6c6e wwlib+0x2e6818 @ 0x64c76818 ?OSFCreateOfficeExtensionsDialogUser@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z+0xfb02f wdCommandDispatch-0x10ee45 wwlib+0x898677 @ 0x65228677 DllGetLCID+0x326892 ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x2248fe wwlib+0x578b88 @ 0x64f08b88 DllGetLCID+0x17706f ?OSFCreateOsfOartGallery@Osf@@YGXAAUIControl@OfficeSpace@@V?$TWeakPtr@VUserInterface@Art@@@Ofc@@AAV?$TCntPtr@UIDataSource@OfficeSpace@@@5@@Z-0x3d4121 wwlib+0x3c9365 @ 0x64d59365 DllGetClassObject+0x2e77 DllGetLCID-0x24a81c wwlib+0x7ada @ 0x64997ada FMain+0x253 DllGetClassObject-0x260 wwlib+0x4a03 @ 0x64994a03 wdCommandDispatch-0x370 winword+0x15c4 @ 0xbd15c4 wdCommandDispatch-0x3dc winword+0x1558 @ 0xbd1558 BaseThreadInitThunk+0x12 SetUnhandledExceptionFilter-0xbc kernel32+0x53c45 @ 0x76c43c45 RtlInitializeExceptionChain+0xef RtlFreeSid-0x117 ntdll+0x637f5 @ 0x776437f5 
    exception.instruction_r: 0f b6 00 0f b6 c0 0f b6 80 60 6b c2 63 0f be c0 
    exception.instruction: movzx eax, byte ptr [eax] 
    exception.exception_code: 0xc0000005 
    exception.symbol: bson_swap_endian32+0x2ad bson_check_string-0x87 
    exception.address: 0x63beb182 
    registers.esp: 2570528 
    registers.edi: 1 
    registers.eax: 195235840 
    registers.ebp: 2570564 
    registers.edx: 195231752 
    registers.ebx: 259 
    registers.esi: 0 
    registers.ecx: 1 
jbremer commented 8 years ago

Interesting, thanks! Will investigate further soon. Seems that the cause is the logging of RegEnumValueA, but will have to see which parameter :)

knifeyspoony commented 8 years ago

Hey, I'm seeing this issue with PDFs as well, which leads me to believe that it might be a bug in the logging facilities.

knifeyspoony commented 8 years ago

From my limited debugging capability with the monitor, it looks like the crash is due to the parameter

LPTSTR lpValueName regkey_r

When I disabled it, it crashed later at RegEnumKeyExA, presumably when trying to log the same parameter.

Looking at report.json, the regkey field contains unicode characters at the end. (in this case \uFFB4). I'll try to see why this causes a crash, but hopefully this helps you @jbremer !

knifeyspoony commented 8 years ago

It looks like this happens when trying to encode ascii as UTF-8, but a non-ascii character is encountered.

If you have a signed char* above 0x7F, it gets sign extended. For example:

A char* buffer starts with the value 0x81, and then has some other bytes.. So utf8_bytecnt_ascii will pass 0xFFFFFF81 to utf8_length, which expects an uint32_t. This is then passed along to utf8_encode, which checks 0xFFFFFF81 and returns -1. Now, this becomes a problem when you try to actually write the encoded string to the utf8string buffer.

The utf8string holds the length in the first 4 bytes, and the buffer follows. When the first character is "written", using utf8_encode, the pos variable is incremented by the number of bytes written (-1). Now when the NEXT byte is written, it's actually overwriting the length value in the utf8string buffer!! This kills the dll down the road when the string is checked ;)

I guess a solution would be to force the character to be unsigned, or, escape non ascii characters when encoding what we think is an ascii string.

jbremer commented 8 years ago

I've pushed a new version of monitor including a fix for the bug as reported by @knifeyspoony. Thanks a lot for that! @arbor-jjones Could you please verify if your bug is still present with the latest monitor?

jjo-sec commented 8 years ago

I am still seeing crashes with injection both enabled and disabled on both win7 and winxp. The exception causing the crash with injection has changed and hopefully will match the exception that happens without injection. The documents are similar to what is blogged here in that they have mangled RTF headers and exploit the same vulnerability, but their shellcode is obfuscated and they are being used in targeted attacks : http://www.sekoia.fr/blog/ms-office-exploit-analysis-cve-2015-1641/

New exception:

stacktrace:
DllSetProperty+0x1e162 msxml6+0xe22e7 @ 0x715322e7
DllRegisterServer+0x99b94 DllSetProperty-0x5054 msxml6+0xbf131 @ 0x7150f131
DllRegisterServer+0x41f32 DllSetProperty-0x5ccb6 msxml6+0x674cf @ 0x714b74cf
DllRegisterServer+0x44b76 DllSetProperty-0x5a072 msxml6+0x6a113 @ 0x714ba113
DllRegisterServer+0x42b1e DllSetProperty-0x5c0ca msxml6+0x680bb @ 0x714b80bb
_MsoFreeCvsList@4+0x58d94 _MsoFHideTaiwan@0-0x13183 mso+0x25d04e @ 0x666ad04e
_MsoFreeCvsList@4+0x58622 _MsoFHideTaiwan@0-0x138f5 mso+0x25c8dc @ 0x666ac8dc
_MsoFreeCvsList@4+0x6728 _MsoFHideTaiwan@0-0x657ef mso+0x20a9e2 @ 0x6665a9e2
_MsoFreeCvsList@4+0x6538 _MsoFHideTaiwan@0-0x659df mso+0x20a7f2 @ 0x6665a7f2
_GetAllocCounters@0+0x2229e DllGetLCID-0x1d4990 wwlib+0x39066 @ 0x68a09066
_GetAllocCounters@0+0x21ba4 DllGetLCID-0x1d508a wwlib+0x3896c @ 0x68a0896c
_GetAllocCounters@0+0x1e62d DllGetLCID-0x1d8601 wwlib+0x353f5 @ 0x68a053f5
_GetAllocCounters@0+0x1e2b3 DllGetLCID-0x1d897b wwlib+0x3507b @ 0x68a0507b
_GetAllocCounters@0+0x1c43b DllGetLCID-0x1da7f3 wwlib+0x33203 @ 0x68a03203
_GetAllocCounters@0+0x1bc92 DllGetLCID-0x1daf9c wwlib+0x32a5a @ 0x68a02a5a
_GetAllocCounters@0+0x1552f DllGetLCID-0x1e16ff wwlib+0x2c2f7 @ 0x689fc2f7
_GetAllocCounters@0+0x2077 DllGetLCID-0x1f4bb7 wwlib+0x18e3f @ 0x689e8e3f
DllGetClassObject+0x29ea _GetAllocCounters@0-0xee02 wwlib+0x7fc6 @ 0x689d7fc6
FMain+0x245 DllGetClassObject-0x2a0 wwlib+0x533c @ 0x689d533c
wdCommandDispatch-0x964 winword+0x1602 @ 0x2fa01602
wdCommandDispatch-0x9cc winword+0x159a @ 0x2fa0159a
BaseThreadInitThunk+0x12 SetUnhandledExceptionFilter-0xbc kernel32+0x53c45 @ 0x761b3c45
RtlInitializeExceptionChain+0xef RtlFreeSid-0x117 ntdll+0x637f5 @ 0x775a37f5
RtlInitializeExceptionChain+0xc2 RtlFreeSid-0x144 ntdll+0x637c8 @ 0x775a37c8

exception.instruction_r: c9 c2 10 00 89 45 c0 eb ed 64 a1 18 00 00 00 8b 
exception.instruction: leave 
exception.exception_code: 0xe0000002 
exception.symbol: RaiseException+0x54 BaseReleaseProcessDllPath-0x100 kernelbase+0xb760 
exception.address: 0x7571b760 
registers.esp: 1461412 
registers.edi: 146382008 
registers.eax: 1461412 
registers.ebp: 1461492 
registers.edx: 0 
registers.ebx: 146381808 
registers.esi: 146381820 
registers.ecx: 1 
jbremer commented 8 years ago

@arbor-jjones I'm not sure if I can help with that one. According to https://msdn.microsoft.com/en-us/library/het71c37.aspx this error code is defined as follows, which would make me believe that your version of Office doesn't support this particular file. Of course if you can open the file without Cuckoo / injection running than something else is going wrong. Given the mangling as explained in the blogpost I wouldn't be surprised if something went wrong.

#define STATUS_FILE_BAD_FORMAT        0xE0000002
jjo-sec commented 8 years ago

That's definitely an odd error, but it seems to only occur when WinWord is launched using inject-x86 - with or without injection specified.

I verified that manually opening the documents in a cuckoo VM directly with winword or launching inside of a Sandboxie sandbox and the exploitation happens successfully.

I did manual testing in Win7x86/WinXP with Office 2010 / 2013 (do not have access to any Office version below that, so cannot tell if this is something that only occurs in newer office versions) where I manually ran inject-x86.exe with the path to word and injection disabled via the CLI option and then opened the document inside word and experienced the same crashes that I see when Cuckoo runs with injection.

Example file that worked in Cuckoo 1.X (where winword was launched via createprocess), but I see crashes in 2.X:

https://malwr.com/analysis/ZGM1OTdjMTZhODlkNDYxNjliYTg1ZDU4OGU1YzBjZjU/#

There should be a dropped dll that gets run via rundll32 and a dropped decoy doc if the exploitation is successful like it is when run not with inject-x86 / cuckoo.

jbremer commented 8 years ago

Do you have any idea whether the issues from this thread are still present? I believe quite a few of them should be resolved by now. @arbor-jjones

jjo-sec commented 8 years ago

When run without injection all appears to function correctly now, but still see premature crashes instead of finishing the payload execution / respawn decoy doc when run with injection.

I tried changing the mode to exploit and office using the latest commits in both monitor and cuckoo, but still am not able to achieve full execution of the exploit and subsequent dropped payload.

jbremer commented 8 years ago

Oke thanks :-) To be continued soon then ;-)