Copy code #include "stdio。h" /*利用函数*/ exploitfunction() { /*如果缓冲区溢出被成功利用,就会输出此行内容*/ printf("This line will be printed after successfully exploiting the buffer overflow. "); system("pause"); ExitProcess(0); }
main(int argc, char *argv[]) { if(argc>1) { normalfunction(argv[1]); printf(" These lines get printed during normal execution with at least 1 commandline argument.The address of exploitfunction is 0x%。8X ",exploitfunction); } else printf("Please provide the program with at least 1 commandline argument. "); ExitProcess(0); }
这段程序所做的就是复制字符串"vulnerable_program AAAAAAAAAAAAAAAAAAAAAAAAAAAA"到一个缓冲区中,并用新的返回地址创建另一个缓冲区,附加在工作缓冲区之上。 在那之后,程序调用system()来执行字符串中的命令。输出结果是: C:>exploit.exe This line will be printed after successfully exploiting the buffer overflow. Press any key to continue……
太棒了,它执行了!
难道那不伟大吗?
虽然我们实际上并没有成功让程序运行我们自己的代码,但经过一些小小的改变就能完成。 关于缓冲区溢出的更多相关信息请参考Aleph One写的著名文章"Smashing the stack for fun and profit"