โ๏ธ Miscellaneous (Misc)/Dreamhack
[Dreamhack] baby-linux ๋๋ฆผํต ์๊ฒ์ ๋ฌธ์ ํ์ด
A Lim Han
2023. 11. 23. 12:54
๐คฑ baby-linux ๋๋ฆผํต ์๊ฒ์ ๋ฌธ์ ํ์ด
1. ๋ฌธ์ ์ค๋ช ํ์ธ ํ ์๋ฒ ์์ฑ

2. ์์ฑํ ์๋ฒ๋ก ์ ์ --> ls ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ฌ ํ์กดํ๋ ํ์ผ ๋ชฉ๋ก ์ถ๋ ฅ

3. cat ๋ช ๋ น์ด๋ฅผ ํตํด requirements.txt ํ์ผ ์คํ --> ๋ณ๋ค๋ฅธ ํํธ๋ฅผ ๋ฐ๊ฒฌํ์ง ๋ชปํจ

4. cat ๋ช ๋ น์ด๋ฅผ ํตํด hint.txt ํ์ผ ์คํ --> FLAG์ ๊ฒฝ๋ก ๋ฐ๊ฒฌ

5. ๋ค์ cat ๋ช ๋ น์ด๋ฅผ ์ด์ฉํด hello ํ์ผ์ ์ ๊ทผ ์๋ --> No! ๋ฌธ์์ด๊ณผ ํจ๊ป ์ ๊ทผ ๊ฑฐ๋ถ
echo $(cat ./dream/hack/hello/flag.txt)
6. app.py ํ์ผ์ ์ด์ด ์์ค์ฝ๋ ํ์ธ
7. app.py ์ฝ๋ ํ์ธ --> Line 13์์ 'flag' ์ฉ์ด ํํฐ๋ง ์์ ๋ฐ๊ฒฌ
#!/usr/bin/env python3
import subprocess
from flask import Flask, request, render_template
APP = Flask(__name__)
@APP.route('/', methods=['GET', 'POST'])
def index():
ใ
คใ
คif request.method == 'POST':
ใ
คใ
คใ
คใ
คuser_input = request.form.get('user_input')
ใ
คใ
คใ
คใ
คcmd = f'echo $({user_input})'
ใ
คใ
คใ
คใ
คif 'flag' in cmd:
ใ
คใ
คใ
คใ
คใ
คใ
คreturn render_template('index.html', result='No!')
ใ
คใ
คใ
คใ
คtry:
ใ
คใ
คใ
คใ
คใ
คใ
คoutput = subprocess.check_output(['/bin/sh', '-c', cmd], timeout=5)
ใ
คใ
คใ
คใ
คใ
คใ
คreturn render_template('index.html', result=output.decode('utf-8'))
ใ
คใ
คใ
คใ
คexcept subprocess.TimeoutExpired:
ใ
คใ
คใ
คใ
คใ
คใ
คreturn render_template('index.html', result='Timeout')
ใ
คใ
คใ
คใ
คexcept subprocess.CalledProcessError:
ใ
คใ
คใ
คใ
คใ
คใ
คreturn render_template('index.html', result='Error')
ใ
คใ
คreturn render_template('index.html')
if __name__ == '__main__':
ใ
คใ
คAPP.run(host='0.0.0.0', port=8000)
8. ํํฐ๋ง ์ฐํ๋ฅผ ์ํ ์ ๊ทํํ์ ์์ฑ
# ์ฌ์ฉ ๊ฐ๋ฅํ ์ ๊ท์
: cat ./dream/hack/hello/f*ag.txt
: cat ./dream/hack/hello/fl*g.txt
++ ์ ๊ทํํ์ ์์ฑ ๋ฐ ๊ฒํ ์ฌ์ดํธ
RegExr: Learn, Build, & Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).
regexr.com
9. ๋ค์ ๋ฌธ์ ๋ก ๋์์ ์์ฑํ ์ ๊ทํํ์ ์ ๋ ฅ --> FLAG ๋ฐ๊ฒฌ