Direct Kernel Object Manipulation
Direct Kernel Object Manipulation
Kernel Mode
The low level kernel functions that implement
the services needed in user land
Protected memory containing objects such as
those for processes, tokens, ports, etc.
Processes running
Files that are created/deleted/modified
Network connections made
Privilege escalation
Attack Scenario
Attacker gains elevated access to computer system
Attacker installs a Rootkit
Rootkits functions
Hide processes
Hide files
Hide network connections
Install a backdoor for future access to the system
NTDLL
CreateFileW
NtCreateFile
User Land
Kernel
&NtCreateFile
2E
push
ebp
mov
ebp, esp
xor
push
User
Land
Kernel
eax, eax
eax
DKOM Uses
Hide Processes
Add Privileges to Tokens
Add Groups to Tokens
Manipulate the Token to Fool the Windows
Event Viewer
Hide Ports
ETHREAD
KTHREAD
ApcState
EPROCESS
EPROCESS
EPROCESS
KPROCESS
KPROCESS
KPROCESS
LIST_ENTRY {
FLINK
}
BLINK
LIST_ENTRY {
FLINK
}
BLINK
LIST_ENTRY {
FLINK
}
BLINK
ETHREAD
KTHREAD
ApcState
EPROCESS
KPROCESS
EPROCESS
KPROCESS
EPROCESS
KPROCESS
LIST_ENTRY {
FLINK
BLINK
}
LIST_ENTRY {
FLINK
BLINK
}
LIST_ENTRY {
FLINK
BLINK
}
PID
Process 0
PID
PID
PID
1901
State
State
State
State
*next_task
*prev_task
*next_task
*prev_task
*next_task
*prev_task
*next_task
*prev_task
*next_run
*prev_run
*next_run
*prev_run
*next_run
*prev_run
*next_run
*prev_run
*p_pptr
*p_cptr
*p_ysptr
*p_osptr
*p_pptr
*p_cptr
*p_ysptr
*p_osptr
*p_pptr
*p_cptr
*p_ysptr
*p_osptr
...
...
...
...
...
...
...
...
*p_pptr
(null)
*p_cptr
*p_ysptr
*p_osptr
PID
1901
PID
Process 0
PID
State
State
State
*next_task
*prev_task
*next_task
*prev_task
*next_task
*prev_task
*next_run
*prev_run
*next_run
*prev_run
*next_run
*prev_run
*p_pptr
*p_cptr
*p_ysptr
*p_osptr
*p_pptr
*p_cptr
*p_ysptr
*p_osptr
*p_pptr
*p_cptr
*p_ysptr
*p_osptr
...
...
...
...
...
...
Token Manipulation
Tokens
Static Part
TOKEN SOURCE
TokenId
AuthenticationId
ParentTokenId
ExpirationTime
TokenLock
ModifiedId
SessionId
UserAndGroupCount
RestrictedSidCount
PrivilegeCount
VariableLength
Etc
Tokens
Variable Part
Privileges
LUID
Attribute
Manipulating Tokens
Difficult to just grow the token because you
are not sure what is after the variable part in
memory
Although static portion has pointers to the
privileges and groups, just changing these to
point to newly allocated memory does not
work due to crazy math in a
SepDuplicateToken() function
Manipulating Tokens
There are a lot of Privileges in a token that
are disabled
We can discard these since they are disabled
anyway and free up space for new
privileges and groups
The in-line method
0x00000000
0x00000001
0x00000000
0x00000001
LUID
0x00000001
0x00000001
0x00000001
LUID
Disabled Privs
Enabled Privs
Added Privs
SIDs
Restricted SIDs
Disabled Privs
Enabled Privs
Added SIDs
LUID
LUID
LUID
LUID
0x00000000
0x00000001
0x00000000
0x00000001
pSID
LUID
pSID
LUID
0x00000007
0x00000001
0x00000001
0x00000007
SID
SIDs
SID
Restricted SIDs
Detours
Overwrite beginning of target function
(SwapContext) with an unconditional jump to a
Detour function
Detour function eventually calls a Trampoline
function
The Trampoline function contains the overwritten
bytes of the target (SwapContext) function and
calls the target (SwapContext) function
The Target function returns to the Detour function
The Detour function returns to the source caller
(kernel dispatcher)
Detours
1
Source
Function
2
Detour
Function
5
3
Trampoline
Function
Target
Function
Conclusion
We have shown the evolution of rootkit
technology
No longer trojanized programs
No longer use hooking, which is easy to detect
Now act as a part of the Trusted Computing
Base (TCB)
DKOM what will it be used for next?
Questions?
Thank you.
Email: james.butler@hbgary.com
Attend the Black Hat Training
Aspects of Offensive Root-kit
Technology