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


前言

最近学习了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.程序界面如下:
在这里插入图片描述
2.这里面有用户名,密码和登录按钮。我预先设置了MySQL里面有几条数据,root/root,1/root…正常使用root/root登录没有问题,页面正常显示登录成功
在这里插入图片描述
3.使用错误的密码就登陆失败
在这里插入图片描述
4.尝试使用”万能密码“绕过:
在这里插入图片描述
5.直接绕过,登录成功
6.原理:将”万能密码“输入登录框以后,拼接的SQL语句为:

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

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


总结

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Qter_Sean

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值