C++/Qt下登录程序的绕过

文章目录

  • 前言
  • 一、SQL注入是什么
  • 二、靶场搭建
    • 1.环境:Qt5 mysql
    • 2.尝试绕过
  • 总结


前言

最近学习了SQL注入内容,想着SQL注入应该不仅仅出现在web端,对于工控行业开发的程序,是不是也存在呢?于是自己用Qt/C++写一个登陆的程序,来验证一下试试看。


一、SQL注入是什么

所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令。在某些表单中,用户输入的内容直接用来构造(或者影响)动态SQL命令,或作为存储过程的输入参数,这类表单特别容易受到SQL注入式攻击。(两点:1.用户有输入;2.用户的输入被当作代码执行),对于Qt来说,登录的界面就相当于web的表单

二、靶场搭建

1.环境:Qt5 mysql

Qt中登陆的界面的代码如下:

    //验证用户的账号密码登录情况
    QString strsql = QString("select * from myuser where username = '%1' and password = '%2'").arg(username).arg(pwd);
    sql->query.exec(strsql);
    bool flag = sql->query.next();
    if (flag) {
        QMessageBox::warning(this,"欢迎","登录成功");
    } else {
         QMessageBox::warning(this,"错误","密码错误");
}

看上去这一点毛病都没有,在看看Qt官方文档对"next"函数的解读:

bool QSqlQuery::next()
Retrieves the next record in the result, if available, and positions the query on the retrieved record. Note that the result must be in the active state and isSelect() must return true before calling this function or it will do nothing and return false.
The following rules apply:
If the result is currently located before the first record, e.g. immediately after a query is executed, an attempt is made to retrieve the first record.
If the result is currently located after the last record, there is no change and false is returned.
If the result is located somewhere in the middle, an attempt is made to retrieve the next record.
If the record could not be retrieved, the result is positioned after the last record and false is returned. If the record is successfully retrieved, true is returned.
See also previous(), first(), last(), seek(), at(), isActive(), and isValid().

意思大概就是取一条数据出来

2.尝试绕过

1.程序界面如下:
C++/Qt下登录程序的绕过_第1张图片
2.这里面有用户名,密码和登录按钮。我预先设置了MySQL里面有几条数据,root/root,1/root…正常使用root/root登录没有问题,页面正常显示登录成功
C++/Qt下登录程序的绕过_第2张图片
3.使用错误的密码就登陆失败
C++/Qt下登录程序的绕过_第3张图片
4.尝试使用”万能密码“绕过:
C++/Qt下登录程序的绕过_第4张图片
5.直接绕过,登录成功
6.原理:将”万能密码“输入登录框以后,拼接的SQL语句为:

select * from myuser where username = '1' or 1=1 #' and password = ''

闭合原有的语句,注释后面的语句,而"or 1=1"恒成立,故以此绕过了登录


总结

SQL注入无处不在,只要在利用表单输入的内容构造SQL命令之前,把所有输入内容过滤一番就可以了(不要相信用户的任何输入)。

你可能感兴趣的:(渗透测试,QT,mysql,c++,渗透测试)