Top Banner
Abusing Interrupts for Reliable Windows Kernel Exploitation 2015/11/14 AVTOKYO2015 inaz2
28

Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Apr 16, 2017

Download

Technology

inaz2
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Abusing Interrupts for Reliable Windows Kernel Exploitation

2015/11/14

AVTOKYO2015

inaz2

Page 2: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

About me

• inaz2

• Security engineer & Python programmer• Working at NTT Communications

• ブログ「ももいろテクノロジー」• http://inaz2.hatenablog.com/

2

Page 3: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Windows kernel exploitation

• カーネルランドの脆弱性を突くタイプの攻撃• デバイスドライバの脆弱性を含む

• Write-what-where condition/vulnerabilityが広く利用される• 任意のアドレスに任意の値を書き込むことが可能な脆弱性

•自身のプロセスの権限を昇格させるShellcodeを実行させる• その後、管理者コマンドプロンプトを起動する

3

Page 4: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Classic technique: halDispatchTable overwrite

• nt!NtQueryIntervalProfile内部API• nt!KeQueryIntervalProfile経由で [nt!halDispatchTable+4] が呼ばれる

• [nt!halDispatchTable+4] の値をShellcodeのアドレスに書き換える

4

Page 5: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Replace token shellcode

• Systemプロセス (PID=4)のToken Objectをコピー

5

41414141hは対象となるプロセスのPIDに置き換える

Page 6: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

It works but …

• nt!NtQueryIntervalProfileの実装に依存• 将来的に実装が変更される可能性がある(つまり、確実ではない)

• より確実な書き換えのターゲットは存在するか?

6

Page 7: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

It works but …

• nt!NtQueryIntervalProfileの実装に依存• 将来的に実装が変更される可能性がある(つまり、確実ではない)

• より確実な書き換えのターゲットは存在するか?

7

Page 8: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

x86 interrupt handling

•ハードウェア割り込み(キーボード入力など)とソフトウェア割り込み(ゼロ除算など)がある• ソフトウェア割り込みは “int n” 命令で発生させることができる

• Interrupt Descriptor Table (IDT)• Interrupt Software Routines (ISR) と呼ばれる割り込みハンドラ関数のアドレスを保持

• ISRはRing 0で実行される• 要するに、なんでもできる

8

Page 9: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

x86 privilege levels (protection rings)

• 0から3までの4つの権限レベル• 数字が大きいほど権限が低い

• Windowsを含むほとんどのOSは、2つのRingのみを利用する• Ring 0はカーネルモード、Ring 3はユーザモードに対応

9

Page 10: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Interrupt Descriptor Table (1/4)

• Intel Developer’s Manual Volume 3, Chapter 6

10

Page 11: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Interrupt Descriptor Table (2/4)

• Intel Developer’s Manual Volume 3, Chapter 6

11

DPL=3ならRing 3から割り込み可能

Page 12: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Interrupt Descriptor Table (3/4)

• WinDbg (KD) view

12

Page 13: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Interrupt Descriptor Table (4/4)

• Interrupt #0に対応するInterrupt Gateの書き換え

13

414184fc

000884fc 4141ee00

DPL=3

Page 14: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

IDT overwrite technique

14

IDTが置かれているアドレスを取得する

Interrupt #nに対応するInterrupt Gateを書き換える

“int n” 命令でInterrupt #nを発生させる

Shellcodeが実行される

Page 15: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Detailed procedure

16

Page 16: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Find the write-what-where vulnerability

• ここでは、脆弱なデバイスドライバを用意しインストールする• IOCTL経由でwrite-what-where脆弱性への攻撃を可能にする

17

Page 17: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Get the IDT address (1/2)

18

Ring 3でも使える!

Page 18: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Get the IDT address (2/2)

• IDTが置かれているアドレスを返す関数

19

alignmentを無効化

Page 19: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Write the Interrupt Software Routine (ISR)

• fsセグメントレジスタの値を切り換える• 0x33 (TEB) → 0x30 (KPCR)

• ISRの直後にあるShellcodeをcallする

• ret命令の代わりにiretd命令でリターンする

20

Page 20: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Allocate memory & put the codes

• 0x41410000から0x41420000にnop-sledを確保する

• 0x41420000にISR code + shellcodeを置く

21

Page 21: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Overwrite the Interrupt Gate

• Interrupt #32に対応するInterrupt Gateの後半4バイトを0x4141ee00で書き換える• #32-255はuser-defined interruptsと定義されている(予約されていない)

22

Page 22: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Trigger the software interrupt

• “int 32”を実行する• ISRを経由してShellcodeが実行される

•続けて、cmd.exeを起動する

23

Page 23: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Demo

24

Page 24: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

What about 64 bit Windows?

• Interrupt Gateのサイズが16バイトになる

• 0x100000000バイトのnop-sledは厳しいため、Interrupt Gate全体を書き換える必要がある(つまり、2回書き込む)

• なぜか割り込みを発生させたタイミングでVirtualBox VMがハングアップしてしまう(PatchGuard??)

25

Page 25: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Comparison with halDispatchTable overwrite

• Pros• あらゆるバージョンのx86-based Windowsに対して確実

• 書き換えのターゲットとなるアドレスの特定が簡単

• Cons• ISRのコードを用意する必要がある

• nop-sledを確保する必要がある

• 64 bitでの動作を検証できていない

26

Page 26: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Recap

• IDT overwriteはあらゆるバージョンのx86-based Windowsに対して確実• カーネル実装の変更に依存しない

• IDTが置かれているアドレスはRing 3でも取得できる

• There’s more than one way to do it

27

Page 27: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

References

• Windowsでデバイスドライバの脆弱性からの権限昇格をやってみる -ももいろテクノロジー• http://inaz2.hatenablog.com/entry/2015/09/15/121926

• Project Zero: One font vulnerability to rule them all #4: Windows 8.1 64-bit sandbox escape exploitation• http://googleprojectzero.blogspot.jp/2015/08/one-font-vulnerability-to-rule-

them-all_21.html

• Interrupt Service Routines - OSDev Wiki• http://wiki.osdev.org/Interrupt_Service_Routines

• SIMPLE IS BETTER: Kernel Information Leak with Unprivileged Instructions (SIDT, SGDT) on x86 - WHY ?• http://hypervsir.blogspot.jp/2014/10/kernel-information-leak-with.html

28

Page 28: Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)

Thank you!inaz2

29