34
MalDoc Evolution From ShellExecute to ^LL^ehs^reWO^p TC TLV Feb 2019

MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

MalDoc EvolutionFrom ShellExecute to ^LL^ehs^reWO^p

TC TLV Feb 2019

Page 2: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

WHOAREWE

Asaf Aprozper

Github: 3pun0x

Twitter: @3pun0x

Gal Bitensky

Github: G4lB1t

Twitter: @Gal_B1t

Security researchers@Ex-

Page 3: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

History Class

Page 4: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 5: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 6: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Gabor Szappanos, Sophos, July 2014

Page 7: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 8: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Document open

Download an executable to

%TEMP%ShellExecute

Page 9: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 10: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 11: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

The Research

Page 12: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

The Research

• Motivation

• Selecting 50 campaigns

• Limiting the research scope –anything following the VBA/exploit

• Stepping through the infection stages

Page 13: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Why Fileless?

• Ol’ ShellExecute:• Download/decode an executable payload

• Directly start it from the VBA/exploit

• No longer good enough:• AVs getting better at executable analysis

• Logging and monitoring anomalies

Page 14: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Why Fileless? (cont’d)

• AV 101:• Static vs. dynamic inspection

• Impact on performance

• The limitations of “NG”/ML products

• Chasing blind spots – it works!

Page 15: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

How Much Fileless?

• Fileless is the norm

• 88% of the inspected samples contained fileless stages!• Excluding using a document as an infection vector

• APTs and commodity malware alike

Page 16: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 17: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Why Obfuscation?

• When plain fileless is insufficient

• Easy, open-source projects

•Obfuscation != encryption

Page 18: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Obfuscation 101

Page 19: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Reverse – CMD

• Batch file can read a string backwards

• FOR loop and CALL command combo

Page 20: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

set "ret=" & set "str=%~2"

for /L %%I in (0,1,100) do (

if "!str!"=="" for %%a in ("!ret!") do (

endlocal & set "%~1=%%~a" & exit /b

)

set "ret=!str:~0,1!!ret!"

set "str=!str:~1!"

)

Page 21: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

FORcoding - CMD

• FOR loop iterating over an “ABC array”

Page 22: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

cmd /V:ON /C "setunique=stirf&&FOR %A IN (4 2 3 0 1 1337) do setfinal=!final!!unique:~%A,1!&& IF%A==1337 CALL %final:~-5%"

Page 23: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 24: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Rename

• Let’s copy paste everything!

Page 25: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 26: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

String Concatenation

• String Concatenation

•Story time! ☺

Page 27: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

PS:\> [Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

PS:\> [Ref].Assembly.GetType('System.Management.Automation.Am'+'siUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

https://www.mdsec.co.uk/2018/06/exploring-powershell-amsi-and-logging-evasion/

Page 28: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Environment Variables

• What is an environment variable?

• Potential x86 sandbox bypass?• Program files vs. program files (x86)

• Funny incompatibility with Windows XP• Documents and Settings vs. Users

Page 29: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document
Page 30: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Obfuscation Layers per Sample

Page 31: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

How Much Obfuscation?

Page 32: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Zooming In – Emotet

Page 33: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Fortune Telling: More of the Same

C:\jOuwbsbAQ\PhUHYKKrs\mnlnuaRmUvt\..\..\..\windows\system32\cmd.exe

• Only limited by imagination and esoteric “features”

• Medium-long range:• Solutions will get better

• New genres will emerge

Page 34: MalDoc Evolution · 2019-03-05 · Twitter: @3pun0x Gal Bitensky Github: G4lB1t Twitter: @Gal_B1t Ex- Security researchers@ History Class. Gabor Szappanos, Sophos, July 2014. Document

Questions?