SlideShare a Scribd company logo
1 of 38
Download to read offline
ROP ILLMATIC: EXPLORING UNIVERSAL ROP ON GLIBC X86-64@inaz2AVTOKYO20142014/11/15
ABOUT ME•@inaz2•Security Engineer & Python Programmer•Girls Idol Freak•ブログ「ももいろテクノロジー」 •http://inaz2.hatenablog.com/ 
2
“ILLMATIC” ? •http://en.wikipedia.org/wiki/Illmatic•アメリカのラッパーNasによる造語 •"supreme ill. It's as ill as ill gets. That s*** is a science of everything ill." 
3
BACKGROUND•バッファオーバーフロー脆弱性などからの任意コード実行 •ドキュメント「各種セキュリティ機構が実装されている」 •どこまで突破できるのか? •論文「固定アドレスに十分な実行可能メモリが存在するならば…」 噂話「x86-64では固定アドレスに実行可能メモリが足りないので難し い」 •実行可能メモリが少ないときでも使える普遍的(universal)な方法はな いのか? 
4
ENVIRONMENT•x86-64環境におけるUbuntu Linux最新版 
$ uname -a 
Linux vm-ubuntu64 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 
$ lsb_release -a 
Description: Ubuntu 14.04.1 LTS 
$ gcc --version 
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 
$ clang --version 
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) 
5
VULNERABLE CODE•スタックバッファオーバーフロー脆弱性を含む最小限のCコード 
6 
#include <unistd.h> 
int main() 
{ 
char buf[100]; 
int size; 
read(0, &size, 8); 
read(0, buf, size); 
write(1, buf, size); 
return 0; 
} 
バッファサイズ以上の 
書き込みが可能
HOW THE CODE IS EXECUTED•RIPレジスタにその時点で実行されようとしている命令のアドレスが入っ ている •x86-64における関数呼び出し •call命令は次の命令のアドレスをスタックにpushしてripを変える •ret命令はスタックからアドレスをpopしてripを戻す •ELFにおけるライブラリ関数呼び出し •オブジェクトはGOT(Global Offset Table) およびPLT(Procedure Linkage Table) セクションを持つ •GOTはライブラリ関数のアドレステーブル •PLTはGOTに置かれた各アドレスにジャンプするためのエントリポイント •PLTを経由して間接ジャンプを行う 
7
SMASHING THE STACK [PHRACK49] •Published in 1996, written by Aleph One•関数からのリターンアドレスを書き換え、シェルコードに向ける 
8 
AAAA 
shellcode 
&buf 
buf[100] 
saved 
ebp 
return 
address 
higher 
address
SECURITY MITIGATIONS•Enabled by default•NX/DEP•ASLR•Stack canary•Additional options•RELRO + BIND_NOW (FullRELRO) •FORTIFY_SOURCE•PIE 
9
NX/DEP (DATA EXECUTION PREVENTION) •書き換え可能メモリ(データ)の実行を禁止する •スタック・ヒープ領域に置いたシェルコードを実行しようとすると落ちる 
$ cat /proc/$$/maps 
00400000-004ef000 r-xp 00000000 fc:00 265344 /bin/bash 
006ef000-006f0000 r--p 000ef000 fc:00 265344 /bin/bash 
006f0000-006f9000 rw-p000f0000 fc:00 265344 /bin/bash 
006f9000-006ff000 rw-p 00000000 00:00 0 
01cb0000-01ed1000 rw-p00000000 00:00 0 [heap] 
... 
7fffe374e000-7fffe376f000 rw-p00000000 00:00 0 [stack] 
10
ROP (RETURN-ORIENTED PROGRAMMING) [BH USA 2008] •リターンアドレスを書き換え、実行可能コードに向ける •ret命令で終わるコード断片(ROP gadget)へのリターンを繰り返す •jmp/call命令を使うものも含めてcode-reuse attackとも呼ばれる 
pop rdi; 
ret; 
system(“/bin/sh”) runs 
11 
&gadget 
/bin/sh¥x00 
&buf 
buf[100] 
return 
address 
higher 
address 
&system
X86-64 CALLING CONVENTIONS•x86-64では、関数の引数はレジスタにセットして渡される •rdi, rsi, rdx, rcx, r8, r9の順 •関数にリターンする前に各レジスタへの値のセットが必要 •“pop rdi; ret” / “pop rsi; ret” / “pop rdx; ret” / … •これらのgadgetが固定アドレスに揃っていないことも多い 
12
LIBC_CSU_INIT GADGETS•ほぼすべての実行ファイルに埋め込まれている__libc_csu_init関数 にあるコード断片を使う •3引数までの任意の関数呼び出しが可能 •第4引数(rcx)はmemset/memcpyを呼ぶことで操作可能 
(1) loc_400626 スタックからレジスタに値をセット 
(2) loc_400610 引数にセットして[r12+rbx*8]をcall 
13
ASLR (ADDRESS SPACE LAYOUT RANDOMIZATION) •スタック・ヒープ領域や共有ライブラリのアドレスをランダム化 •実行ファイルが置かれるアドレスは固定のまま 
14 
heap 
a.out 
libc.so.6 
1stexecution: 
higher 
address 
stack 
heap 
a.out 
libc.so.6 
2ndexecution: 
stack
ROP STAGER USING IO PRIMITIVES•PLTにある入出力関数を使い、固定アドレスにROPシーケンスを送り 込む •read/write, send/recv, fgets/fputs…, だいたい何かしらある •スタックポインタを送り込んだROPシーケンスに向ける(stack pivot) •rbpをセットしてleave命令を実行することでrspを差し替える 
read@plt # call read(0, 0x601048, 0x400) 
# 0x601048 = writable address around bss section 
pop rbp; ret; # set rbp=0x601048 
leave; ret; # equiv. to “mov rsp, rbp; pop rbp” 
15
DETERMINING LIBRARY FUNCTION ADDRESS•ランダム化されたアドレスにあるsystem関数を呼ぶには? •GOTにある__libc_start_main関数のアドレスを読み出す •__libc_start_main関数からsystem関数までのオフセットを足す •ターゲットホストで使われているlibcバイナリを特定する必要がある •__libc_start_main関数の下位ビットから推測する方法も考えられる 
$ nm -D -n /lib/x86_64-linux-gnu/libc-2.19.so 
0000000000021dd0 T __libc_start_main 
0000000000046530 W system 
offset = 0x046530 −0x021dd0 = 0x24760 
16
RETURN-TO-DL-RESOLVE [PHRACK58] •Published in 2001, written by Nergal•偽のシンボル情報一式を作って、ダイナミックリンカ (_dl_runtime_resolve関数)に読ませる •libcバイナリの特定なしで、任意のライブラリ関数の呼び出しが可能 
17 
buf+= struct.pack(‘<Q’, addr_plt) # PLT0 jumps to resolver 
buf+= struct.pack(‘<Q’, offset2rela) 
buf+= ‘NEXT_RIP’ 
buf+= ‘A’ * alignment1 
buf+= struct.pack(‘<QQQ’, writable_addr, offset2sym, 0) # Elf64_Rela 
buf+= 'A' * alignment2 
buf+= struct.pack(‘<IIQQ’, offset2symstr, 0x12, 0, 0) # Elf64_Sym 
buf+= ‘system¥x00’ # symstr
SKIPPING SYMBOL VERSION CHECK•x86-64ではふつうにReturn-to-dl-resolveを行うと落ちる •偽シンボルのバージョンのインデックスを取得する箇所でSEGV (*1) •GOTセクションにあるlink_map構造体のアドレスを読み出し、 [link_map+0x1c8]の値を0に書き換える •バージョン情報を取得する処理をスキップ 
if (l->l_info[VERSYMIDX (DT_VERSYM)]!= NULL) 
{ 
const ElfW(Half) *vernum = 
(const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]); 
ElfW(Half) ndx= vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff; // (*1) 
version = &l->l_versions[ndx]; 
if (version->hash == 0) 
version = NULL; 
} 
18
RELRO + BIND_NOW (FULLRELRO) •Relocation read-only with lazy binding disabled•実行直後にすべてのGOTアドレスを解決し、Read-onlyにする •実行時、メモリ上に_dl_runtime_resolve関数のアドレスがセットされ ない •直接呼び出すことができなくなる 
(gdb) x/4gx 0x601000 
0x601000: 0x0000000000000000 0x0000000000000000 
0x601010: 0x00000000000000000x0000000000000000 
(gdb) x/4gx 0x601000 
0x601000: 0x0000000000600e28 0x00007ffff7ffe1c8 
0x601010: 0x00007ffff7df04e00x0000000000400456 
19 
FullRELRO(0x601000 = address of GOT section)
DT_DEBUG TRAVERSAL•DynamicセクションにあるDT_DEBUGの値を見る •実行時にデバッグ用構造体r_debugのアドレスが入る •r_debugから、ロードされている各ライブラリのlink_map構造体が辿 れる •link_map構造体を通して、ライブラリに関する各種アドレスが得られる •ロードされたライブラリのGOTセクションから_dl_runtime_resolve関 数のアドレスを特定する 
20
LET’S TRY! •x86-64かつASLR+NX/DEP+FullRELROが有効な条件下におい て、シェルを起動する 1.関数呼び出しにlibc_csu_initgadgetsを用いる 2.IO primitivesを使って固定アドレスにROPシーケンスを送り込み、 stack pivotする 3.DT_DEBUG traversalを行い、_dl_runtime_resolve関数のアドレス を特定する 4.Return-to-dl-resolveでsystem関数を呼び出す 
21
DEMO 1•http://inaz2.hatenablog.com/entry/2014/10/12/191047•gccを使い、ASLR+NX/DEP+FullRELROを有効にした実行ファイルを 作る •ROP stager + Return-to-dl-resolveでシェルを起動する 
22 
Enable ASLR: 
$ sudosysctl-w kernel.randomize_va_space=2 
Compile with NX/DEP+FullRELROenabled (w/o stack canary): 
$ gcc-fno-stack-protector -Wl,-z,relro,-z,nowbof.c 
Execute the program and exploit it: 
$ python exploit.py 100
IT WORKS, BUT IS TOO COMPLICATED… DT_DEBUG Traversal requires read & write 5 times 
23
DYNAMIC ROP•Or “Just-in-time Code Reuse” [BH USA 2013] •libcメモリを丸ごと読み出して使う 1.GOTにある__libc_start_main関数のアドレスを読み出す 2.読み出したアドレスから0x160000バイト程度を読み出す 3.読み出したメモリ内にあるROP gadgetを使い、システムコールを実行 するROPシーケンスを構築する 
pop rax; ret; # set rax=59 (_NR_execve) 
pop rdi; ret; # set rdi="/bin/sh" 
pop rsi; ret; # set rsi={"/bin/sh", NULL} 
pop rdx; ret; # set rdx=NULL 
syscall; # call execve("/bin/sh", {"/bin/sh", NULL}, NULL) 
24
LEAVE-LESS EXECUTABLES•clangでコンパイルすると、関数エピローグにleave命令が使われない •“add rsp, XXh” の形で厳密にrspが調整される •leave命令がない場合のstack pivotはめんどい •固定アドレスに送り込んだROPシーケンスへのpivotが難しくなる 
gcc 
clang 
25
RETURN-TO-VULN•同一の脆弱な関数に繰り返しリターンする •stack pivotなしで次のROPシーケンスを実行できる 
26 
Vulnerable function 
Read the address of __libc_start_main 
Read the libcmemory 
Execute system call 
1. 
2. 
3.
ROPUTILS•https://github.com/inaz2/roputils•ROPに関する各種タスクを行うツールキット •readelfコマンドによるELFパース ⇒セクション、シンボル、よく使うgadgetのアドレスを取得 •パラメータからのROPシーケンス構築 •pipe (local) & socket (remote) 両対応のNon-blocking IO•Linux i386 / x86-64シェルコード生成 •適用されているセキュリティ機構の確認 •Metasploitパターンの生成およびオフセット計算 
27
ELFパース 
各種アドレスの取得 
ROPシーケンスの構築 
すべてのクラスをimport 
Non-blocking IO 
ターゲットがremoteなら 次のようにする: Proc(host=x, port=y) 
28
DEMO 2•https://github.com/inaz2/roputils/blob/master/examples/libc- dynamic-no-leave-x64.py•clangを使い、ASLR+NX/DEP+FullRELROを有効にした実行ファイ ルを作る •socatを使ってTCPサービスにする •Dynamic ROP + Return-to-vulnでリモートシェルを起動 
Enable ASLR and compile with NX/DEP+FullRELROenabled (w/o stack canary): 
$ sudosysctl-w kernel.randomize_va_space=2 
$ clang -fno-stack-protector -Wl,-z,relro,-z,nowbof.c 
Execute the program as a TCP service: 
$ socattcp-listen:5000,fork,reuseaddr exec:./a.out& 
Exploit it: 
$ python libc-dynamic-no-leave-x64.py ./a.out120 29
HOW ABOUT THE REST? Stack canary, FORTIFY_SOURCE and PIE 
30
STACK CANARY•リターンアドレスの前にランダムな値を差し込むことでスタックバッファ オーバーフローを検知 •値が変わっていたら強制終了 •ターゲットが単純なfork serverなら、1バイトずつのbruteforceで突 破可能(最大試行数256 * 8 = 2048) •Heap overflow / Use-after-free脆弱性などによるポインタ書き換え に対しては効果なし 
31 
値が変わってないかチェック
FORTIFY_SOURCE•危険な標準ライブラリ関数を安全なものに置き換える •gets → gets_chk, strcpy→ strcpy_chk, read → read_chk, … •バッファサイズのチェックを追加 •ほとんどのスタックバッファオーバーフロー脆弱性は塞がれる •ただし、*_chkを使ったROP stager自体は可能 •Heap overflow / Use-after-free脆弱性などによるポインタ書き換えを 探す 
32 
read(0, buf, size) → __read_chk(0, buf, size, 100)
PIE (POSITION-INDEPENDENT EXECUTABLES) •実行ファイルが置かれるアドレスもランダム化 •もちろんASLRが有効な場合に限る •実行ファイルやlibc中にある何かしらのアドレスが得られる場合には 効果なし(information leak) •Buffer over-readなど他の脆弱性を使う •下位バイトのみを書き換えることで、リターンアドレスをずらすことはで きる(partial overwrite) •しかし、genericな攻撃は難しいと思われる 
33
FURTHER MITIGATIONS•Shadow stack•StackShield(2000), TRUSS (2008), ROPdefender(2011) •リターンアドレスを別の領域にコピーしておき検証する •Related: “SCADS: Separated Control-and Data-Stacks” (2014) •Coarse-grained Control-Flow Integrity (CFI) •ROPGuard(2012), kBouncer(2013), ROPecker(2014) •Indirect Branches and Behavior-Based Heuristics policies•取り得るジャンプ先を集めておいて検証する •短い命令列が連続する回数を制限する(閾値ベース) •Call-ret-pair gadget、Long-NOP gadgetが存在すればbypass可能 
34
RECAP•NX/DEP bypass: ROP•ASLR bypass: ROP stager•前提条件: PLT上のIO primitives、十分なROP用バッファ •x86-64での関数呼び出し: libc_csu_init gadgets•ライブラリ関数呼び出し: Return-to-dl-resolve•FullRELRObypass: DT_DEBUG traversal•システムコール実行: Dynamic ROP•leave-less executable対策: Return-to-vuln•ROP is illmatic 
35
REFERENCES (1/2) •"Exploit" -記事一覧-ももいろテクノロジー •http://inaz2.hatenablog.com/archive/category/Exploit•Smashing The Stack For Fun And Profit (Phrack49) •http://phrack.org/issues/49/14.html•The advanced return-into-lib(c) exploits: PaXcase study (Phrack58) •http://phrack.org/issues/58/4.html•Return-Oriented Programming: Exploits Without Code Injection (Black Hat USA 2008) •http://cseweb.ucsd.edu/~hovav/talks/blackhat08.html•Return to Dynamic Linker (Codegate2014 Junior) •http://blog.jinmo123.pe.kr/entry/Codegate-2014-Junior-Presentation 
36
REFERENCES (2/2) •Ghost in the Shellcode 2014 -fuzzy -Code Arcana•http://codearcana.com/posts/2014/01/19/ghost-in-the-shellcode-2014-fuzzy.html•Just-In-Time Code Reuse: The more things change, the more they stay the same (Black Hat USA 2013) •https://media.blackhat.com/us-13/US-13-Snow-Just-In-Time-Code-Reuse- Slides.pdf•SCADS: Separated Control-and Data-Stacks (SECURECOMM 2014) •https://www1.cs.fau.de/filepool/scads/scads-securecomm2014.pdf•Stitching the Gadgets: On the Ineffectiveness of Coarse-Grained Control- Flow Integrity Protection (USENIX Security 2014) •https://www.usenix.org/conference/usenixsecurity14/technical- sessions/presentation/davi•And many others 
37
THANK YOU! @inaz2 
38

More Related Content

What's hot

X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterMasato Kinugawa
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniqueAngel Boy
 
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsHunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsMikhail Egorov
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopPaul Ionescu
 
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesOWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesFrans Rosén
 
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webappsMikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webappshacktivity
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesMikhail Egorov
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacksKapil Nagrale
 
Binary exploitation - AIS3
Binary exploitation - AIS3Binary exploitation - AIS3
Binary exploitation - AIS3Angel Boy
 
Tcache Exploitation
Tcache ExploitationTcache Exploitation
Tcache ExploitationAngel Boy
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMFrans Rosén
 
Windows 10 Nt Heap Exploitation (Chinese version)
Windows 10 Nt Heap Exploitation (Chinese version)Windows 10 Nt Heap Exploitation (Chinese version)
Windows 10 Nt Heap Exploitation (Chinese version)Angel Boy
 
COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺hydai
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程Weber Tsai
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL ApplicationsNeelu Tripathy
 
API Testing with Frisby and Mocha
API Testing with Frisby and MochaAPI Testing with Frisby and Mocha
API Testing with Frisby and MochaLyudmila Anisimova
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsMikhail Egorov
 

What's hot (20)

X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit Technique
 
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsHunting for security bugs in AEM webapps
Hunting for security bugs in AEM webapps
 
Secure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa WorkshopSecure Coding 101 - OWASP University of Ottawa Workshop
Secure Coding 101 - OWASP University of Ottawa Workshop
 
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesOWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
 
jQuery
jQueryjQuery
jQuery
 
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webappsMikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
Binary exploitation - AIS3
Binary exploitation - AIS3Binary exploitation - AIS3
Binary exploitation - AIS3
 
Tcache Exploitation
Tcache ExploitationTcache Exploitation
Tcache Exploitation
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 
Sql Injection Myths and Fallacies
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and Fallacies
 
Windows 10 Nt Heap Exploitation (Chinese version)
Windows 10 Nt Heap Exploitation (Chinese version)Windows 10 Nt Heap Exploitation (Chinese version)
Windows 10 Nt Heap Exploitation (Chinese version)
 
COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL Applications
 
API Testing with Frisby and Mocha
API Testing with Frisby and MochaAPI Testing with Frisby and Mocha
API Testing with Frisby and Mocha
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
 
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging modulePython Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
 

Similar to ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)

Xbyakの紹介とその周辺
Xbyakの紹介とその周辺Xbyakの紹介とその周辺
Xbyakの紹介とその周辺MITSUNARI Shigeo
 
2011.09.18 v7から始めるunix まとめ
2011.09.18 v7から始めるunix まとめ2011.09.18 v7から始めるunix まとめ
2011.09.18 v7から始めるunix まとめMakiko Konoshima
 
スタート低レイヤー #0
スタート低レイヤー #0スタート低レイヤー #0
スタート低レイヤー #0Kiwamu Okabe
 
Php in ruby
Php in rubyPhp in ruby
Php in rubydo_aki
 
高速な暗号実装のためにしてきたこと
高速な暗号実装のためにしてきたこと高速な暗号実装のためにしてきたこと
高速な暗号実装のためにしてきたことMITSUNARI Shigeo
 
Intro to SVE 富岳のA64FXを触ってみた
Intro to SVE 富岳のA64FXを触ってみたIntro to SVE 富岳のA64FXを触ってみた
Intro to SVE 富岳のA64FXを触ってみたMITSUNARI Shigeo
 
Programming camp 2008, Codereading
Programming camp 2008, CodereadingProgramming camp 2008, Codereading
Programming camp 2008, CodereadingHiro Yoshioka
 
ラズパイでデバイスドライバを作ってみた。
ラズパイでデバイスドライバを作ってみた。ラズパイでデバイスドライバを作ってみた。
ラズパイでデバイスドライバを作ってみた。Kazuki Onishi
 
第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西Masahide Yamamoto
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflowionis111
 
ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!Yohei Fushii
 
ROS Tutorial 02 - CIT
ROS Tutorial 02 - CITROS Tutorial 02 - CIT
ROS Tutorial 02 - CITDaiki Maekawa
 
BLS署名の実装とその応用
BLS署名の実装とその応用BLS署名の実装とその応用
BLS署名の実装とその応用MITSUNARI Shigeo
 
Lxc cf201207-presen
Lxc cf201207-presenLxc cf201207-presen
Lxc cf201207-presenKouhei Maeda
 
A story of porting OpenBSD/luna88k
A story of porting OpenBSD/luna88kA story of porting OpenBSD/luna88k
A story of porting OpenBSD/luna88kKenji Aoyama
 
Sagittariusの紹介
Sagittariusの紹介Sagittariusの紹介
Sagittariusの紹介Kato Takashi
 
x86とコンテキストスイッチ
x86とコンテキストスイッチx86とコンテキストスイッチ
x86とコンテキストスイッチMasami Ichikawa
 
TripleOの光と闇
TripleOの光と闇TripleOの光と闇
TripleOの光と闇Manabu Ori
 

Similar to ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja) (20)

Xbyakの紹介とその周辺
Xbyakの紹介とその周辺Xbyakの紹介とその周辺
Xbyakの紹介とその周辺
 
2011.09.18 v7から始めるunix まとめ
2011.09.18 v7から始めるunix まとめ2011.09.18 v7から始めるunix まとめ
2011.09.18 v7から始めるunix まとめ
 
スタート低レイヤー #0
スタート低レイヤー #0スタート低レイヤー #0
スタート低レイヤー #0
 
Php in ruby
Php in rubyPhp in ruby
Php in ruby
 
高速な暗号実装のためにしてきたこと
高速な暗号実装のためにしてきたこと高速な暗号実装のためにしてきたこと
高速な暗号実装のためにしてきたこと
 
Intro to SVE 富岳のA64FXを触ってみた
Intro to SVE 富岳のA64FXを触ってみたIntro to SVE 富岳のA64FXを触ってみた
Intro to SVE 富岳のA64FXを触ってみた
 
Programming camp 2008, Codereading
Programming camp 2008, CodereadingProgramming camp 2008, Codereading
Programming camp 2008, Codereading
 
ラズパイでデバイスドライバを作ってみた。
ラズパイでデバイスドライバを作ってみた。ラズパイでデバイスドライバを作ってみた。
ラズパイでデバイスドライバを作ってみた。
 
第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西第一回コンテナ情報交換会@関西
第一回コンテナ情報交換会@関西
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
 
ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!
 
ROS Tutorial 02 - CIT
ROS Tutorial 02 - CITROS Tutorial 02 - CIT
ROS Tutorial 02 - CIT
 
BLS署名の実装とその応用
BLS署名の実装とその応用BLS署名の実装とその応用
BLS署名の実装とその応用
 
Lxc cf201207-presen
Lxc cf201207-presenLxc cf201207-presen
Lxc cf201207-presen
 
A story of porting OpenBSD/luna88k
A story of porting OpenBSD/luna88kA story of porting OpenBSD/luna88k
A story of porting OpenBSD/luna88k
 
Sagittariusの紹介
Sagittariusの紹介Sagittariusの紹介
Sagittariusの紹介
 
SystemV IPC
SystemV IPCSystemV IPC
SystemV IPC
 
x86とコンテキストスイッチ
x86とコンテキストスイッチx86とコンテキストスイッチ
x86とコンテキストスイッチ
 
TripleOの光と闇
TripleOの光と闇TripleOの光と闇
TripleOの光と闇
 
Yesod on Heroku
Yesod on HerokuYesod on Heroku
Yesod on Heroku
 

More from inaz2

Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?inaz2
 
Why is Security Management So Hard?
Why is Security Management So Hard?Why is Security Management So Hard?
Why is Security Management So Hard?inaz2
 
HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装inaz2
 
Protecting Passwords
Protecting PasswordsProtecting Passwords
Protecting Passwordsinaz2
 
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in LinuxSelf Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linuxinaz2
 
Abusing Interrupts for Reliable Windows Kernel Exploitation (en)
Abusing Interrupts for Reliable Windows Kernel Exploitation (en)Abusing Interrupts for Reliable Windows Kernel Exploitation (en)
Abusing Interrupts for Reliable Windows Kernel Exploitation (en)inaz2
 
Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)
Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)
Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)inaz2
 
WinDbg Primer
WinDbg PrimerWinDbg Primer
WinDbg Primerinaz2
 
proxy2: HTTPS pins and needles
proxy2: HTTPS pins and needlesproxy2: HTTPS pins and needles
proxy2: HTTPS pins and needlesinaz2
 
How to apt-get from the internal network: remote sshd with kneesocks
How to apt-get from the internal network: remote sshd with kneesocksHow to apt-get from the internal network: remote sshd with kneesocks
How to apt-get from the internal network: remote sshd with kneesocksinaz2
 
CRYPT+YOU, UNDERSTAND TODAY!
CRYPT+YOU, UNDERSTAND TODAY!CRYPT+YOU, UNDERSTAND TODAY!
CRYPT+YOU, UNDERSTAND TODAY!inaz2
 
Making a Proxy for Fun and Profit
Making a Proxy for Fun and ProfitMaking a Proxy for Fun and Profit
Making a Proxy for Fun and Profitinaz2
 
Sniffing BitTorrent DHT ~人はBTで何を落とすのか~
Sniffing BitTorrent DHT ~人はBTで何を落とすのか~Sniffing BitTorrent DHT ~人はBTで何を落とすのか~
Sniffing BitTorrent DHT ~人はBTで何を落とすのか~inaz2
 

More from inaz2 (13)

Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?Can We Prevent Use-after-free Attacks?
Can We Prevent Use-after-free Attacks?
 
Why is Security Management So Hard?
Why is Security Management So Hard?Why is Security Management So Hard?
Why is Security Management So Hard?
 
HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装
 
Protecting Passwords
Protecting PasswordsProtecting Passwords
Protecting Passwords
 
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in LinuxSelf Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
 
Abusing Interrupts for Reliable Windows Kernel Exploitation (en)
Abusing Interrupts for Reliable Windows Kernel Exploitation (en)Abusing Interrupts for Reliable Windows Kernel Exploitation (en)
Abusing Interrupts for Reliable Windows Kernel Exploitation (en)
 
Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)
Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)
Abusing Interrupts for Reliable Windows Kernel Exploitation (ja)
 
WinDbg Primer
WinDbg PrimerWinDbg Primer
WinDbg Primer
 
proxy2: HTTPS pins and needles
proxy2: HTTPS pins and needlesproxy2: HTTPS pins and needles
proxy2: HTTPS pins and needles
 
How to apt-get from the internal network: remote sshd with kneesocks
How to apt-get from the internal network: remote sshd with kneesocksHow to apt-get from the internal network: remote sshd with kneesocks
How to apt-get from the internal network: remote sshd with kneesocks
 
CRYPT+YOU, UNDERSTAND TODAY!
CRYPT+YOU, UNDERSTAND TODAY!CRYPT+YOU, UNDERSTAND TODAY!
CRYPT+YOU, UNDERSTAND TODAY!
 
Making a Proxy for Fun and Profit
Making a Proxy for Fun and ProfitMaking a Proxy for Fun and Profit
Making a Proxy for Fun and Profit
 
Sniffing BitTorrent DHT ~人はBTで何を落とすのか~
Sniffing BitTorrent DHT ~人はBTで何を落とすのか~Sniffing BitTorrent DHT ~人はBTで何を落とすのか~
Sniffing BitTorrent DHT ~人はBTで何を落とすのか~
 

Recently uploaded

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 

Recently uploaded (12)

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 

ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)

  • 1. ROP ILLMATIC: EXPLORING UNIVERSAL ROP ON GLIBC X86-64@inaz2AVTOKYO20142014/11/15
  • 2. ABOUT ME•@inaz2•Security Engineer & Python Programmer•Girls Idol Freak•ブログ「ももいろテクノロジー」 •http://inaz2.hatenablog.com/ 2
  • 3. “ILLMATIC” ? •http://en.wikipedia.org/wiki/Illmatic•アメリカのラッパーNasによる造語 •"supreme ill. It's as ill as ill gets. That s*** is a science of everything ill." 3
  • 4. BACKGROUND•バッファオーバーフロー脆弱性などからの任意コード実行 •ドキュメント「各種セキュリティ機構が実装されている」 •どこまで突破できるのか? •論文「固定アドレスに十分な実行可能メモリが存在するならば…」 噂話「x86-64では固定アドレスに実行可能メモリが足りないので難し い」 •実行可能メモリが少ないときでも使える普遍的(universal)な方法はな いのか? 4
  • 5. ENVIRONMENT•x86-64環境におけるUbuntu Linux最新版 $ uname -a Linux vm-ubuntu64 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux $ lsb_release -a Description: Ubuntu 14.04.1 LTS $ gcc --version gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 $ clang --version Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) 5
  • 6. VULNERABLE CODE•スタックバッファオーバーフロー脆弱性を含む最小限のCコード 6 #include <unistd.h> int main() { char buf[100]; int size; read(0, &size, 8); read(0, buf, size); write(1, buf, size); return 0; } バッファサイズ以上の 書き込みが可能
  • 7. HOW THE CODE IS EXECUTED•RIPレジスタにその時点で実行されようとしている命令のアドレスが入っ ている •x86-64における関数呼び出し •call命令は次の命令のアドレスをスタックにpushしてripを変える •ret命令はスタックからアドレスをpopしてripを戻す •ELFにおけるライブラリ関数呼び出し •オブジェクトはGOT(Global Offset Table) およびPLT(Procedure Linkage Table) セクションを持つ •GOTはライブラリ関数のアドレステーブル •PLTはGOTに置かれた各アドレスにジャンプするためのエントリポイント •PLTを経由して間接ジャンプを行う 7
  • 8. SMASHING THE STACK [PHRACK49] •Published in 1996, written by Aleph One•関数からのリターンアドレスを書き換え、シェルコードに向ける 8 AAAA shellcode &buf buf[100] saved ebp return address higher address
  • 9. SECURITY MITIGATIONS•Enabled by default•NX/DEP•ASLR•Stack canary•Additional options•RELRO + BIND_NOW (FullRELRO) •FORTIFY_SOURCE•PIE 9
  • 10. NX/DEP (DATA EXECUTION PREVENTION) •書き換え可能メモリ(データ)の実行を禁止する •スタック・ヒープ領域に置いたシェルコードを実行しようとすると落ちる $ cat /proc/$$/maps 00400000-004ef000 r-xp 00000000 fc:00 265344 /bin/bash 006ef000-006f0000 r--p 000ef000 fc:00 265344 /bin/bash 006f0000-006f9000 rw-p000f0000 fc:00 265344 /bin/bash 006f9000-006ff000 rw-p 00000000 00:00 0 01cb0000-01ed1000 rw-p00000000 00:00 0 [heap] ... 7fffe374e000-7fffe376f000 rw-p00000000 00:00 0 [stack] 10
  • 11. ROP (RETURN-ORIENTED PROGRAMMING) [BH USA 2008] •リターンアドレスを書き換え、実行可能コードに向ける •ret命令で終わるコード断片(ROP gadget)へのリターンを繰り返す •jmp/call命令を使うものも含めてcode-reuse attackとも呼ばれる pop rdi; ret; system(“/bin/sh”) runs 11 &gadget /bin/sh¥x00 &buf buf[100] return address higher address &system
  • 12. X86-64 CALLING CONVENTIONS•x86-64では、関数の引数はレジスタにセットして渡される •rdi, rsi, rdx, rcx, r8, r9の順 •関数にリターンする前に各レジスタへの値のセットが必要 •“pop rdi; ret” / “pop rsi; ret” / “pop rdx; ret” / … •これらのgadgetが固定アドレスに揃っていないことも多い 12
  • 13. LIBC_CSU_INIT GADGETS•ほぼすべての実行ファイルに埋め込まれている__libc_csu_init関数 にあるコード断片を使う •3引数までの任意の関数呼び出しが可能 •第4引数(rcx)はmemset/memcpyを呼ぶことで操作可能 (1) loc_400626 スタックからレジスタに値をセット (2) loc_400610 引数にセットして[r12+rbx*8]をcall 13
  • 14. ASLR (ADDRESS SPACE LAYOUT RANDOMIZATION) •スタック・ヒープ領域や共有ライブラリのアドレスをランダム化 •実行ファイルが置かれるアドレスは固定のまま 14 heap a.out libc.so.6 1stexecution: higher address stack heap a.out libc.so.6 2ndexecution: stack
  • 15. ROP STAGER USING IO PRIMITIVES•PLTにある入出力関数を使い、固定アドレスにROPシーケンスを送り 込む •read/write, send/recv, fgets/fputs…, だいたい何かしらある •スタックポインタを送り込んだROPシーケンスに向ける(stack pivot) •rbpをセットしてleave命令を実行することでrspを差し替える read@plt # call read(0, 0x601048, 0x400) # 0x601048 = writable address around bss section pop rbp; ret; # set rbp=0x601048 leave; ret; # equiv. to “mov rsp, rbp; pop rbp” 15
  • 16. DETERMINING LIBRARY FUNCTION ADDRESS•ランダム化されたアドレスにあるsystem関数を呼ぶには? •GOTにある__libc_start_main関数のアドレスを読み出す •__libc_start_main関数からsystem関数までのオフセットを足す •ターゲットホストで使われているlibcバイナリを特定する必要がある •__libc_start_main関数の下位ビットから推測する方法も考えられる $ nm -D -n /lib/x86_64-linux-gnu/libc-2.19.so 0000000000021dd0 T __libc_start_main 0000000000046530 W system offset = 0x046530 −0x021dd0 = 0x24760 16
  • 17. RETURN-TO-DL-RESOLVE [PHRACK58] •Published in 2001, written by Nergal•偽のシンボル情報一式を作って、ダイナミックリンカ (_dl_runtime_resolve関数)に読ませる •libcバイナリの特定なしで、任意のライブラリ関数の呼び出しが可能 17 buf+= struct.pack(‘<Q’, addr_plt) # PLT0 jumps to resolver buf+= struct.pack(‘<Q’, offset2rela) buf+= ‘NEXT_RIP’ buf+= ‘A’ * alignment1 buf+= struct.pack(‘<QQQ’, writable_addr, offset2sym, 0) # Elf64_Rela buf+= 'A' * alignment2 buf+= struct.pack(‘<IIQQ’, offset2symstr, 0x12, 0, 0) # Elf64_Sym buf+= ‘system¥x00’ # symstr
  • 18. SKIPPING SYMBOL VERSION CHECK•x86-64ではふつうにReturn-to-dl-resolveを行うと落ちる •偽シンボルのバージョンのインデックスを取得する箇所でSEGV (*1) •GOTセクションにあるlink_map構造体のアドレスを読み出し、 [link_map+0x1c8]の値を0に書き換える •バージョン情報を取得する処理をスキップ if (l->l_info[VERSYMIDX (DT_VERSYM)]!= NULL) { const ElfW(Half) *vernum = (const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]); ElfW(Half) ndx= vernum[ELFW(R_SYM) (reloc->r_info)] & 0x7fff; // (*1) version = &l->l_versions[ndx]; if (version->hash == 0) version = NULL; } 18
  • 19. RELRO + BIND_NOW (FULLRELRO) •Relocation read-only with lazy binding disabled•実行直後にすべてのGOTアドレスを解決し、Read-onlyにする •実行時、メモリ上に_dl_runtime_resolve関数のアドレスがセットされ ない •直接呼び出すことができなくなる (gdb) x/4gx 0x601000 0x601000: 0x0000000000000000 0x0000000000000000 0x601010: 0x00000000000000000x0000000000000000 (gdb) x/4gx 0x601000 0x601000: 0x0000000000600e28 0x00007ffff7ffe1c8 0x601010: 0x00007ffff7df04e00x0000000000400456 19 FullRELRO(0x601000 = address of GOT section)
  • 20. DT_DEBUG TRAVERSAL•DynamicセクションにあるDT_DEBUGの値を見る •実行時にデバッグ用構造体r_debugのアドレスが入る •r_debugから、ロードされている各ライブラリのlink_map構造体が辿 れる •link_map構造体を通して、ライブラリに関する各種アドレスが得られる •ロードされたライブラリのGOTセクションから_dl_runtime_resolve関 数のアドレスを特定する 20
  • 21. LET’S TRY! •x86-64かつASLR+NX/DEP+FullRELROが有効な条件下におい て、シェルを起動する 1.関数呼び出しにlibc_csu_initgadgetsを用いる 2.IO primitivesを使って固定アドレスにROPシーケンスを送り込み、 stack pivotする 3.DT_DEBUG traversalを行い、_dl_runtime_resolve関数のアドレス を特定する 4.Return-to-dl-resolveでsystem関数を呼び出す 21
  • 22. DEMO 1•http://inaz2.hatenablog.com/entry/2014/10/12/191047•gccを使い、ASLR+NX/DEP+FullRELROを有効にした実行ファイルを 作る •ROP stager + Return-to-dl-resolveでシェルを起動する 22 Enable ASLR: $ sudosysctl-w kernel.randomize_va_space=2 Compile with NX/DEP+FullRELROenabled (w/o stack canary): $ gcc-fno-stack-protector -Wl,-z,relro,-z,nowbof.c Execute the program and exploit it: $ python exploit.py 100
  • 23. IT WORKS, BUT IS TOO COMPLICATED… DT_DEBUG Traversal requires read & write 5 times 23
  • 24. DYNAMIC ROP•Or “Just-in-time Code Reuse” [BH USA 2013] •libcメモリを丸ごと読み出して使う 1.GOTにある__libc_start_main関数のアドレスを読み出す 2.読み出したアドレスから0x160000バイト程度を読み出す 3.読み出したメモリ内にあるROP gadgetを使い、システムコールを実行 するROPシーケンスを構築する pop rax; ret; # set rax=59 (_NR_execve) pop rdi; ret; # set rdi="/bin/sh" pop rsi; ret; # set rsi={"/bin/sh", NULL} pop rdx; ret; # set rdx=NULL syscall; # call execve("/bin/sh", {"/bin/sh", NULL}, NULL) 24
  • 25. LEAVE-LESS EXECUTABLES•clangでコンパイルすると、関数エピローグにleave命令が使われない •“add rsp, XXh” の形で厳密にrspが調整される •leave命令がない場合のstack pivotはめんどい •固定アドレスに送り込んだROPシーケンスへのpivotが難しくなる gcc clang 25
  • 26. RETURN-TO-VULN•同一の脆弱な関数に繰り返しリターンする •stack pivotなしで次のROPシーケンスを実行できる 26 Vulnerable function Read the address of __libc_start_main Read the libcmemory Execute system call 1. 2. 3.
  • 27. ROPUTILS•https://github.com/inaz2/roputils•ROPに関する各種タスクを行うツールキット •readelfコマンドによるELFパース ⇒セクション、シンボル、よく使うgadgetのアドレスを取得 •パラメータからのROPシーケンス構築 •pipe (local) & socket (remote) 両対応のNon-blocking IO•Linux i386 / x86-64シェルコード生成 •適用されているセキュリティ機構の確認 •Metasploitパターンの生成およびオフセット計算 27
  • 28. ELFパース 各種アドレスの取得 ROPシーケンスの構築 すべてのクラスをimport Non-blocking IO ターゲットがremoteなら 次のようにする: Proc(host=x, port=y) 28
  • 29. DEMO 2•https://github.com/inaz2/roputils/blob/master/examples/libc- dynamic-no-leave-x64.py•clangを使い、ASLR+NX/DEP+FullRELROを有効にした実行ファイ ルを作る •socatを使ってTCPサービスにする •Dynamic ROP + Return-to-vulnでリモートシェルを起動 Enable ASLR and compile with NX/DEP+FullRELROenabled (w/o stack canary): $ sudosysctl-w kernel.randomize_va_space=2 $ clang -fno-stack-protector -Wl,-z,relro,-z,nowbof.c Execute the program as a TCP service: $ socattcp-listen:5000,fork,reuseaddr exec:./a.out& Exploit it: $ python libc-dynamic-no-leave-x64.py ./a.out120 29
  • 30. HOW ABOUT THE REST? Stack canary, FORTIFY_SOURCE and PIE 30
  • 31. STACK CANARY•リターンアドレスの前にランダムな値を差し込むことでスタックバッファ オーバーフローを検知 •値が変わっていたら強制終了 •ターゲットが単純なfork serverなら、1バイトずつのbruteforceで突 破可能(最大試行数256 * 8 = 2048) •Heap overflow / Use-after-free脆弱性などによるポインタ書き換え に対しては効果なし 31 値が変わってないかチェック
  • 32. FORTIFY_SOURCE•危険な標準ライブラリ関数を安全なものに置き換える •gets → gets_chk, strcpy→ strcpy_chk, read → read_chk, … •バッファサイズのチェックを追加 •ほとんどのスタックバッファオーバーフロー脆弱性は塞がれる •ただし、*_chkを使ったROP stager自体は可能 •Heap overflow / Use-after-free脆弱性などによるポインタ書き換えを 探す 32 read(0, buf, size) → __read_chk(0, buf, size, 100)
  • 33. PIE (POSITION-INDEPENDENT EXECUTABLES) •実行ファイルが置かれるアドレスもランダム化 •もちろんASLRが有効な場合に限る •実行ファイルやlibc中にある何かしらのアドレスが得られる場合には 効果なし(information leak) •Buffer over-readなど他の脆弱性を使う •下位バイトのみを書き換えることで、リターンアドレスをずらすことはで きる(partial overwrite) •しかし、genericな攻撃は難しいと思われる 33
  • 34. FURTHER MITIGATIONS•Shadow stack•StackShield(2000), TRUSS (2008), ROPdefender(2011) •リターンアドレスを別の領域にコピーしておき検証する •Related: “SCADS: Separated Control-and Data-Stacks” (2014) •Coarse-grained Control-Flow Integrity (CFI) •ROPGuard(2012), kBouncer(2013), ROPecker(2014) •Indirect Branches and Behavior-Based Heuristics policies•取り得るジャンプ先を集めておいて検証する •短い命令列が連続する回数を制限する(閾値ベース) •Call-ret-pair gadget、Long-NOP gadgetが存在すればbypass可能 34
  • 35. RECAP•NX/DEP bypass: ROP•ASLR bypass: ROP stager•前提条件: PLT上のIO primitives、十分なROP用バッファ •x86-64での関数呼び出し: libc_csu_init gadgets•ライブラリ関数呼び出し: Return-to-dl-resolve•FullRELRObypass: DT_DEBUG traversal•システムコール実行: Dynamic ROP•leave-less executable対策: Return-to-vuln•ROP is illmatic 35
  • 36. REFERENCES (1/2) •"Exploit" -記事一覧-ももいろテクノロジー •http://inaz2.hatenablog.com/archive/category/Exploit•Smashing The Stack For Fun And Profit (Phrack49) •http://phrack.org/issues/49/14.html•The advanced return-into-lib(c) exploits: PaXcase study (Phrack58) •http://phrack.org/issues/58/4.html•Return-Oriented Programming: Exploits Without Code Injection (Black Hat USA 2008) •http://cseweb.ucsd.edu/~hovav/talks/blackhat08.html•Return to Dynamic Linker (Codegate2014 Junior) •http://blog.jinmo123.pe.kr/entry/Codegate-2014-Junior-Presentation 36
  • 37. REFERENCES (2/2) •Ghost in the Shellcode 2014 -fuzzy -Code Arcana•http://codearcana.com/posts/2014/01/19/ghost-in-the-shellcode-2014-fuzzy.html•Just-In-Time Code Reuse: The more things change, the more they stay the same (Black Hat USA 2013) •https://media.blackhat.com/us-13/US-13-Snow-Just-In-Time-Code-Reuse- Slides.pdf•SCADS: Separated Control-and Data-Stacks (SECURECOMM 2014) •https://www1.cs.fau.de/filepool/scads/scads-securecomm2014.pdf•Stitching the Gadgets: On the Ineffectiveness of Coarse-Grained Control- Flow Integrity Protection (USENIX Security 2014) •https://www.usenix.org/conference/usenixsecurity14/technical- sessions/presentation/davi•And many others 37