该
execve系统调用 时 被调用,但你确实传递错误参数。
(您可以通过使用运行可执行文件来查看此内容
strace。)
存在三个问题:
.ascii
不以0结尾的字符串。(您可能会很幸运,因为.data
在此示例中的本节中没有任何内容,但是不能保证…)添加0或使用.asciz
(或.string
)代替。movl file_to_run, %edi
移动的值 指向 由所述file_to_run
符号到%edi
,即,第一个4个字节的字符串(0x6e69622f
)。字符串的 地址 只是符号本身的值,因此您需要对$
字面值使用前缀:movl $file_to_run, %edi
。同样,您需要说movl $file_to_run, %ebx
几行。(这是AT&T语法和Intel语法之间常见的混淆源!)参数以错误的顺序放在堆栈上:
-0x8(%ebp)
比的地址低-0x4(%ebp)
。因此,应该将命令字符串的地址写入-0x8(%ebp)
,将0写入-0x4(%ebp)
,将leal
指令写入leal -8(%ebp), %ecx
。
固定代码:
.section .datafile_to_run:.asciz "/bin/sh".section .text.globl mainmain: pushl %ebp movl %esp, %ebp subl $0x8, %esp # array of two pointers. array[0] = file_to_run array[1] = 0 movl $file_to_run, %edi movl %edi, -0x8(%ebp) movl $0, -0x4(%ebp) movl $11, %eax# sys_execve movl $file_to_run, %ebx # file to executeleal -8(%ebp), %ecx # command line parameters movl $0, %edx # environment block int $0x80 leave ret



