pwnable.kr(5) - passcode
## Problem
Points: 10 pt
Link
1
2
3
4
5Mommy told me to make a passcode based login system.
My initial C code was compiled without any error!
Well, there was some compiler warning, but who cares about that?
ssh [email protected] -p2222 (pw:guest)
Thinking
Code
1 |
|
Solution
main當中只有兩個function,
L27welcome看起來很正常,scanf有指定字元長度100,沒有辦法做bof。
接著看L4login,其中L9跟L14的scanf都沒有&取址符號,所以會直接取用這兩個沒有初始化的變數內容來當作地址輸入。
在沒辦法正確輸入數值到passcode1跟passcode2的狀況之下,理所當然會得到一個Address boundary error,所以連試都不用試了。
所以我們需要找出方法,把passcode1的內容設定成一個合法的地址。
幾個輸入點只有welcome的L30,login的L9,L14。
雖然welcome的scanf有指定字元長度,
但是還是用gdb看一下能不能蓋內容過去。
1 | Breakpoint 1, 0x08048668 in main () |
Prepare
C scanf
1 |
|
1 | If success, return the number of items of argument list successfully filled. |
正常來講,
scanf的常見格式應該為scanf("%s", &var);。
若scanf沒有取址符號&,則直接將var的值作為地址寫入。
所以平常情況下,沒有加上取址符號會造成Address boundary error