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