Slide 1

Slide 1 text

2021 
 Skrull Like A King! 從重兵看守的天眼防線殺出重圍 [email protected]

Slide 2

Slide 2 text

April 21, 2021 2 Sheng-Hao Ma Threat Researcher at TXOne Networks • Core member of CHROOT Security Group • Over 10-year experience in reverse engineering, Windows vulnerability, and Intel 8086. • Spoke at S&P, BlackHat, DEFCON, HITB, HITCON, VXCON, ROOTCON, CYBERSEC, SITCON, etc. • Instructor of Ministry of National Defense, Ministry of Education, HITCON, and etc. • Publication Windows APT Warfare 惡意程式前線戰術指南

Slide 3

Slide 3 text

Background

Slide 4

Slide 4 text

April 21, 2021 Background 4

Slide 5

Slide 5 text

April 21, 2021 Background 5

Slide 6

Slide 6 text

April 21, 2021 Background 6

Slide 7

Slide 7 text

April 21, 2021 Background 7

Slide 8

Slide 8 text

April 21, 2021 AntiVirus Design • Malware Detection • Signature-Patterns Scanning e.g. YARA • ML: Heuristic-Detection e.g. SVM • Virtual Machine (VM) • When To Scan? • Regular Schedule Service • Minifilter & PsSetCreateProcessNotifyRoutine • Automatic Sample Submission 8

Slide 9

Slide 9 text

April 21, 2021 Challenge 9 • Malware Detection • Signature-Patterns Scanning e.g. YARA • ML: Heuristic-Detection e.g. SVM • Virtual Machine (VM) • When To Scan? • Regular Schedule Service • Minifilter & PsSetCreateProcessNotifyRoutine • Automatic Sample Submission inject malware into trusted system processes, without triggering AV/EDR?

Slide 10

Slide 10 text

April 21, 2021 Challenge 10 • Malware Detection • Signature-Patterns Scanning e.g. YARA • ML: Heuristic-Detection e.g. SVM • Virtual Machine (VM) • When To Scan? • Regular Schedule Service • Minifilter & PsSetCreateProcessNotifyRoutine • Automatic Sample Submission our payload shouldn't be scanned

Slide 11

Slide 11 text

April 21, 2021 Challenge 11 • Malware Detection • Signature-Patterns Scanning e.g. YARA • ML: Heuristic-Detection e.g. SVM • Virtual Machine (VM) • When To Scan? • Regular Schedule Service • Minifilter & PsSetCreateProcessNotifyRoutine • Automatic Sample Submission can we protect our malware against reversing, even if the binary got captured in hand?

Slide 12

Slide 12 text

April 21, 2021 Skynet by AV/EDR 12 • Malware Detection • Signature-Patterns Scanning e.g. YARA • ML: Heuristic-Detection e.g. SVM • Virtual Machine (VM) • When To Scan? • Regular Schedule Service • Minifilter & PsSetCreateProcessNotifyRoutine • Automatic Sample Submission and here's the only way we know about BAD GUYS ...

Slide 13

Slide 13 text

April 21, 2021 Outline A. AV/EDR Real-Time Scan B. The Treasure left since XP: CreateProcessEx C. Force Unlink: Abuse NTFS Streams to Unlink() D. Skrull DRM: 千⾯⼈病毒 & Anti-Copy Malware E. Conclusion 13

Slide 14

Slide 14 text

The Treasure left since XP

Slide 15

Slide 15 text

April 21, 2021 15 Explorer EXE File C:\fishfish.exe got clicked!

Slide 16

Slide 16 text

April 21, 2021 16 EXE File Explorer kernel32!CreateProcessW kernel32!CreateProcessInternalW C:\fishfish.exe got clicked!

Slide 17

Slide 17 text

April 21, 2021 17 EXE File Process PE Header .text .data .idata .reloc file mapping (fishfish.exe) Explorer kernel32!CreateProcessW kernel32!CreateProcessInternalW ntdll!ZwCreateProcessEx( section ) filePtr = fopen( "C:\fishfish.exe" ) C:\fishfish.exe got clicked! Using ZwCreateSection, to create the file as an section That's used for mapping into the process note: in practice, fopen() should be replaced by CreateFile

Slide 18

Slide 18 text

April 21, 2021 18 EXE File PE Header .text PEB .data .idata .reloc .ImageBase Process Explorer kernel32!CreateProcessW kernel32!CreateProcessInternalW ntdll!ZwCreateProcessEx( section ) filePtr = fopen( "C:\fishfish.exe" ) ntdll!RtlCreateProcessParametersEx C:\fishfish.exe got clicked! create a PEB struct & write info manually so we can make process path & cmdlinein in disguise :) path: "C:\fishfish.exe" cmdline: "fishfish.exe http://30cm.tw" workDir: "C:\Windows\System32"

Slide 19

Slide 19 text

April 21, 2021 19 Explorer EXE File kernel32!CreateProcessW kernel32!CreateProcessInternalW ntdll!ZwCreateProcessEx( section ) ntdll!ZwCreateThreadEx PE Header .text .data .idata .reloc filePtr = fopen( "C:\fishfish.exe" ) ntdll!RtlCreateProcessParametersEx Process PEB .ImageBase C:\fishfish.exe got clicked!

Slide 20

Slide 20 text

miniCreateProcessEx https://github.com/aaaddress1/PR0CESS April 21, 2021 20

Slide 21

Slide 21 text

miniCreateProcessEx https://github.com/aaaddress1/PR0CESS April 21, 2021 21 yeah, got signed by M$

Slide 22

Slide 22 text

It's All About The Time :) Hey... Wait a minute. So where's the Antivirus?

Slide 23

Slide 23 text

April 21, 2021 Scan in "Real-Time"? • Microsoft provides a set of APIs for security vendors, to monitor: • PsSetCreateProcessNotifyRoutineEx • PsSetCreateThreadNotifyRoutineEx • It's in Kernel, hard to unhook • Sure, Bad for attackers :(

Slide 24

Slide 24 text

April 21, 2021 Ok, so what they got in hands? • PsSetCreateProcessNotifyRoutineEx: • Recive a PS_CREATE_NOTIFY_INFO struct • It's a record about our child process • FILE_OBJECT corresponds to the file on disk 
 ...yes. it's the object, get by fopen() • ImageFileName & CommandLine 
 We can fake it, not a problem ;) 24 typedef struct _PS_CREATE_NOTIFY_INFO { SIZE_T Size; union { ULONG Flags; struct { ULONG FileFopenNameAvailable : 1; ULONG IsSubsystemProcess : 1; ULONG Reserved : 30; }; }; HANDLE ParentProcessId; CLIENT_ID CreatingThreadId; struct _FILE_OBJECT *FileObject; PCUNICODE_STRING ImageFileName; PCUNICODE_STRING CommandLine; NTSTATUS CreationStatus; };

Slide 25

Slide 25 text

April 21, 2021 Process Notify? When? 25 Explorer EXE File kernel32!CreateProcessW kernel32!CreateProcessInternalW ntdll!ZwCreateProcessEx( section ) ntdll!ZwCreateThreadEx ntdll!RtlCreateProcessParametersEx --- ntdll!ZwCreateUserProcess (Win7+) --- 25 you'll say: hey it's easy, should be here right? filePtr = fopen( "C:\fishfish.exe" )

Slide 26

Slide 26 text

April 21, 2021 Process Notify? When? 26 Explorer EXE File kernel32!CreateProcessW kernel32!CreateProcessInternalW ntdll!ZwCreateProcessEx( section ) ntdll!ZwCreateThreadEx filePtr = fopen( "C:\fishfish.exe" ) ntdll!RtlCreateProcessParametersEx --- ntdll!ZwCreateUserProcess (Win7+) --- 26 you'll say: hey it's easy, should be here right? ... but actually here :) creation of the first thread

Slide 27

Slide 27 text

April 21, 2021 It's not the worst... 27 Explorer EXE File kernel32!CreateProcessW kernel32!CreateProcessInternalW ntdll!ZwCreateProcessEx( section ) ntdll!ZwCreateThreadEx filePtr = fopen( "C:\fishfish.exe" ) ntdll!RtlCreateProcessParametersEx --- ntdll!ZwCreateUserProcess (Win7+) --- 27 scan fopened file & the files listed in PEB typedef struct _PS_CREATE_NOTIFY_INFO { SIZE_T Size; union { ULONG Flags; struct { ULONG FileFopenNameAvailable : 1; ULONG IsSubsystemProcess : 1; ULONG Reserved : 30; }; }; HANDLE ParentProcessId; CLIENT_ID CreatingThreadId; struct _FILE_OBJECT *FileObject; PCUNICODE_STRING ImageFileName; PCUNICODE_STRING CommandLine; NTSTATUS CreationStatus; }; ... but actually here :) creation of the first thread

Slide 28

Slide 28 text

April 21, 2021 28 Attacker filePtr = fopen( "dummy.txt" , "wb") dummy.txt Create a controllable file for attackers. note: in practice, fopen() should be replaced by CreateFile

Slide 29

Slide 29 text

April 21, 2021 29 Attacker PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) WriteFile( filePtr, mimikatz, ... ) 🥝 ntdll!ZwCreateProcessEx( section ) dummy.txt 🥝 # write malware into it # create the file as a new process yeah! so mimikatz landed into the process

Slide 30

Slide 30 text

April 21, 2021 30 Attacker PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) 🥝 ntdll!ZwCreateProcessEx( section ) WriteFile( filePtr, mimikatz, ... ) WriteFile( filePtr, "AAAAAA..." ) dummy.txt "AAAAAAAAAAAAA" # remember that the file is still controled? # this makes it look innocent :)

Slide 31

Slide 31 text

PEB April 21, 2021 31 Attacker ntdll!ZwCreateProcessEx( section ) PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) WriteFile( filePtr, mimikatz, ... ) WriteFile( filePtr, "AAAAAA..." ) ntdll!ZwCreateThreadEx ntdll!RtlCreateProcessParametersEx 🥝 dummy.txt "AAAAAAAAAAAAA"

Slide 32

Slide 32 text

PEB April 21, 2021 32 Attacker ntdll!ZwCreateProcessEx( section ) PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) WriteFile( filePtr, mimikatz, ... ) WriteFile( filePtr, "AAAAAA..." ) ntdll!ZwCreateThreadEx ntdll!RtlCreateProcessParametersEx 🥝 dummy.txt "AAAAAAAAAAAAA" by this trick, AV/EDR always scan the wrong file (not the file run as the process)

Slide 33

Slide 33 text

miniHerpaderping https://github.com/aaaddress1/PR0CESS April 21, 2021 33

Slide 34

Slide 34 text

miniHerpaderping https://github.com/aaaddress1/PR0CESS April 21, 2021 34 we're mspaint.exe now

Slide 35

Slide 35 text

April 21, 2021 Process Doppelganging • The Issue first introduced in BlackHat Europe 2017 "Lost in Transaction: Process Doppelgänging" by @Tal_Liberman • More variety following by this attack vector • Osiris banking Trojan • Herpaderping by @jxy__s • Process Ghosting by @GabrielLandau • Not Sneaky enough in 2021, got blocked by Defender • the well-known Minifilter • provide Defender with the ability to scan written files of NTFS → Find a method to control file data, but not actually write it? 35 WriteFile( filePtr, mimikatz, .. dummy.txt 🥝 filePtr = fopen( "dummy.txt" , "wb")

Slide 36

Slide 36 text

Fileless Do we really need a file to run the process?

Slide 37

Slide 37 text

April 21, 2021 37 Attacker filePtr = fopen( "dummy.txt" , "wb") FileDispositionInfo.DeleteFile = TRUE dummy.txt # using SetFileInformationByHandle, # mark it as a temporary (delete-on-close) file. note: in practice, fopen() should be replaced by CreateFile

Slide 38

Slide 38 text

April 21, 2021 38 Attacker filePtr = fopen( "dummy.txt" , "wb") WriteFile( filePtr, mimikatz, ... ) FileDispositionInfo.DeleteFile = TRUE dummy.txt 🥝 As a result, we're indeed writing malware payload in files on NTFS but Defender cannot access or scan until we close it :)

Slide 39

Slide 39 text

PEB April 21, 2021 39 Attacker ntdll!ZwCreateProcessEx( section ) PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) WriteFile( filePtr, mimikatz, ... ) 🥝 FileDispositionInfo.DeleteFile = TRUE dummy.txt 🥝

Slide 40

Slide 40 text

PEB April 21, 2021 40 Attacker ntdll!ZwCreateProcessEx( section ) PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) WriteFile( filePtr, mimikatz, ... ) ntdll!ZwClose( filePtr ) 🥝 FileDispositionInfo.DeleteFile = TRUE dummy.txt 🥝 bye :) vanish from NTFS # it's temporary, right? # the file vanish, once got closed

Slide 41

Slide 41 text

April 21, 2021 41 Attacker ntdll!ZwCreateProcessEx( section ) filePtr = fopen( "dummy.txt" , "wb") WriteFile( filePtr, mimikatz, ... ) ntdll!ZwClose( filePtr ) FileDispositionInfo.DeleteFile = TRUE PEB PE Header .text .data .idata .reloc Process (dummy.txt) ntdll!ZwCreateThreadEx ntdll!RtlCreateProcessParametersEx 🥝 dummy.txt 🥝

Slide 42

Slide 42 text

PEB Attacker ntdll!ZwCreateProcessEx( section ) PE Header .text .data .idata .reloc filePtr = fopen( "dummy.txt" , "wb") Process (dummy.txt) WriteFile( filePtr, mimikatz, ... ) ntdll!ZwClose( filePtr ) ntdll!ZwCreateThreadEx ntdll!RtlCreateProcessParametersEx 🥝 FileDispositionInfo.DeleteFile = TRUE by this trick AV/EDR *ALWAYS* scan a non-existent file ? dummy.txt 🥝

Slide 43

Slide 43 text

miniGhosting https://github.com/aaaddress1/PR0CESS April 21, 2021 43 name? no, it's fileless :)

Slide 44

Slide 44 text

April 21, 2021 Process Ghosting • Abuse Temporary File, to Run a Ghost Process "What you need to know about Process Ghosting, a new executable image tampering attack" by @GabrielLandau • Totally bypass Defender & The others based on Minifilter → New Idea: Run ourself like a ghost, without Custom-Launcher? 44

Slide 45

Slide 45 text

Arbitrary Unlink Yes, unlink all the files. even a running process

Slide 46

Slide 46 text

April 21, 2021 NTFS Streams - Mark of the Web 46

Slide 47

Slide 47 text

April 21, 2021 NTFS Streams - Malware 47

Slide 48

Slide 48 text

April 21, 2021 NTFS Streams - Malware 48 Write malware to arbitrary stream of innocent files & Run it as a single process even the process is still running but we can delete it anyway :)

Slide 49

Slide 49 text

April 21, 2021 Force Unlink • Windows does not allow the deletion of files from running process • Amazing trick to force unlock files found by @jonasLyk 1. open the file with the DELETE flag 2. relocate EXE data from main stream to another one 3. yes. we can delete it now :) 49

Slide 50

Slide 50 text

April 21, 2021 50 Attacker Malware Dropping & Run Malware.exe ::$DATA 1337 bytes 🥝

Slide 51

Slide 51 text

April 21, 2021 51 Attacker Malware Dropping & Run filePtr = CreateFile( "malware.exe" , DELETE ) FILE_RENAME_INFORMATION.FileName = ":dummy" ntdll!ZwClose( filePtr ) Malware.exe ::$DATA 0 bytes :dummy:$DATA 1337 bytes 🥝 # using SetFileInformationByHandle, relocate the data to the dummy stream

Slide 52

Slide 52 text

April 21, 2021 52 Attacker Malware Dropping & Run filePtr = CreateFile( "malware.exe" , DELETE ) FILE_RENAME_INFORMATION.FileName = ":dummy" ntdll!ZwClose( filePtr ) Malware.exe ::$DATA 0 bytes :dummy:$DATA 1337 bytes kernel32!DeleteFile( "malware.exe" ) 🥝

Slide 53

Slide 53 text

April 21, 2021 53 Attacker Malware Dropping & Run filePtr = CreateFile( "malware.exe" , DELETE ) FILE_RENAME_INFORMATION.FileName = ":dummy" ntdll!ZwClose( filePtr ) Malware.exe ::$DATA Signed Benignware :dummy:$DATA Malware Running🥝 Fill In Payload of Signed EXE during AV/EDR scheduled scanning, always fetch the EXE data from the main stream ?

Slide 54

Slide 54 text

DEMO File Unlink & Forged Sign https://github.com/aaaddress1/Skrull

Slide 55

Slide 55 text

Skrull: Anti-Copy Launcher Fileless Malware Launcher: to Armor Malware and Deploy on Victim

Slide 56

Slide 56 text

April 21, 2021 Automatic Sample Submission • most AV/EDR embedded the feature as default e.g. Windows Defender • Invoke when attackers carelessly do the suspicious behaviors • AV/EDR keep eyes on attackers by collecting those dropped files & analysis • Fileless is cool. but attackers need to deploy persistent trojan for long-term monitoring → Find a method to let the files naturally broken when submitted? 56

Slide 57

Slide 57 text

April 21, 2021 🚀Skrull DRM: Anti-Copy Malware Launcher • Anti-Copy Malware Launcher • Running Malware by Process-Ghosting method • DRM: The Launch couldn't copied to another environment • Easy for attackers to run malware persistently & evade AV/EDR • Anti-Copy DRM for Malware • Obtain unique features on the victim's environment • User Name, System Version, CPU count, etc. • Should not be reproduced on the different environment • Use those features, to reassemble our EXE file • EXE files will be naturally broken when copied 57

Slide 58

Slide 58 text

April 21, 2021 Skrull 58 Attacker run launcher Skrull.exe Collect Unique Features on victim Reassemble & Armor itself (Persistence & Anti-Copy) *contain malware payload*

Slide 59

Slide 59 text

April 21, 2021 Skrull 59 Attacker Malware.exe 🥝 run launcher Skrull.exe Decrypt Malware Payload Collect Unique Features on victim Reassemble & Armor itself Launch the Malware by Ghosting Trick (Persistence & Anti-Copy) (Fileless)

Slide 60

Slide 60 text

April 21, 2021 Skrull 60 Attacker AV/EDR Lab Malware.exe 🥝 run launcher Skrull.exe Decrypt Malware Payload Collect Unique Features on victim Reassemble & Armor itself Launch the Malware by Ghosting Trick (Persistence & Anti-Copy) (Fileless) always capture broken files (Auto Sample Submit)

Slide 61

Slide 61 text

DEMO Skrull: Malware DRM https://github.com/aaaddress1/Skrull

Slide 62

Slide 62 text

Conclusion

Slide 63

Slide 63 text

April 21, 2021 Conclusion • Process Ghosting: Attackers can abuse temporary files to create processes that will not be scanned by AV/EDR Real-Time Scan • File Unlink: Delete running programs by migrating data between NTFS streams • DRM: Malware rebuild itself before being submitted by AV/EDR, so it can perfectly resist follow-up analysis by researchers • Malware Scheduled & Real-Time Scan A. shouldn't assume all running process must have EXE file on NTFS B. shouldn't only scan for files on NTFS, but also for running processes, to prevent fileless & DRM attacks 63

Slide 64

Slide 64 text

© 2021