因为在scanf函数读入数据时,如果输入的数据过长,会覆盖掉栈里面其他变量的内容。达到溢出利用。
本程序只是掩饰如何覆盖其密码,达到越过验证!
在本程序中第一次输入 1111111122222
第2次输入22222就可以通过验证 具体可以下断点查看内存数据的变化
#include "stdafx.h"
#include <string.h>
int main(int argc, char* argv[])
{
//正确密码存放处
char szPassword[] = "Hello";
char szBuffer[8];
int i = 0;
while(i++ < 3)
{
fflush(stdin);
scanf("%s", szBuffer);
int a= strcmp(szPassword, szBuffer);
if (0==a)
{
printf("Login.../r/n");
}
else
{
printf("Error!/n");
}
}
return 0;
}