首页 > 其他分享 >Nullcon Berlin HackIM 2023 CTF - WEB,wp

Nullcon Berlin HackIM 2023 CTF - WEB,wp

时间:2023-03-13 21:22:36浏览次数:34  
标签:__ WEB cookies import app write CTF wp output

题目:reguest

先来看下代码

app.py

from flask import Flask, Response, request
import requests
import io

app = Flask(__name__)


@app.route('/')
def index():
    s = requests.Session()
    cookies = {'role': 'guest'}

    output = io.StringIO()
    output.write("Usage: Look at the code ;-)\n\n")
    try:
        output.write("Overwriting cookies with default value! This must be secure!\n")
        cookies = {**dict(request.cookies), **cookies}
        headers = {**dict(request.headers)}

        if cookies['role'] != 'guest':
            raise Exception("Illegal access!")

        r = requests.Request("GET", "http://backend:8080/whoami", cookies=cookies, headers=headers)
        prep = r.prepare()

        output.write("Prepared request cookies are: ")
        output.write(str(prep._cookies.items()))
        output.write("\n")
        output.write("Sending request...")
        output.write("\n")
        
        resp = s.send(prep, timeout=2.0)
        
        output.write("Request cookies are: ")
        output.write(str(resp.request._cookies.items()))
        output.write("\n\n")
        if 'Admin' in resp.content.decode():
            output.write("Someone's drunk oO\n\n")
        output.write("Response is: ")
        output.write(resp.content.decode())
        output.write("\n\n")
    except Exception as e:
        print(e)
        output.write("Error :-/" + str(e))
        output.write("\n\n")

    return Response(output.getvalue(), mimetype='text/plain')


if __name__ == "__main__":
    app.run(host='0.0.0.0', port='8080', debug=False)

 

 back.py

import os
from flask import Flask, request, Response

app = Flask(__name__)


@app.route('/whoami')
def whoami():
    role = request.cookies.get('role','guest')
    really = request.cookies.get('really', 'no')
    if role == 'admin':
        if really == 'yes':
            resp = 'Admin: ' + os.environ['FLAG']
        else:
            resp = 'Guest: Nope'
    else:
        resp = 'Guest: Nope'
    return Response(resp, mimetype='text/plain')

if __name__ == "__main__":
    app.run(host='0.0.0.0', port='8080', debug=False)

 

 

一个简单的python代码审计题,就按照他的方式传2个cookie就可以获取flag了

if role == 'admin':

if really == 'yes':

resp = 'Admin: ' + os.environ['FLAG']

 

一个cookie是 role :adimn

另一个是 really :yes

上传上去就能给flag

题目:web zpr

这是一个Nullcon Berlin HackIM 2023 CTF的题目

 

 

先来看给的app.py代码文件

from flask import Flask, Response, request
from werkzeug.utils import secure_filename
from subprocess import check_output
import io
import hashlib
import secrets
import zipfile
import os
import random
import glob

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 1.5 * 1000 # 1kb

@app.route('/', methods=['GET'])
def index():
    output = io.StringIO()
    output.write("Send me your zipfile as a POST request and I'll make them accessible
  to you ;-0.")

    return Response(output.getvalue(), mimetype='text/plain')


@app.route('/', methods=['POST'])
def upload():
    output = io.StringIO() 
# 创建一个StingIO对象,寄存在缓冲区,可选参数buf
# 是一个str或unicode类型,它将会与后续写的数据存放一起。
    if 'file' not in request.files:
        output.write("No file provided!\n")
        return Response(output.getvalue(), mimetype='text/plain')

    try:
        file = request.files['file']

        filename = hashlib.md5(secrets.token_hex(8).encode()).hexdigest()
        dirname = hashlib.md5(filename.encode()).hexdigest()

        dpath = os.path.join("/tmp/data", dirname)
        fpath = os.path.join(dpath, filename + ".zip")

        os.mkdir(dpath)
        file.save(fpath)


        with zipfile.ZipFile(fpath) as zipf: #用于读写 ZIP 文件的类。
            files = zipf.infolist()
            if len(files) > 5:
                raise Exception("Too many files!")

            total_size = 0
            for the_file in files:
                if the_file.file_size > 50:
                    raise Exception("File too big.")

                total_size += the_file.file_size

            if total_size > 250:
                raise Exception("Files too big in total")

        check_output(['unzip', '-q', fpath, '-d', dpath])


        g = glob.glob(dpath + "/*")
        for f in g:
            output.write("Found a file: " + f + "\n")

        output.write("Find your files at http://...:8088/" + dirname + "/\n")


    except Exception as e:
        output.write("Error :-/\n")

    return Response(output.getvalue(), mimetype='text/plain')



if __name__ == "__main__":
    app.run(host='0.0.0.0', port='8080', debug=True)

 

看上面的代码大概意思是你可以上传一个文件但是文件的大小被限制了

然后还会读取你这个zip文件最后还会返回一个链接给你

 

 

 

这里告诉我们上传一个zip文件给它,

这里直接使用软链接

软链接:这个其实就相当于Windows的快捷方式,当你使用这个快捷方式的时候他会指向这个快捷方式保存的内存地址,比如说你一个游戏的快捷方式, 你这个游戏很大肯定不能直接放在桌面上吧,然后就会创建一个快捷方式当你点击这个快捷方式的时候里面就存放了这个游戏运行文件的实际地址,然后就可以玩游戏啦

 

然后用kali创建一个软链接,然后压缩

 

 

然后再通过写一个强上传脚本给写上传上去

 

 

 

 

然后这里给了我们上传的软链接位置,然后直接在10016端口访问这个软链接就可以把我们直接代到flag所在的目录了,这里就拿到flag了

 

 

 

 

 

标签:__,WEB,cookies,import,app,write,CTF,wp,output
From: https://www.cnblogs.com/xxpanda/p/17212918.html

相关文章

  • 百度地图web服务API
    一、获取AK官网地址:https://api.map.baidu.com/lbsapi/cloud/index.htm点击地图API产品,选择web服务API该套API免费对外开放,使用前请先申请密钥(key)点击创建应用提......
  • [BUUCTF]Reverse-[BJDCTF2020]JustRE
      进去之后直接看字符串窗口,发现一个疑似flag的,点进去查看    我的妈耶!良心啊,直接把flag给我们了,呜呜呜呜,真的好少见这种淳朴的出题人!!!BJD{1999902069a4579......
  • WPF 日历控件 样式
    一、WPF日历控件基本样式通过Blend获取到Calendar需要设置的三个样式CalendarStyle、CalendarButtonStyle、CalendarDayButtonStyle、CalendarItemStyle。然后通过设置样......
  • 3.datax-web搭建
    1.路径mkdir/home/datax-webcd/home/datax-web 2.下载https://github.com/WeiYe-Jing/datax-web 3.解压tar-zxvfdatax-web-2.1.2.tar.gzmvdatax-web-2.1.2......
  • .net使用websocket
    客户端:<headrunat="server"><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title></title><scriptsrc="Scripts/jquery-3.......
  • javaweb审计/函数
    statement.executeQuery(sql);lombok模块可以自动生成setter/getter/tostring等方法SQL注入可以首先找到所有包含sql语句的点,随后观察传参类型是否是sring类型,只有当......
  • web自动化-下拉框
    一、select下拉框基础知识:""""一、下拉列表分类"1、select下拉列表https://www.w3school.com.cn/tiy/t.asp?f=eg_html_elements_selectSelect类fromselenium.webd......
  • 网络安全(中职组)-B模块:Web隐藏信息获取
    Web隐藏信息获取任务环境说明:服务器场景名:web20200604服务器场景用户名:未知(关闭链接)1.   通过本地PC中渗透测试平台Kali使用Nmap扫描目标靶机HTTP服务子目录,将扫描子......
  • webpack、vite、vue-cli、create-vue 的区别
    首先说结论Rollup更适合打包库,webpack更适合打包项目应用,vite基于rollup实现了热更新也适合打包项目。功能工具工具脚手架vue-clicreate-vue构建项目 vit......
  • 总算跑通了webserver
    前言最近因为到了找工作季,我之前那篇春招的博客阅读量也上去了。于是也就有个热心的网友,认真的帮我看了我的WebSever项目。发现跑不起来,为了答谢他好好看了我的博客并帮我......