- 论坛徽章:
- 0
|
以下程序
- int main()
- {
- __asm__ __volatile__
- ("
- mov $0x0, %edx ;\
- push %edx ;\
- push $0x68732f6e ;\
- push $0x69622f2f ;\
- mov %esp, %ebx ;\
- push %ebx ;\
- mov %esp, %ecx ;\
- mov $0xb, %eax ;\
- int $0x80
- ");
- }
复制代码
在int0x80前断点,得到
- (gdb) display/i $eip
- 1: x/i $eip 0x804831e <main+42>: int $0x80
- (gdb) info reg eax ebx ecx edx
- eax 0xb 11
- ebx 0xbffff9c4 -1073743420
- ecx 0xbffff9c0 -1073743424
- edx 0x0 0
- (gdb) x/s $ebx
- 0xbffff9c4: "//bin/sh"
- (gdb) x/s *0xbffff9c0
- 0xbffff9c4: "//bin/sh"
复制代码
execve声明 int execve(const char *filename, char *const argv [], char *const envp[]);
eax 系统调用号:11
ebx filename: //bin/sh
ecx *argv[] : 只向0xbffff9c4(//bin/sh字符串的指针)
edx *envp[]: 0 没有环境变量
看上去都没有错,但是运行都没能启动shell
后来查书,发现
- int main()
- {
- __asm__ __volatile__
- ("
- mov $0x0, %edx ;\
- push %edx ;\
- push $0x68732f6e ;\
- push $0x69622f2f ;\
- mov %esp, %ebx ;\
- push %edx ;\
- push %ebx ;\
- mov %esp, %ecx ;\
- mov $0xb, %eax ;\
- int $0x80
- ");
- }
复制代码
竟然可以。
求教,为什么要把edx压栈。 根据/usr/include/asm/unistd.h 里面 _syscall3 的宏, 不是只把参数依次放进ebx, ecx, edx 就可以了?为什么栈会有影响
已解决。 只是因为argv数组也需要null结尾。 真是低级问题。 
[ 本帖最后由 viton_xuan 于 2007-1-24 13:48 编辑 ] |
|