abusing interrupts for reliable windows kernel exploitation (ja)
TRANSCRIPT
About me
• inaz2
• Security engineer & Python programmer• Working at NTT Communications
• ブログ「ももいろテクノロジー」• http://inaz2.hatenablog.com/
2
Windows kernel exploitation
• カーネルランドの脆弱性を突くタイプの攻撃• デバイスドライバの脆弱性を含む
• Write-what-where condition/vulnerabilityが広く利用される• 任意のアドレスに任意の値を書き込むことが可能な脆弱性
•自身のプロセスの権限を昇格させるShellcodeを実行させる• その後、管理者コマンドプロンプトを起動する
3
Classic technique: halDispatchTable overwrite
• nt!NtQueryIntervalProfile内部API• nt!KeQueryIntervalProfile経由で [nt!halDispatchTable+4] が呼ばれる
• [nt!halDispatchTable+4] の値をShellcodeのアドレスに書き換える
4
It works but …
• nt!NtQueryIntervalProfileの実装に依存• 将来的に実装が変更される可能性がある(つまり、確実ではない)
• より確実な書き換えのターゲットは存在するか?
6
It works but …
• nt!NtQueryIntervalProfileの実装に依存• 将来的に実装が変更される可能性がある(つまり、確実ではない)
• より確実な書き換えのターゲットは存在するか?
7
x86 interrupt handling
•ハードウェア割り込み(キーボード入力など)とソフトウェア割り込み(ゼロ除算など)がある• ソフトウェア割り込みは “int n” 命令で発生させることができる
• Interrupt Descriptor Table (IDT)• Interrupt Software Routines (ISR) と呼ばれる割り込みハンドラ関数のアドレスを保持
• ISRはRing 0で実行される• 要するに、なんでもできる
8
x86 privilege levels (protection rings)
• 0から3までの4つの権限レベル• 数字が大きいほど権限が低い
• Windowsを含むほとんどのOSは、2つのRingのみを利用する• Ring 0はカーネルモード、Ring 3はユーザモードに対応
9
Interrupt Descriptor Table (2/4)
• Intel Developer’s Manual Volume 3, Chapter 6
11
DPL=3ならRing 3から割り込み可能
Interrupt Descriptor Table (4/4)
• Interrupt #0に対応するInterrupt Gateの書き換え
13
414184fc
000884fc 4141ee00
DPL=3
IDT overwrite technique
14
IDTが置かれているアドレスを取得する
Interrupt #nに対応するInterrupt Gateを書き換える
“int n” 命令でInterrupt #nを発生させる
Shellcodeが実行される
Find the write-what-where vulnerability
• ここでは、脆弱なデバイスドライバを用意しインストールする• IOCTL経由でwrite-what-where脆弱性への攻撃を可能にする
17
Write the Interrupt Software Routine (ISR)
• fsセグメントレジスタの値を切り換える• 0x33 (TEB) → 0x30 (KPCR)
• ISRの直後にあるShellcodeをcallする
• ret命令の代わりにiretd命令でリターンする
20
Allocate memory & put the codes
• 0x41410000から0x41420000にnop-sledを確保する
• 0x41420000にISR code + shellcodeを置く
21
Overwrite the Interrupt Gate
• Interrupt #32に対応するInterrupt Gateの後半4バイトを0x4141ee00で書き換える• #32-255はuser-defined interruptsと定義されている(予約されていない)
22
What about 64 bit Windows?
• Interrupt Gateのサイズが16バイトになる
• 0x100000000バイトのnop-sledは厳しいため、Interrupt Gate全体を書き換える必要がある(つまり、2回書き込む)
• なぜか割り込みを発生させたタイミングでVirtualBox VMがハングアップしてしまう(PatchGuard??)
25
Comparison with halDispatchTable overwrite
• Pros• あらゆるバージョンのx86-based Windowsに対して確実
• 書き換えのターゲットとなるアドレスの特定が簡単
• Cons• ISRのコードを用意する必要がある
• nop-sledを確保する必要がある
• 64 bitでの動作を検証できていない
26
Recap
• IDT overwriteはあらゆるバージョンのx86-based Windowsに対して確実• カーネル実装の変更に依存しない
• IDTが置かれているアドレスはRing 3でも取得できる
• There’s more than one way to do it
27
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