Unanticipated segmentation fault in C

喜夏-厌秋 提交于 2019-12-08 04:14:24

问题


I'm writing a Linux shell code exploit. My target C code is:

 char code[] = "\xb0\x01\x31\xdb\xcd\x80";
 int main(int argc, char **argv)
 {
      int(*func)();
      func = (int (*)()) code;

      (Int)(*func)();
 }

Why does compiling and running this C program raise a segmentation fault error? The string is shell code that exits the program using the system call Int 0x80/EAX=1. The original exploit code in assembly is:

b0 01                   mov    al,0x1
31 db                   xor    ebx,ebx
cd 80                   int    0x80

回答1:


You are not setting eax=0x1, you are setting al=0x1, so if you don't know what instructions are executed before that your shellcode, you will have eax=xxxxxx01.

As the comments said you, you have to do a xor eax, eax on the beginning of your shellcode.



来源:https://stackoverflow.com/questions/48847149/unanticipated-segmentation-fault-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!