Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Stack&Heep
Search
Kotokaze
May 31, 2021
Education
90
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Stack&Heep
スタック・ヒープオーバーラン勉強会の資料です
Kotokaze
May 31, 2021
More Decks by Kotokaze
See All by Kotokaze
Introduction to Git & GitHub
kotokaze
0
250
ファイルレスマルウェアの実態と対策
kotokaze
1
550
実は簡単!? AIを攻撃してみよう
kotokaze
0
420
Other Decks in Education
See All in Education
Sekolah Sabat - Triwulan 3 2026 - Pelajaran 13
hiola
0
11k
【ainiチャット操作ガイド】
ainischool
0
120
Carbohydrates: Classification, Structure & Chemical Properties
pawan_pharm
0
330
Requirements Analysis and Prototyping - Lecture 3 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.8k
生成AIとの付き合い方/ How to work with AI
kaityo256
PRO
3
890
Padlet opetuksessa
matleenalaakso
12
16k
AIの力を100%引き出すために
frievea
0
610
Sekolah Sabat - Triwulan 4 2026 - Pelajaran 3
hiola
0
6.7k
aini school小中等部説明会資料
ainischool
0
180
SANG PENCIPTA BERBICARA (01ABSG-Q4-2026)
ssmedikasda
0
470
学習者データを「見る」:外国語教師のためのデータの入力、分析、解釈方法
uranoken
0
440
人間関係に取り組む、その時に / step away to make space
spring_aki
0
140
Featured
See All Featured
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
BBQ
matthewcrist
90
10k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Facilitating Awesome Meetings
lara
57
7.2k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
Building Applications with DynamoDB
mza
96
7.2k
Evolving SEO for Evolving Search Engines
ryanjones
0
330
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