Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Stack&Heep
Search
Kotokaze
May 31, 2021
Education
86
0
Share
Stack&Heep
スタック・ヒープオーバーラン勉強会の資料です
Kotokaze
May 31, 2021
More Decks by Kotokaze
See All by Kotokaze
Introduction to Git & GitHub
kotokaze
0
230
ファイルレスマルウェアの実態と対策
kotokaze
1
500
実は簡単!? AIを攻撃してみよう
kotokaze
0
380
Other Decks in Education
See All in Education
Design Guidelines and Principles - Lecture 7 - Information Visualisation (4019538FNR)
signer
PRO
0
3k
小さなまちで始める デジタル創作の居場所〜すべての子どもが創造的に未来を描ける社会へ〜
codeforeveryone
0
510
Protecting Patrons with Digital Vendors
dsalo
0
170
Dashboards - Lecture 11 - Information Visualisation (4019538FNR)
signer
PRO
1
2.7k
2026年度春学期 統計学 第2回 統計資料の収集と読み方 (2026. 4. 16)
akiraasano
PRO
0
160
[2026前期火5] 論理学(京都大学文学部 前期 第2回)「論理的な正しさはどこにあるのか」
yatabe
0
910
From Days to Minutes: How We Taught an AI to Onboard 50+ Tenants on our AI Features
mfcabrera
0
150
2026年度春学期 統計学 第5回 分布をまとめるー記述統計量(平均・分散など) (2026. 5. 7)
akiraasano
PRO
0
110
From Participation to Outcomes
territorium
PRO
0
460
Data Physicalisation - Lecture 9 - Next Generation User Interfaces (4018166FNR)
signer
PRO
1
1k
Lectura 2 (PIT : Python Basico)
robintux
0
310
Liberalism's Last Man and Asia
vyadav
0
140
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
390
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
160
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
250
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
140
The browser strikes back
jonoalderson
0
1.1k
How GitHub (no longer) Works
holman
316
150k
Skip the Path - Find Your Career Trail
mkilby
1
130
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
200
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
30 Presentation Tips
portentint
PRO
1
300
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Transcript
スタックとヒープ Kotokaze
1. メモリとは データの⼀時置き場 ( ⼤きな配列のようなもの) のこと プロセス実⾏時には、プログラムがメモリ上に展開される → 32bit コンピュータであれば、232
分だけ確保* される +----------------------------------------------------- ---------------+ | 0x00000000 | 0x00000001 | 0x00000002 | 0x00000003 | ≈≈≈≈≈ | 0xFFFFFFFF | +----------------------------------------------------- ---------------+ * ほとんどの場合では、必要とする分だけ OS が⽤意してくれる 2
environ argv share bss data text 0 番地 232 番地
heep stack 2. プロセスとメモリ 名称 主な配置データ 備考 text 機械語 Read Only data グローバル変数 初期値有り bss グローバル変数 初期値無し heep 動的なデータ malloc など stack ⾃動変数/ アドレス ⾃動的に拡張 3
data data 3. スタック 積み⽊ように、積み上げてデータ保存 アクセスできるのは最上位のみ スタック領域では、ローカル変数・ リターンアドレスなどを保存 命令語 内容
PUSH スタックの先頭に追加 POP スタック先頭の値を取り出す 4
使⽤中 data1 data0 使⽤中 使⽤中 使⽤中 4. ヒープ 使う分だけ確保して使う 未整列
( 空域に⾃動配置) → 場所指定でアクセス可 ⾃由度は⾼いが、 脆弱になりやすい int* data0 = new int[sizeof(buff)]; int* data1 = malloc(sizeof(buff)); 5
5. バッファ・オーバーラン (CWE-119) 実⾏中プロセスのメモリ内における、 意図したバッファ外の値を読み書きすること C / C++ で発⽣しやすい 名称
対象 スタック破壊攻撃 ローカル( ⾃動) 変数・リターンアドレス ヒープ破壊攻撃 配置したデータ 6
6. プログラム解析 サンプルコードの解析をしてみよう! サンプルコード: Kotokaze/stack-study 7
6. プログラム解析 (2) Key1: Stack のコンストラクタで、 data0 / data1 を初期化
→ ヒープ領域に連続して* 配置されていると考えられる +-----------------------------------------------------------------------+ | data0 | data1 | ≈≈≈≈≈ | +-----------------------------------------------------------------------+ * 複数の初期化を同時に⾏うと、連続して配置される場合が多い 8
6. プログラム解析 (3) Key2: コンストラクタに注⽬ for (int i = 0;
i <= this->tail; i++) this->data1[i] = 3; 名称 \ 位置 0 1 2 3 4 5 6 7 data0 - - - - - - - - data1 3 3 3 3 3 3 3 3 9
6. プログラム解析 (4) Key3: 値の変化に注⽬ → main のループで順に代⼊していくと... for (int
i = 0; i < num; i++) stk.push(i + 1); 名称 \ 位置 0 1 2 3 4 5 6 7 data0 1 2 3 - - - - - data1 3 3 3 3 3 3 3 3 10
7. 動かしてみる data0 に 12 回の値を⼊れ続けるとどうなる??? → README を参考に動かしてみよう ※
脆弱性を含んでいる事に注意しましょう 11
参考情報 https://jvndb.jvn.jp/ja/cwe/CWE-119.html https://www.ipa.go.jp/security/awareness/vendor/programmingv2/ contents/c901.html 12