[windows kernel] Process Token Abusing

2024. 3. 28. 12:56·윈도우

개요

Process Token

로그인한 이후 본인 인증을 하기 위해 쿠키에 세션 키를 저장하는것처럼 프로세스도 식별 및 권한 부여를 위해 토큰을 가지고있다.

이 말은, 다른 프로세스의 토큰을 가지고있다면 그 프로세스의 권한을 그대로 가져올 수 있다는 뜻이다.

실습

Powershell이 System 프로세스 권한에서 실행되도록 조작하기

  1. powershell 프로세스 정보 찾기
PROCESS ffff800006782580
    SessionId: 1  Cid: 036c    Peb: e15b8c3000  ParentCid: 0f2c
    DirBase: 28400000  ObjectTable: ffffc00f2b3418c0  HandleCount: 686.
    Image: powershell.exe
  1. 프로세스 오브젝트에서 토큰이 들어있는 멤버 찾기

  1. 토큰 오브젝트 살펴보기
0: kd> dq ffff800006782580+0x358 L1
ffff8000`067828d8  ffffc00f`2c9e6068
0: kd> !token ffffc00f`2c9e6068
The address 0xffffc00f2c9e6068 does not point to a token object.

0x358에 들어있는 주소 그대로는 유효한 주소가 아니다. 마지막 4비트를 날려줘야(마지막 자리를 0으로 만듦) 유효한 주소가 나온다.

마지막 1바이트에는 Refcnt라는 멤버가 존재한다. → 토큰을 참조한 횟수

0: kd> !token ffffc00f`2c9e6060
_TOKEN 0xffffc00f2c9e6060
TS Session ID: 0x1
User: S-1-5-21-2688943681-613566461-1452993856-1001
User Groups: 
 00 S-1-5-21-2688943681-613566461-1452993856-513
    Attributes - Mandatory Default Enabled 
 01 S-1-1-0
    Attributes - Mandatory Default Enabled 
 02 S-1-5-114
    Attributes - DenyOnly
 ~~~

유저의 세션 아이디랑 그룹같은걸 볼 수 있다.

  1. 시스템 토큰 가져오기
0: kd> !process 4 0
Searching for Process with Cid == 4
PROCESS ffff800003289040
    SessionId: none  Cid: 0004    Peb: 00000000  ParentCid: 0000
    DirBase: 001ab000  ObjectTable: ffffc00f22e15040  HandleCount: 2221.
    Image: System
0: kd> dt nt!_EX_FAST_REF ffff800003289040+0x358
   +0x000 Object           : 0xffffc00f`22e18049 Void
   +0x000 RefCnt           : 0y1001
   +0x000 Value            : 0xffffc00f`22e18049

따라서 시스템 토큰 주소는 0xffffc00f`22e18040

  1. 토큰 바꿔치기
eq ffff800006782580+0x358 0xffffc00f`22e18040

eq로 값 대입 가능

0: kd> dt nt!_EX_FAST_REF ffff800006782580+0x358
   +0x000 Object           : 0xffffc00f`22e18040 Void
   +0x000 RefCnt           : 0y0000
   +0x000 Value            : 0xffffc00f`22e18040
  1. 권한 확인

사용자명이 system으로 잘 뜬다.

추가

토큰오브젝트에는 권한을 나타내는 _SEP_TOKEN_PRIVILEGES 구조체가 존재한다.

안에는 Enabled와 Present 멤버가 있는데

Present에는 권한 개수가 나타나있고 Enabled에는 각 권한이 enabled 되어있는지가 있다.

참고자료

https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-token_privileges

https://www.ired.team/miscellaneous-reversing-forensics/windows-kernel-internals/how-kernel-exploits-abuse-tokens-for-privilege-escalation

'윈도우' 카테고리의 다른 글

what the fuzz (wtf)로 퍼징하기  (1) 2024.03.29
[HEVD] Windows 10 x64 Stack Overflow  (0) 2024.03.28
[windows kernel] SSDT (System Service Descriptor Table)  (0) 2024.03.28
[windows driver] PnP 드라이버란  (0) 2024.03.28
[windows kernel] 커널오브젝트  (0) 2024.03.28
'윈도우' 카테고리의 다른 글
  • what the fuzz (wtf)로 퍼징하기
  • [HEVD] Windows 10 x64 Stack Overflow
  • [windows kernel] SSDT (System Service Descriptor Table)
  • [windows driver] PnP 드라이버란
oriotie
oriotie
  • oriotie
    낭만파 보안인의 기록 저장소
    oriotie
  • 전체
    오늘
    어제
    • 분류 전체보기 (74)
      • 워게임&CTF (25)
      • 윈도우 (16)
      • N day (16)
      • web3 (10)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 글쓰기
  • 링크

  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
oriotie
[windows kernel] Process Token Abusing
상단으로

티스토리툴바