Owowning With The Windows Api: Dijit (@secfurry)
Owowning With The Windows Api: Dijit (@secfurry)
Windows API
Dijit (@secfurry)
1
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
$(whoami)
• I’m Dijit!
• @secfurry
• Loves
• Purple
• Programming
• Video Games
• Hacking
• Offensive Security Engineer
• Specializes in Windows security
3
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
OvOerview: What’s this about?
• Windows API Techniques
• Parent Process Spoofing
• Shellcode Injection
• Using undocumented functions
• Methodologies
• Code
• Execution
• Detection / Prevention
• Final Thoughts / Lessons Learned
• “Hack it Forward”
• Expand the Windows API knowledge
• Document “undocumented” or obscure functions
• Introduce new methods to execute code
• Security Engineer / Red Teamer
• Evade Detection
• Hunter / Blue Teamer
• Examples of Red Team methodologies
11
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Parent Process Spoofing: Background
installer.exe
Process Tree
explorer.exe
installer.exe
Process Tree
explorer.exe
2. Requires Admin
consent.exe
Rights, UAC Prompt
Started
consent.exe
installer.exe
Process Tree
explorer.exe
2. Requires Admin
consent.exe
Rights, UAC Prompt
Started
3. UAC Passed. UAC
consent.exe Launches Executable
1. Launch Executable
malware.exe target.exe
Process Tree
explorer.exe
malware.exe
target.exe
malware.exe
OpenProcess
target.exe
Process Tree
explorer.exe
2. Obtain Handle to
Target Process malware.exe
target.exe
malware.exe
OpenProcess
target.exe
Process Tree
explorer.exe
3. Create New 2. Obtain Handle to
STARTUPINFOEX Struct Target Process malware.exe
target.exe
malware.exe
OpenProcess
target.exe
Process Tree
explorer.exe
3. Create New 2. Obtain Handle to
STARTUPINFOEX Struct Target Process malware.exe
4. Call Function target.exe
InitializeProcThreadAttributeList
malware.exe
OpenProcess
target.exe
Process Tree
explorer.exe
3. Create New 2. Obtain Handle to
STARTUPINFOEX Struct Target Process malware.exe
4. Call Function target.exe
InitializeProcThreadAttributeList
malware.exe
OpenProcess
target.exe
Process Tree
explorer.exe
3. Create New 2. Obtain Handle to
STARTUPINFOEX Struct Target Process malware.exe
4. Call Function target.exe
InitializeProcThreadAttributeList
malware.exe
OpenProcess
target.exe
Process Tree
explorer.exe
3. Create New 2. Obtain Handle to
STARTUPINFOEX Struct Target Process malware.exe
Child Of
4. Call Function target.exe
InitializeProcThreadAttributeList
cmd.exe
5. Update the AttributeList with a Pointer
cmd.exe
to the Target Process Handle using
UpdateProcThreadAttribute 7. New Process
Created!
6. Use the STARTUPINFOEX struct in the
CreateProcess Function with the
EXTENDED_STARTUPINFO_PRESENT Flag
OwOwning with the Windows API | @secfurry 2020 | secfurry.com 27
Parent Process Spoofing: Code
33
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Parent Elevated Process
Spoofing
Let’s go deeper (UwU)
34
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Parent Process Spoofing: Elevated
malware.exe winlogon.exe
Process Tree
explorer.exe
1A. Open Handle to Self Using
OpenProcessToken malware.exe
winlogon.exe
malware.exe winlogon.exe
Process Tree
explorer.exe
1A. Open Handle to Self Using
OpenProcessToken malware.exe
malware.exe winlogon.exe
Process Tree
explorer.exe
1A. Open Handle to Self Using
OpenProcessToken malware.exe
malware.exe
OpenProcess
winlogon.exe
Process Tree
explorer.exe
3. Create New 2. Obtain Handle to
STARTUPINFOEX Struct Target Process malware.exe
Child Of
4. Call Function winlogon.exe
InitializeProcThreadAttributeList
cmd.exe
5. Update the AttributeList with a Pointer
cmd.exe
to the Target Process Handle using
UpdateProcThreadAttribute 7. New Process Created!
45
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Parent Process Spoofing: Detection
[2] @SmolSammichOwO
• Not much…
• Not considered “malicious”
• By design
• Generates false positives
• Potential detection through parsing ETW events [4]
48
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Code Injection: What and Why?
• Creating a separate thread in a process
• Can be local or remote
• Allows for attributing execution
• “File-less” or memory only
• Harder to detect “malicious” code
• Methods are easily detectable (mostly)
• Can be used to “hot-patch” executables
• Overwrite real-time virtual memory
• Allocate – NtAllocateVirtualMemory
• Segment a section of memory for writing
• Change permissions to allow execution
• Write – NtWriteVirtualMemory
• Copy data into the allocated space
• Execute – NtCreateThreadEx
• Run it!
1. Launch Executable
malware.exe target.exe
Target.exe Memory Map
malware.exe
OpenProcess
target.exe
Target.exe Memory Map
2. Obtain Handle to
Target Process
malware.exe
OpenProcess
target.exe
Target.exe Memory Map
malware.exe
OpenProcess
target.exe
Target.exe Memory Map
Allocated Memory :D
(empty)
malware.exe
OpenProcess
target.exe
Target.exe Memory Map
malware.exe
OpenProcess
target.exe
Target.exe Memory Map
62
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
DEMO: Code Injection
Elevated Execution
63
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Code Injection: Detection
[3] @poofsuits
OwOwning with the Windows API | @secfurry 2020 | secfurry.com 64
Final Thoughts
65
OwOwning with the Windows API | @secfurry 2020 | secfurry.com
Final Thoughts: Parent Process Spoofing
• Excellent way to attribute execution
• Prevention is hard
• Push for using more application containment?
• Detection is slim
• Not many setups include it (or look for it)
• Drawbacks
• Must have filesystem write access
• Executables must be on-disk
Questions?
[4] @PrinceMaiArt 71
OwOwning with the Windows API | @secfurry 2020 | secfurry.com