【发布时间】:2018-02-26 05:42:57
【问题描述】:
我有一个 x64 处理器,我正在研究 shellcode。
我有以下代码:
section .text
global _start
_start:
push rax
mov rbx, 0x68732f6e69622f2f
shr rbx, 0x8
push rbx
mov rdi, rsp
;mov rdi, com
mov al, 59
syscall
用傻逼命令编译时:
nasm -g -f elf64 execve.asm
并与:
ld execve.o -o execve
运行良好。它打开一个外壳。如果我从中得到 shellcode:
"\x50\x48\xbb\x2f\x2f\x62\x69\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe7\xb0\x3b\x0f\x05"
并使用这个 C 程序:
int main(void)
{
const char shellcode[] = "\x50\x48\xbb\x2f\x2f\x62\x69\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe7\xb0\x3b\x0f\x05";
(*(void (*)()) shellcode)();
return 0;
} 编译它:
gcc -fno-stack-protector -z execstack -o ex2 ex.c
如果运行它会返回一个分段错误,但它应该执行一个 shell。为什么? 帮助表示赞赏!
【问题讨论】:
-
您是否检查过
shellcode数组及其内容实际上已放入代码段,使其可执行? -
我猜是因为内存没有执行权限。
-
感谢您的回复。我猜它有执行它的权限,因为它是用 gcc -fno-stack-protector -z execstack -o ex2 ex.c 编译的
-
@Ervin 尝试将
shellcode设为static const变量。 -
有什么理由用“//bin/sh”加载rbx然后右移,丢弃多余的前导'/'?
标签: c gcc assembly nasm shellcode