安全编程原理-LAB4-Format-String-Vulnerability

#Lab 2.4 Format String Vulnerability

1、Crash the program named “vul_prog.c”.

连续输入 %s 即可,经过实验 最少3个就可以完成crash

image-20200617160839651image-20200617160839651

如图,出现段错误

2、Print out the secret[1] value.

image-20200617170452971image-20200617170452971

调试代码,在printf设置断点,运行到printf(user_input)

查看堆栈如上,可以看到user_input的参数地址为 0xffffd668 而看1的位置,可以知道user_input和int_input地址差了16.

因此我们可以将secret1的值输入到int_input. 然后通过8个 .%08x 来控制字符串。 输入 “.%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x|%s”

image-20200617174550605image-20200617174550605

|后面输出了 U 即为secret 并且前面的地址和debug的结果一致

3、 Modify the secret[1] value.

只需使用%hn即可

image-20200617175026933image-20200617175026933

如图 新的密码变成了0x48

###4、 Modify the secret[1] value to a pre-determined value.

我们把secret1 改为 0x1111

同理,但是我们前面控制长度的字符需要进行改变

0x1111 十进制为 4369

8个.08x 输出长度 8*9=72,远远小于4369

改为7个 .08x 7*9=63

4369-63+1=4307

故输入

%.08x.%08x.%08x.%08x.%08x.%08x.%08x%.4307d%hn

image-20200617180620725image-20200617180620725

如图 得到了0x1111的正确结果