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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kotokaze
May 31, 2021
Education
0
84
Stack&Heep
スタック・ヒープオーバーラン勉強会の資料です
Kotokaze
May 31, 2021
Tweet
Share
More Decks by Kotokaze
See All by Kotokaze
Introduction to Git & GitHub
kotokaze
0
220
ファイルレスマルウェアの実態と対策
kotokaze
1
480
実は簡単!? AIを攻撃してみよう
kotokaze
0
370
Other Decks in Education
See All in Education
高校数学B「統計的な推測」 分野の問題と課題
shimizudan
1
120
バージョン管理とは / 01-a-vcs
kaityo256
PRO
1
220
インシデント対応
akira345
0
360
滑空スポーツ講習会2025(実技講習)EMFT講習 実施要領/JSA EMFT 2025 procedure
jsaseminar
0
160
Introduction - Lecture 1 - Next Generation User Interfaces (4018166FNR)
signer
PRO
2
4.5k
Virtual and Augmented Reality - Lecture 8 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
2.1k
Gesture-based Interaction - Lecture 6 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
2.1k
小さなまちで始める デジタル創作の居場所〜すべての子どもが創造的に未来を描ける社会へ〜
codeforeveryone
0
240
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
Measuring your measuring
jonoalderson
2
790
Leveraging LLMs for student feedback in introductory data science courses (Stats Up AI)
minecr
1
240
Interactive Tabletops and Surfaces - Lecture 5 - Next Generation User Interfaces (4018166FNR)
signer
PRO
1
2k
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
150
Building Adaptive Systems
keathley
44
3k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
980
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Utilizing Notion as your number one productivity tool
mfonobong
4
270
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.5k
RailsConf 2023
tenderlove
30
1.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
150
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Done Done
chrislema
186
16k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
310
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