Web Hacking/DreamHack
[ DreamHack ] command-injection-1
호IT
2021. 3. 28. 06:28
- 문제 정보
특정 Host에 ping 패킷을 보내는 서비스입니다.
Command Injection을 통해 플래그를 획득하세요. 플래그는 flag.py에 있습니다.
#!/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)
페이지는 ping을 날릴수있는 page이다
즉 시스템명령어가 사용가능하다는것이다.
그럼 리눅스의 멀티커맨드 특성을 이용해 ping 과 다른 명령어 를 넣어 시스템 명령어를 입력할 수있다.
nevertrustbrutus.tistory.com/177?category=776190
하지만 아이피 형식을 제외하고 다른것을 추가로 넣을려면 패턴에 걸려 전송하지못한다.
가볍게 제거 후 시스템 명령어를 입력하면 된다.
123.123.123.123 "; cat flag.py"