【问题标题】:infinite loop in shellcodeshellcode中的无限循环
【发布时间】:2013-03-06 10:54:49
【问题描述】:

我想用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!”后不退出,反而像死循环一样一直显示这句话。

【问题讨论】:

  • 我不是int 0x80 的专家,但你确定第一个系统调用不会破坏eax 的前24 位(第二个系统调用必须为零)?跨度>

标签: c assembly x86 system-calls shellcode


【解决方案1】:

似乎第一个int 0x80返回eax中的返回值。之后将al 设置为1,但不是eax

所以你应该把你的代码改成:

mov eax,1
xor ebx,ebx
int 0x80

【讨论】:

  • 您的 .asm 文件显示为 xor ebx, ebx,但您的 C 文件显示为 mov ebx, 0。只是说...
  • mov eax,1 不是好的 shellcode(因为不是 mov ebx,0),因为 (32bit-) 常量中嵌入了零。 xor reg,reg 后跟 inc regadd/mov 到 8 位 reg 将不会在操作码上包含零。
猜你喜欢
  • 2012-12-24
  • 1970-01-01
  • 2013-02-22
  • 2011-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-25
  • 1970-01-01
相关资源
最近更新 更多