Web Hacking/SWLUG 내부 CTF

[SWLUG] FILE Download1- write up

hanbunny 2025. 4. 14. 11:44

🐰시작!

파일을 다운로드 받을 수 있는 창이뜨고 시작한다.

from flask import Flask, request, send_file, render_template_string, abort
import os

app = Flask(__name__)

# 파일이 저장된 디렉토리
FILE_DIR = '/usr/src/app/upload'

@app.route('/')
def index():
    try:
        files = os.listdir(FILE_DIR)
        file_links = [f'<li><a href="/download?filename={file}">{file}</a></li>' for file in files]
        file_list_html = '<ul>' + '\n'.join(file_links) + '</ul>'
        return render_template_string('''
        <h1>FILE Download1</h1>
        {{ file_list_html|safe }}
        ''', file_list_html=file_list_html)
    except Exception as e:
        return str(e), 500

@app.route('/download')
def download():
    filename = request.args.get('filename', '')
    file_path = os.path.join(FILE_DIR, filename)
    if os.path.exists(file_path):
        try:
            return send_file(file_path, as_attachment=True)
        except Exception as e:
            return str(e), 500
    else:
        return abort(404)

if __name__ == '__main__':
    app.run(host='0.0.0.0')

filename = request.args.get('filename', '') 이 부분을 보면 URL 쿼리 파라미터에서 filename값을 가져온다.

그래서 먼저 FLAG.txt 파일을 넣어 다운로드를 시도해봤다.

Not Found가 뜨는 걸 보니 다른 경로에 있는 것 같음.

그래서 상위폴더에서 찾아봤음.

FLAG값이 들은 파일이 다운로드 된다.

'Web Hacking > SWLUG 내부 CTF' 카테고리의 다른 글

[SWLUG] CMDi2- write up  (0) 2025.04.14
[SWLUG] CMDi1- write up  (0) 2025.04.14
[SWLUG] URL1 - write up  (0) 2025.04.14
[SWLUG] Sqli7 - write up  (0) 2025.04.14
[SWLUG] Sqli5 - write up  (0) 2025.04.14