在Linux(Fedora)上执行汇编shellcode hello.S's-proc -e'返回SIGSEGV
问题描述:
我写了一个简单的Linux汇编shellcode,它打印出“Hello,world!”标准输出。在Linux(Fedora)上执行汇编shellcode hello.S's-proc -e'返回SIGSEGV
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
jmp short string
code:
pop ecx
mov bl,1
mov al,13
mov al,4
int 0x80
dec bl
mov al,1
int 0x80
string:
call code
db 'hellow, world!'
程序名是hello.S
。现在,编译代码:
$ nasm -o hello hello.S
$ ./s-proc -p hello
/* The following shellcode is 47 bytes long: */
char shellcode[] =
"\x66\x31\xc0\x66\x31\xdb\x66\x31\xc9\x66\x31\xd2\xeb\x10\x66"
"\x59\xb3\x01\xb0\x0d\xb0\x04\xcd\x80\xfe\xcb\xb0\x01\xcd\x80"
"\xe8\xed\xff\x68\x65\x6c\x6c\x6f\x77\x2c\x20\x77\x6f\x72\x6c"
"\x64\x21";
$ ./s-proc -e hello
Calling code ...
Segmentation fault
$
该程序是正确的,但它会给出错误。
关于S-PROC:
S-PROC是用于执行的shellcode一个C程序。使用ld命令使得shellcode很大,因此我使用了s-proc。
答
包装代码只需使用malloc
得到的内存块和文件读入它。但是现在堆内存不可执行,因此你得到了段错误。您可以使用mprotect
来标记所需的页面可执行文件。如果您决定将shellcode放在堆栈上,则需要打开可执行堆栈(-z execstack
选项至gcc
)。
*该程序是正确的,但会给出错误。*其中一个陈述是** false **。 – 2014-09-06 17:27:34