【发布时间】:2018-11-09 09:52:22
【问题描述】:
在缓冲区溢出分配中,我得到了一个 C 文件 (call_shellcode.c),其中包含以下 C 代码的汇编版本,该代码执行以打开一个 shell:
#include <stdio.h>
#include <unistd.h>
int main(){
char *name[2];
name[0] = "/bin/sh";
name[1] = NULL;
execve(name[0], name, NULL);
}
文件call_shellcode.c中的代码是:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
const char code[] =
"\x31\xc0" /* xorl %eax,%eax */
"\x50" /* pushl %eax */
"\x68""//sh" /* pushl $0x68732f2f */
"\x68""/bin" /* pushl $0x6e69622f */
"\x89\xe3" /* movl %esp,%ebx */
"\x50" /* pushl %eax */
"\x53" /* pushl %ebx */
"\x89\xe1" /* movl %esp,%ecx */
"\x99" /* cdql */
"\xb0\x0b" /* movb $0x0b,%al */
"\xcd\x80" /* int $0x80 */
;
int main(int argc, char **argv)
{
char buf[sizeof(code)];
strcpy(buf, code);
((void(*)( ))buf)( );
}
我已经通过命令编译了:
gcc -fno-stack-protector -z execstack -o call_shellcode call_shellcode.c
当我执行它时,它显示分段错误。哪里出错了?
【问题讨论】:
标签: assembly buffer-overflow shellcode stack-smash