mainのリターンアドレスを上書きして、exit(0)呼び出しのこの単純なオペコードを実行しようとしています。問題は、セグメンテーション違反が発生していることです。
#include <stdio.h>
char shellcode[]= "/0xbb/0x14/0x00/0x00/0x00"
"/0xb8/0x01/0x00/0x00/0x00"
"/0xcd/0x80";
void main()
{
int *ret;
ret = (int *)&ret + 2; // +2 to get to the return address on the stack
(*ret) = (int)shellcode;
}
実行結果はセグメンテーションエラーになります。
[user1@fedo BOF]$ gcc -o ExitShellCode ExitShellCode.c
[user1@fedo BOF]$ ./ExitShellCode
Segmentation fault (core dumped)
これはshellcode.aのObjdumpです。
[user1@fedo BOF]$ objdump -d exitShellcodeaAss
exitShellcodeaAss: file format elf32-i386
Disassembly of section .text:
08048054 <_start>:
8048054: bb 14 00 00 00 mov $0x14,%ebx
8048059: b8 01 00 00 00 mov $0x1,%eax
804805e: cd 80 int $0x80
私が使用しているシステム
fedora Linux 3.1.2-1.fc16.i686
ASLR is disabled.
Debugging with GDB.
gcc version 4.6.2