1

シェルコードからHelloWorldを表示したいのですが、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!」を表示した後は終了しません。それどころか、無限ループのようにこの文を表示し続けます。

4

1 に答える 1

4

最初int 0x80に戻り値をで返すようですeax。その後、に設定しますが、には設定al1ませんeax

したがって、コードを次のように変更する必要があります。

mov eax,1
xor ebx,ebx
int 0x80
于 2013-03-06T11:01:22.677 に答える