超精講-逐例分析CS:LAB2-Bomb!(上)
阿新 • • 發佈:2021-01-20
### 0. 環境要求
關於環境已經在lab1裡配置過了這裡要記得安裝`gdb`
安裝命令 `sudo yum install gdb`
實驗的下載地址 http://csapp.cs.cmu.edu/3e/labs.html
gbd的命令地址 http://csapp.cs.cmu.edu/2e/docs/gdbnotes-x86-64.pdf
知乎同款連線 https://zhuanlan.zhihu.com/p/339461318
這裡我們需要使用`objdump -d ./bomb >> bomb.s`反彙編工具來得到彙編程式碼。
下面就開始==舉世盛名==的`bomb` 實驗吧
### 1. 第一關
1. 粗讀 `main` 函式
```c
initialize_bomb();
printf("Welcome to my fiendish little bomb. You have 6 phases with\n");
printf("which to blow yourself up. Have a nice day!\n");
/* Hmm... Six phases must be more secure than one phase! */
input = read_line(); /* Get input */
phase_1(input); /* Run the phase */
phase_defused(); /* Drat! They figured it out!
```
通過簡單的閱讀理解應該知道這裡面的`phase_1` 就是我們的第一關了,然後根據函式名稱` input = read_line()` 應該是要驗證我們的輸入是否合理,我們先亂輸入一個看看先執行起來
```scala
(gdb) r
Starting program: /csapp/bomb/bomb
warning: Error disabling address space randomization: Operation not permitted
Welcome to my fiendish little bomb. You have 6 phases with
which to blow yourself up. Have a nice day!
```
輸入`hello wordl`
```tcl
hello world
BOOM!!!
The bomb has blown up.
[Inferior 1 (process 67) exited with code 010]
```
果然