这种情况下,缓冲区无法溢出?

环境是FC9,GCC版本是4.3.0,代码如下

#include <string.h>

int main(int argc, char **argv)
{
        char arr[512];
        if (argc > 1)
        {
                strcpy(arr, argv[1]);
        }
        return 0;
}


用试探法,无法覆盖EIP的值,我输入了600,700,到最后,输入5000,10000。竟然还是无法覆盖EIP的值。于是,调试。

反汇编main函数,得到

(gdb) disass main
Dump of assembler code for function main:
0x080483c4 <main+0>:    lea    0x4(%esp),%ecx
0x080483c8 <main+4>:    and    $0xfffffff0,%esp
0x080483cb <main+7>:    pushl  -0x4(%ecx)
0x080483ce <main+10>:   push   %ebp
0x080483cf <main+11>:   mov    %esp,%ebp
0x080483d1 <main+13>:   push   %ecx
0x080483d2 <main+14>:   sub    $0x214,%esp
0x080483d8 <main+20>:   mov    %ecx,-0x208(%ebp)
0x080483de <main+26>:   mov    -0x208(%ebp),%eax
0x080483e4 <main+32>:   cmpl   $0x1,(%eax)
0x080483e7 <main+35>:   jle    0x8048409 <main+69>
0x080483e9 <main+37>:   mov    -0x208(%ebp),%edx
0x080483ef <main+43>:   mov    0x4(%edx),%eax
0x080483f2 <main+46>:   add    $0x4,%eax
0x080483f5 <main+49>:   mov    (%eax),%eax
0x080483f7 <main+51>:   mov    %eax,0x4(%esp)
0x080483fb <main+55>:   lea    -0x204(%ebp),%eax
0x08048401 <main+61>:   mov    %eax,(%esp)
0x08048404 <main+64>:   call   0x80482f4 <strcpy@plt>
0x08048409 <main+69>:   mov    $0x0,%eax
0x0804840e <main+74>:   add    $0x214,%esp
0x08048414 <main+80>:   pop    %ecx
0x08048415 <main+81>:   pop    %ebp
0x08048416 <main+82>:   lea    -0x4(%ecx),%esp
0x08048419 <main+85>:   ret    
End of assembler dump.
(gdb) 


看到需要覆盖的地址是0x08048409

在0x08048404处设置断点,输入10个A,来进行调试

最后,发现如下:

(gdb) x/50x $esp
0xbffff4b0:     0x00000000      0x08048310      0xbffff6d8      0x08048409
0xbffff4c0:     0xbffff4d4      0xbffff8b8      0x00000000      0x00000000
0xbffff4d0:     0xbffff6f0      0x41414141      0x00414141      0x00000000
0xbffff4e0:     0x00000000      0x00000000      0x002535b8      0x002535ac
0xbffff4f0:     0x00000000      0x00000000      0x00000000      0x00000000
0xbffff500:     0x00000000      0x00000000      0x00000000      0x00000000
0xbffff510:     0x00000000      0x00000000      0x00000000      0x00000000
0xbffff520:     0x00000000      0x00000000      0x00000000      0x00000000
0xbffff530:     0x00000000      0x00000000      0x0023f804      0x058f52ff
0xbffff540:     0x0804823e      0xb7fec2d0      0x00000002      0x00245208
0xbffff550:     0x0804820c      0x00253934      0x00252fc0      0xbffff5ac
0xbffff560:     0xb7fec2a4      0xbffff5e0      0x0023fc0e      0x00000000
0xbffff570:     0x00000000      0x00000000


我输入了7个A,然后看到要覆盖的0x08048409,在低地址,而41在高地址,而且填充也只会往高处填充,于是,就算填充再多的A,覆盖的也是高地址,所以,我前面,无论输入多少A,都无法覆盖EIP。

原因是:局部变量先入栈,strcpy的返回地址,后入栈,而栈是向低地址增长的,所以不会覆盖EIP,但是其他人的博客里,怎么能覆盖呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值