可视化展示
string sql = "select id from t_user where user='";
sql += username;
sql += "' and password =md5('";
sql += password;
sql += "')";
cout << sql << endl;
select id from t_user where user='fdd' and password =md5('990107Wjl@')
select md5(1);
select id from t_user where user = '1'or '1'='1' and password = md5('1') or'c4ca4238a0b923820dcc509a6f75849b'=md5('1');
?在Linux下,也攻击成功了,十分危险
input password : ***********************************************select id from t_user where user = '1' or '1' = '1' and password = md5('1') or 'c4ca4238a0b923820dcc509a6f75849b' = md5('1')
? ? ? ? ? ? login success!
select id from t_user where user = '1'or '1'='1' and password = md5('1') or'c4ca4238a0b923820dcc509a6f75849b'=md5('1');
?username=1'or'1'='1
?password= 1') or'c4ca4238a0b923820dcc509a6f75849b'=md5('1
//用于检查用户的输入 false不安全。 true表示安全
bool XClient::CheckInput(const std::string& in)
{
//限定不允许出现的字符
string str = "'\"()";
for (char a : str)
{
//size_t 类型表示C中任何对象所能达到的最大长度,它是无符号整数。
size_t found = in.find(a);
//输入字符in是否可以在a中被找到
//如果字符串不存在包含关系,那么返回值就一定是npos
if (found != string::npos)//发现违规字符
{
return false;
}
}
return true;
}
if (!CheckInput(password) || !CheckInput(username))
{
//输入是危险的
cerr << "Injection attacks!!!! Inout password or username dangerous!!" << endl;
continue;
}
直接输出注入攻击错误
input username:1'or'1'='1
input password:***********************************************Injection attacks!!!! Inout password or username dangerous!!
完结花花