-
Level 1
- Baby-Linux
#!/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)
- echo $() <- input 태그에 입력값이 들어오고 그 입력값으로 /bin/sh 의 경로에 있는 배시셀이 작동됨
- 만약에 입력된 값에서 “flag” 라는 값이 들어있으면 result에 No!라는 값으로 대치됨.
- 문제에서 “flag.txt” 라는 파일명이 제시되어있기 때문에 find 명령을 통해 txt 확장자의 파일들을 찾아주었음.
- flag.txt는 /dream/hack/hello 경로에 위치한것을 확인
- flag 라는 단어는 검증식이 있기때문에 사용하지 못함
- cat 명령어를 이용하여 flag.txt의 파일 내부를 살펴봄
- cat dream/hack/hello/* - 해당 경로의 모든 파일의 내용을 봄
- cat dream/hack/hello/*.txt - 해당 경로의 txt파일들의 내용을 봄
- cat dream/hack/hello/fl* - “fl”로 시작하는 파일의 내용을 봄
결과값
-
Level 1
- Baby-Linux
#!/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)
- echo $() <- input 태그에 입력값이 들어오고 그 입력값으로 /bin/sh 의 경로에 있는 배시셀이 작동됨
- 만약에 입력된 값에서 “flag” 라는 값이 들어있으면 result에 No!라는 값으로 대치됨.
- 문제에서 “flag.txt” 라는 파일명이 제시되어있기 때문에 find 명령을 통해 txt 확장자의 파일들을 찾아주었음.
- flag.txt는 /dream/hack/hello 경로에 위치한것을 확인
- flag 라는 단어는 검증식이 있기때문에 사용하지 못함
- cat 명령어를 이용하여 flag.txt의 파일 내부를 살펴봄
- cat dream/hack/hello/* - 해당 경로의 모든 파일의 내용을 봄
- cat dream/hack/hello/*.txt - 해당 경로의 txt파일들의 내용을 봄
- cat dream/hack/hello/fl* - “fl”로 시작하는 파일의 내용을 봄
결과값