1 / 6

バッファオーバーフロー実験

バッファオーバーフロー実験. 2001 年 9 月 11 日 上牧瀬 誠. オーバーフロー. バッファオーバーフローとは. バッファより長いデータを与える. バッファ. 入力データ. buf[] の 先頭アドレス. buf[10] の領域. 簡単な例. int foo() { char *rtn; char buf[10]; gets(buf); }. rtn. 戻り値アドレスなど. スタック. buf[] の領域より大きいデータが書き込まれると, rtn ,戻り値アドレスなどが 上書き される.

sileas
Download Presentation

バッファオーバーフロー実験

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. バッファオーバーフロー実験 2001年9月11日 上牧瀬 誠

  2. オーバーフロー バッファオーバーフローとは • バッファより長いデータを与える バッファ 入力データ

  3. buf[]の 先頭アドレス buf[10]の領域 簡単な例 int foo() { char *rtn; char buf[10]; gets(buf); } rtn 戻り値アドレスなど スタック buf[]の領域より大きいデータが書き込まれると, rtn,戻り値アドレスなどが上書きされる

  4. バッファオーバーフローで戻り値アドレスを書き換えるバッファオーバーフローで戻り値アドレスを書き換える (別のプログラムの先頭アドレス) root権限を取得 無権限利用 多くのサーバプログラムはroot権限で稼動

  5. 対策 • 入力データを読み込むときに,長さを指定する関数を 使用する • 入力データを保持するバッファは,長さを調べた上で 動的に確保する

  6. 実験 #include <stdio.h> #define BUFLEN 200 int main(int argc , char **argv) { char *rtn; char dmy[BUFLEN]; char buf[BUFLEN]; memset(dmy,'\0',BUFLEN); memset(buf,'\0',BUFLEN); printf("before\n"); printf("buf(len:%d) = %s\n",strlen(buf),buf); printf("dmy(len:%d) = %s\n",strlen(dmy),dmy); if((rtn = gets(buf)) == NULL) exit(1); printf("after\n"); printf("buf(len:%d) = %s\n",strlen(buf),buf); printf("dmy(len:%d) = %s\n",strlen(dmy),dmy); } • /u/makoto_k/rinkou/buffer/から次のファイルをコピー • buftest.c • test.dat • コンパイルし,実行 • gcc buftest.c –o buftest • ./buftest < test.dat

More Related