我想从 shellcode 中显示一个 hello world,c 代码很简单:
#include <stdio.h>
char shellcode[] = "\xeb\x17\x59\x31\xc0\xb0\x04\x31\xdb\x43\x31\xd2\xb2\x0f\xcd\x80\xb0\x01\xbb\x00\x00\x00\x00\xcd\x80\xe8\xe4\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x73\x68\x65\x6c\x6c\x21\x0a\x0d";
int main(int argc, char **argv){
int (*func)();
func = (int (*)()) shellcode;
(int)(*func)();
return 0;
}
问题应该在汇编文件中,这里是:
BITS 32
jmp short one
;write hello world on standard output
two:
pop ecx ;i get string address
xor eax,eax
mov al,4
xor ebx,ebx
inc bl ;bl should be 1
xor edx,edx
mov dl,15
int 0x80
;exit with status 0
mov al,1
xor ebx,ebx
int 0x80
one:
call two
db "Hello shell!",0x0a,0x0d
代码运行良好,但在显示“hello shell!”后不退出,相反它一直显示这句话,就像在无限循环中一样。