
在缓冲区溢出的攻击中,本来已经调试好的漏洞利用程序,由于动态链接库的装入和卸载等原因,
windows进程的函数栈帧很可能产生“移位”,因此:利用成片数据简单地把返回地址覆盖成一个定值的做法往往不能让exploit奏效,
为了不至于10次中只有2次才能成功运行shellcode,我们通常使用“跳板”技术来完善这段shellcode,
常用“跳板”有:jmp eax;机器码为(16制)FF E0,jmp esp;机器码为(16制)FF E4,call esp;机器码为(16制)FF D4等等,
下面以USER32.DLL中的一个“jmp esp”为例,搜索内存中的跳板,实现代码如下:
#include <windows.h>
#include <stdio.h>
#define DLL_NAME "user32.dll" //此处可改为内存中其它的动态链接库
main()
{
BYTE* ptr;
int position,address;
HINSTANCE handle;
BOOL done_flag = FALSE;
handle=LoadLibrary(DLL_NAME);
if(!handle)
{
printf(" load dll erro !");
exit(0);
}
ptr = (BYTE*)handle;
for(position = 0; !done_flag; position++)
{
try
{
if(ptr[position] == 0xFF && ptr[position+1] == 0xE4)
{
//0xFFE4是JMP ESP的机器码,可改为其它的跳板
int address = (int)ptr + position;
printf("OPCODE found at 0x%x\n",address);
}
}
catch(...)
{
int address = (int)ptr + position;
printf("END OF 0x%x\n", address);
done_flag = true;
}
}
}