4
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function
Slide 5
Slide 5 text
5
Overview
Slide 6
Slide 6 text
6
提案アイディア
稼働しているサービスが攻撃を受けるのは困る
Attack!
Service Cracker
21
緩和の仕組み
.plt section
printf (jmp to library)
.text section
(...)
call printf (jmp to .plt)
(...)
Slide 22
Slide 22 text
緩和の仕組み
22
.plt section
printf (jmp to library)
.text section
(...)
call printf (jmp to .plt)
(...)
Slide 23
Slide 23 text
緩和の仕組み
23
.plt section
printf (jmp to library)
.text section
(...)
call printf (jmp to .plt)
(...)
HOOOOOOK!
Slide 24
Slide 24 text
緩和の仕組み
24
.plt section
printf (jmp to library)
.text section
(...)
call printf (jmp to .plt)
(...)
in Context
Register
ESP EBP EIP EAX
Memory
Stack
Heap
Slide 25
Slide 25 text
25
Function Detail
Slide 26
Slide 26 text
26
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function
Slide 27
Slide 27 text
27
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function
1. Filtering Dangerous Function (Detail)
31
①Elf32_Rel構造体のr_infoから対応するElf32_Sym構造体へのインデックスを取得
②Elf32_Sym構造体のst_nameから対応する.dynstrへのインデックスを取得
③.dynstrセクションから指定されたインデックスの文字列を調べる
Elf32_Rel
Elf32_Sym
Elf32_Sym
Elf32_Sym
...
t f \0 g e t s \0
①r_info
②st_name
Proposal
Slide 32
Slide 32 text
1. Filtering Dangerous Function (Detail)
32
関数の名前を探しているだけ
Elf32_Rel
Elf32_Sym
Elf32_Sym
Elf32_Sym
...
t f \0 g e t s \0
①r_info
②st_name
Proposal
Slide 33
Slide 33 text
実験
33
gets関数の使用
(危険な関数を使っている)
※C11でなくなった関数
Slide 34
Slide 34 text
結果
実行しないようにできた
34
Slide 35
Slide 35 text
2. Implementation of Self-NX
No Excute (NX bit)の機能を擬似的に再現する
35
r w x p
Overview
Slide 36
Slide 36 text
2. Implementation of Self-NX (Detail)
36
data
code
heap
stack
EIP
Proposal
Slide 37
Slide 37 text
2. Implementation of Self-NX (Detail)
37
data
heap
stack
EIP
Proposal
code
Slide 38
Slide 38 text
2. Implementation of Self-NX (Detail)
38
data
code
heap
stack
EIP
Proposal
Slide 39
Slide 39 text
実験
39
/bin/shが立ち上がる
シェルコードがある
(今回はそれを実行する)
Slide 40
Slide 40 text
結果
/bin/shが実行されることなく終了している
40
Slide 41
Slide 41 text
3. Detecting Use After Free
freeしたメモリが使われるのを防止する
41
free-ed
memory
!!! DO NOT USE !!!
Overview
Slide 42
Slide 42 text
3. Detecting Use After Free (Detail)
42
function.txt
Proposal
Slide 43
Slide 43 text
3. Detecting Use After Free (Detail)
43
function.txt
Proposal
fgets(0x12345678,0x20,stdin)
Slide 44
Slide 44 text
3. Detecting Use After Free (Detail)
44
function.txt
Proposal
fgets(0x12345678,0x20,stdin)
Slide 45
Slide 45 text
3. Detecting Use After Free (Detail)
45
function.txt
Proposal
fgets(0x12345678,0x20,stdin)
0xabadbabe
0xbaddcafe
0x12345678
0xfacefeed
0xfee1dead
free-ed
Slide 46
Slide 46 text
3. Detecting Use After Free (Detail)
46
function.txt
Proposal
fgets(0x12345678,0x20,stdin)
0xabadbabe
0xbaddcafe
0x12345678
0xfacefeed
0xfee1dead
free-ed
Slide 47
Slide 47 text
3. Detecting Use After Free (Detail)
47
function.txt
fgets(0x12345678,0x20,stdin) !!!
!!!
Proposal
0xabadbabe
0xbaddcafe
0x12345678
0xfacefeed
0xfee1dead
free-ed
5. Collection of Function Argument
関数で使われたバッファなどの中身を収集する
57
123456
iloveyou
football
1234567
letmein
123456789
12345
qwerty
122345678
password
2017年のパスワードTop 10 https://news.mynavi.jp/article/20171220-559970/
Overview
Slide 58
Slide 58 text
5. Collection of Function Argument (Detail)
58
function_list.txt
Proposal
Slide 59
Slide 59 text
5. Collection of Function Argument (Detail)
59
function_list.txt
Proposal
“fgets,1”
“gets,1”
Slide 60
Slide 60 text
5. Collection of Function Argument (Detail)
60
function_list.txt
Proposal
“fgets,1”
“gets,1”
fgets(buf,sizeof(buf),stdin)
Slide 61
Slide 61 text
5. Collection of Function Argument (Detail)
61
function_list.txt
Proposal
“fgets,1”
“gets,1”
fgets(buf,sizeof(buf),stdin)
“I’ll be back” “SecHack365 Returns”
Slide 62
Slide 62 text
5. Collection of Function Argument (Detail)
62
function_list.txt
Proposal
“fgets,1”
“gets,1”
fgets(buf,sizeof(buf),stdin)
“I’ll be back” “SecHack365 Returns”
honeypot.log
Slide 63
Slide 63 text
5. Collection of Function Argument (Detail)
63
function_list.txt honeypot.log
fgets(buf,sizeof(buf),stdin)
“I’ll be back”
“I’ll be back”
“SecHack365 Returns”
“fgets,1”
“gets,1”
“SecHack365 Returns”
Proposal
Slide 64
Slide 64 text
実験
64
今回はこのfgets関数の
入力されたデータを
ハニポログとして収集する
Slide 65
Slide 65 text
結果
入力した内容を時刻付きでログに収めることができた
65
Slide 66
Slide 66 text
66
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function
Slide 67
Slide 67 text
67
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function
Slide 68
Slide 68 text
6. Restricting the Format String
書式文字列の中から%n指定子を探し出して置き換える
68
%c%s%d%u%o%x%f%e
%g%ld%lu%n%lo%lx%lf
%c%s%d%u%o%x%f%e
%g%ld%luxx%lo%lx%lf
Overwrite!
Overview
Slide 69
Slide 69 text
書式文字列と引数の関係(x86の場合)
69
printf(“%d%s%x”,int,str,hex)
Problem
Slide 70
Slide 70 text
書式文字列と引数の関係(x86の場合)
70
printf(“%d%s%x”,int,str,hex)
“%d%s%x”
数値
文字列
数値
スタック
Problem
Slide 71
Slide 71 text
書式文字列と引数の関係(x86の場合)
71
printf(“%d%s%x”,int,str,hex)
“%d%s%x”
数値
文字列
数値
スタック
参照
Problem
Slide 72
Slide 72 text
書式文字列と引数の関係(x86の場合)
72
printf(“%d%s%x”,int,str,hex)
“%d%s%x”
数値
文字列
数値
スタック
参照
Problem
Slide 73
Slide 73 text
書式文字列と引数の関係(x86の場合)
73
printf(“%d%s%x”,int,str,hex)
“%d%s%x”
数値
文字列
数値
スタック
参照
Problem
9. Protecting the Global Offset Table
GOTの不正な書き換えを検知して元の値に戻す
130
PLT
Library
Evil Code
GOT
Overview
Slide 131
Slide 131 text
Global Offset Tableの仕組みと書換え
131
Problem
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
PLT
GOT
Slide 132
Slide 132 text
Global Offset Tableの仕組みと書換え
132
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
初回呼び出し
Slide 133
Slide 133 text
Global Offset Tableの仕組みと書換え
133
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
初回呼び出し
Slide 134
Slide 134 text
Global Offset Tableの仕組みと書換え
134
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
初回呼び出し
Slide 135
Slide 135 text
Global Offset Tableの仕組みと書換え
135
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
初回呼び出し
Slide 136
Slide 136 text
Global Offset Tableの仕組みと書換え
136
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
初回呼び出し
Slide 137
Slide 137 text
Global Offset Tableの仕組みと書換え
137
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
2回目以降
Slide 138
Slide 138 text
Global Offset Tableの仕組みと書換え
138
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
2回目以降
Slide 139
Slide 139 text
Global Offset Tableの仕組みと書換え
139
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード
攻撃時
Slide 140
Slide 140 text
Global Offset Tableの仕組みと書換え
140
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード 攻撃
攻撃時
Slide 141
Slide 141 text
Global Offset Tableの仕組みと書換え
141
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード 攻撃
攻撃時
Slide 142
Slide 142 text
Global Offset Tableの仕組みと書換え
142
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード
攻撃時
Slide 143
Slide 143 text
Global Offset Tableの仕組みと書換え
143
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード
攻撃時
Slide 144
Slide 144 text
Global Offset Tableの仕組みと書換え
144
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード
攻撃時
Slide 145
Slide 145 text
Global Offset Tableの仕組みと書換え
145
Problem
PLT
GOT
プログラム
(printf関数呼び出し)
ライブラリ
(printf関数の本体)
悪意あるコード
GOTが書き換えられると
コントロールが奪われてしまう
攻撃時
Slide 146
Slide 146 text
9. Protecting the Global Offset Table (Detail)
146
GOT of func1
Saved GOT
status
GOT of func2
GOT of func3
GOT of func1
GOT of func2
GOT of func3
GOT in Memory
Proposal
Slide 147
Slide 147 text
9. Protecting the Global Offset Table (Detail)
147
GOT of func1
Not Called
Saved GOT
status
GOT of func2
GOT of func3
Overwrite
GOT of func2
GOT of func3
GOT in Memory
Proposal
Slide 148
Slide 148 text
9. Protecting the Global Offset Table (Detail)
148
GOT of func1
Not Called
Saved GOT
status
GOT of func2
GOT of func3
Overwrite
GOT of func2
GOT of func3
GOT in Memory
Proposal
Slide 149
Slide 149 text
9. Protecting the Global Offset Table (Detail)
149
GOT of func1
Not Called
Saved GOT
status
GOT of func2
GOT of func3
GOT of func1
GOT of func2
GOT of func3
GOT in Memory
Proposal
Slide 150
Slide 150 text
9. Protecting the Global Offset Table (Detail)
150
GOT of func1
Not Called
Saved GOT
status
GOT of func2
Calling...
GOT of func3
GOT of func1
Overwrite
GOT of func3
GOT in Memory
Proposal
Slide 151
Slide 151 text
9. Protecting the Global Offset Table (Detail)
151
GOT of func1
Not Called
Saved GOT
status
GOT of func2
Calling...
GOT of func3
GOT of func1
Overwrite
GOT of func3
GOT in Memory
Proposal
Slide 152
Slide 152 text
9. Protecting the Global Offset Table (Detail)
152
GOT of func1
Not Called
Saved GOT
status
GOT of func2
Calling...
GOT of func3
GOT of func1
Overwrited
GOT of func3
GOT in Memory
Proposal
Slide 153
Slide 153 text
9. Protecting the Global Offset Table (Detail)
153
GOT of func1
Not Called
Saved GOT
status
GOT of func2
Calling...
GOT of func3
Called
GOT of func1
Overwrited
Overwrite
GOT in Memory
Proposal
Slide 154
Slide 154 text
9. Protecting the Global Offset Table (Detail)
154
GOT of func1
Not Called
Saved GOT
status
GOT of func2
Calling...
GOT of func3
Called
GOT of func1
Overwrited
Overwrite
GOT in Memory
Proposal
Slide 155
Slide 155 text
9. Protecting the Global Offset Table (Detail)
155
GOT of func1
Not Called
Saved GOT
status
GOT of func2
Calling...
GOT of func3
Called
GOT of func1
Overwrited
GOT of func3
GOT in Memory
Proposal
Slide 156
Slide 156 text
実験
156
既存のputs関数のGOTを
書き換えようとしている
(GOT Overwrite)
Slide 157
Slide 157 text
結果
GOT Overwriteを検知して元のアドレスに戻すことができた
157
Slide 158
Slide 158 text
158
Demo
Slide 159
Slide 159 text
159
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function
169
Buffer
Overflow
Format
String
RELRO
Double
Free
Mitigation
Detection
System
Call
Use After
Free
No
Execute
Dangerous
Function
Collection
Function
Argument
9 Function