Share
Embed
Transcript
54 slides
-
UAC vs. AP UAC AP Linked Token Linked Token Remaining
Token Remaining Token Linked Token Remaining Token Shadow Admin Token (with new SID) -
Outline What were covering • Access Token Structure • How
DosDevice works? • What is an impersonation? • Object Manager Demos • DoSDevice EoP • DoSDevice Race Condition EoP -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Create DOS Dir. not initialized Lazy init. Identi cationLevel Token (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi cationLevel Token Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading Bypass -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Identi Create DOS Dir. not initialized Lazy init. (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
AppInfo appinfo.dll denied return Failed Reference svchost.exe RaiLaunchAdminProcess() allow Create
new process with primary token Elevated Process -
Information we have to pass in the handle CREATE_SUSPENDED is
also useful later -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Identi Create DOS Dir. not initialized Lazy init. (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi cationLevel Token Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
Access Token Group SIDs Privileges Default Owner Primary Group DACL
Source Type Impersonation Level Statistics Restricting SIDs TS session ID Session Reference Sandbox Inert Audit Policy Origin Logon Session Cached Credentials Lsass.exe -
Impersonation ) ( n ke Op Server SYSTEM Token o
r P en o T s ces Primary Access Token Impersonation Token Impersonation Access Token Ope nThr eadT oken ( ) RPC(MSRPC) User Delegate Client’s local & network credentials can be passed Impersonate Can access local resources as the client Identify Default. Obtain ID & do ACL checks Anonymous Does not contain any information. Local interprocess communication. User Token -
Impersonation ) ( n ke o r P en o
T s ces Primary Access Token Op Server SYSTEM Token Impersonation Token Impersonation Access Token Ope nThr eadT oken ( ) RPC(MSRPC) User Delegate Client’s local & network credentials can be passed Impersonate Can access local resources as the client Identify Default. Obtain ID & do ACL checks Anonymous Does not contain any information. Local interprocess communication. User Token -
Impersonation ) ( n ke o r P en o
T s ces Primary Access Token Op Server SYSTEM Token Impersonation Token Impersonation Access Token Ope nThr eadT oken ( ) RPC(MSRPC) User Delegate Client’s local & network credentials can be passed Impersonate Can access local resources as the client Identify Default. Obtain ID & do ACL checks Anonymous Does not contain any information. Local interprocess communication. User Token -
Impersonation ) ( n ke o r P en o
T s ces Primary Access Token Op Server SYSTEM Token Impersonation Token Impersonation Access Token Ope nThr eadT oken ( ) RPC(MSRPC) User Delegate Client’s local & network credentials can be passed Impersonate Can access local resources as the client Identify Default. Obtain ID & do ACL checks Anonymous Does not contain any information. Local interprocess communication. User Token -
securitybaseapi.h AccessCheck() AccessCheckByType() Server Check Private Object AccessCheckByTypeResultList() AdjustTokenPrivileges() Impersonation
Access Token securitybaseapi.h winht.h Update pointer to TOKEN_PRIVILEGES TOKEN_PRIVILEGES securitybaseapi.h PrivilegeCheck() Check the pointer to PRIVILEGE_SET winbase.h ObjectOpenAuditAlarmA() PrivilegedServiceAuditAlarmA() Generate audit messages -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Identi Create DOS Dir. not initialized Lazy init. (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
DoSDevices • Device name that Windows Object Manger provide for
reference. • e.g. “C:”, “COM1”, “Serial0” • Apps can take it to access NT Object Devices -
Object Manager Structure HarddiskVolume3 Device Null Serial0 C: -> /Device/HarddiskVolume3
/ \GLOBAL?? NUL -> /Device/Null COM1 -> /Device/Serial0 00000000-00123456 (LOGON 1) Sessions 0 DOSDevices 00000000-007890AB (LOGON 2) DOSDevices \?? -
Object Manager Structure HarddiskVolume3 / Device Null (Objects Dir) Serial0
(Device Objects) C: -> /Device/HarddiskVolume3 (Symbolic Links) NUL -> /Device/Null \GLOBAL?? (Objects Dir) COM1 -> /Device/Serial0 00000000-00123456 (LOGON 1) Sessions 0 DOSDevices 00000000-007890AB (LOGON 2) DOSDevices \?? (Capability Alias) -
\Device • IoCreateObject(…); • e.g. A driver create the \Device\MyDevice,
it will be mapped into the DEVICE_OBJECT in the kernel memory -
\Device • When IO Manager is handling the open request
of this device -> it handle the IO using the driver/device stack • We can’t expect the Win32 apps to know what the NT paths are when we pass it like \Device\whateverdevice into CreateFileW() • Therefore, we need another one for help. -
\DoSDevices Win32 Path C:\Windows\text.txt NT Path (DOS Prefix) \??\C:\Windows\test.txt DOSDevices
Mapping C: -> \Device\HarddiskVolume3 NT Device Path \Device\HarddiskVolume3\Windows\test.txt -
Local Shadowing Access \??\C: Local DoSDevices Local Mapping Find current
DoSDevices context Not Found \GLOBAL??\C: Global Mapping -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Create DOS Dir. not initialized Lazy init. Identi cationLevel Token (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
SID • Every user has one for identi cation •
It will be transfered into Binary through ConvertStringSidToSid() S-R-X Y1-Y2-…-Yn-1 Domain which SID Pre x fi fi the Local SAM account stays in Yn RID -
Local Shadowing Access \??\C: Local DoSDevices Local Mapping Find current
DoSDevices context Not Found \GLOBAL??\C: Global Mapping -
Local Shadowing Access \??\C: Local DoSDevices Local Mapping Find current
DoSDevices context Not Found \GLOBAL??\C: Where is my \GLOBAL?? Global Mapping -
High Delegate Client’s local & network credentials can be passed
Impersonate Can access local resources as the client Identify Default. Obtain ID & do ACL checks Anonymous Does not contain any information. Local interprocess communication. Low Not enough to control admin -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Create DOS Dir. not initialized Lazy init. Identi cationLevel Token (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Identi Create DOS Dir. not initialized Lazy init. (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe Bypass (elevated) -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Create DOS Dir. not initialized Lazy init. Identi cationLevel Token (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi cationLevel Token Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe Bypass (elevated) -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Create DOS Dir. not initialized Lazy init. Identi cationLevel Token (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi cationLevel Token Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe Bypass (elevated) -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Identi Create DOS Dir. not initialized Lazy init. (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
DoS initialized Access Denied Calling Shadow Admin User RPC Impersonation
Thread AppInfo elevation cmd.exe DuplicateTokenEx() Primary Token t a h Identi Symbolic Link DoSDevices T C: -> \GLOBAL??\C:\fakec Create DOS Dir. not initialized Lazy init. o g t . d o o n is fi (Not Trusted) Primary Token ZwCreateDirectoryObject() Catch STATUS_BAD_IMPERSONATION_LEVEL Primary Token take place ownership Shadow Admin gets into the fakec dir. fi Identi DLL Sideloading cmd.exe (elevated) -
DoS Device EoP initialized Access Denied Calling Shadow Admin User
RPC Impersonation Thread AppInfo elevation cmd.exe Identi Create DOS Dir. not initialized Lazy init. (Not Trusted) Primary Token ZwCreateDirectoryObject() DuplicateTokenEx() Primary Token Identi Catch STATUS_BAD_IMPERSONATION_LEVEL Symbolic Link DoSDevices C: -> \GLOBAL??\C:\fakec Primary Token take place ownership fi fi Shadow Admin gets into the fakec dir. DLL Sideloading cmd.exe (elevated) -
AppInfo appinfo.dll denied return Failed Reference svchost.exe RaiLaunchAdminProcess() allow Create
new process with primary token Elevated Process -
AppInfo appinfo.dll denied return Failed Reference svchost.exe RaiLaunchAdminProcess() allow Create
new process with primary token Elevated Process -
AppInfo appinfo.dll denied return Failed Reference svchost.exe RaiLaunchProcessOnce() allow Create
new process with primary token Elevated Process -
Race Condition Attacker Thread OpenProcessToken() DuplicateTokenEx() trigger lazy init for
\?? Success Scheduled Loader opens le DoS dir. Created Failed Admin Thread fi winning line