#!/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)
cmd = f'ping -c 3 {host}'
host를 입력받아 ping을 보내는 cmd 가 있다.
실험해 보자.
정상 작동되는 걸 볼 수 있다.
그러면 AND 연산을 같이 넣어주면 명령어가 실행이 되는지 확인해 보자.
리눅스에서 AND 연산자는 && 를 의미하고 핑을 성공적으로 실행된 경우에 뒤의 명령어인 'ls'가 실행한다.
결과를 보면...
바로 나온다.
flag를 보면...
잘 나온다.
'DreamHack > WEB' 카테고리의 다른 글
sql injection bypass WAF (0) | 2024.10.29 |
---|---|
blind sql injection advanced (0) | 2024.10.23 |
error based sql injection (0) | 2024.10.18 |
simple_sqli_chatgpt (0) | 2024.10.17 |
php-1 (1) | 2024.10.16 |