728x90
👾 문제 설명
특정 Host에 ping 패킷을 보내는 서비스입니다.
Command Injection을 통해 플래그를 획득하세요. 플래그는 flag.py에 있습니다.
chatGPT와 함께 풀어보세요!
📎 https://dreamhack.io/wargame/challenges/768
command-injection-chatgpt
특정 Host에 ping 패킷을 보내는 서비스입니다. Command Injection을 통해 플래그를 획득하세요. 플래그는 flag.py에 있습니다. chatGPT와 함께 풀어보세요! Reference Webhacking Roadmap
dreamhack.io
접속 정보에 "서버 생성하기"를 눌러서 링크에 접속한다.
이런 페이지가 등장한다.
8.8.8.8을 입력해 ping test를 수행했더니 실제 ping 명령과 동일한 기능을 수행하는 것을 확인할 수 있다.
문제 파일을 다운로드 한다.
🍉 app.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)
Command Injection을 이용한 문제이다.
/ping 페이지에
- GET Method로 접속한 경우 : 핑을 보낼 수 있는 템플릿을 리턴
- POST Method로 접속한 경우 : host 파라미터를 받아와 host라는 변수에 지정하고, ping -c 3 {host} 명령어를 통해 입력한 값을 {host}에 대입함으로써 핑을 보냄
참고 링크 : https://velog.io/@dhlife09/dreamhack-wargame-768
[Dreamhack] command-injection-chatgpt
특정 Host에 ping 패킷을 보내는 서비스입니다. Command Injection을 통해 플래그를 획득하세요.
velog.io
- 보통 command injection을 하기 위해서는 &&, ||, ; 등 여러 기호를 사용
- 이는 모두 명령어를 한 줄에 연속 실행하기 위한 기호
- && 기호는 앞의 명령어가 성공하면 뒤에 있는 명령어도 실행
- || 기호는 앞의 명령어가 오류가 발생하면 뒤의 명령어가 실행
- ; 기호는 성공실패여부를 가리지 않고 무조건 실행
먼저 cmd에 해당 기능을 이용하여' | ls ' 값을 입력하게 되면 아래와 같이 파일 목록을 확인할 수 있다.
8.8.8.8|ls
flag.py 를 cat으로 내용을 확인하자.
chatgpt를 이용하지 않았지만... 풀이 성공!
728x90
'공부 > 웹해킹 (Web hacking)' 카테고리의 다른 글
[Webhacking.kr | 웹해킹] g00gle1 (0) | 2024.05.09 |
---|---|
[드림핵 | 웹해킹] LEVEL 1: php-1 (1) | 2024.05.02 |
[Webhacking.kr | 웹해킹] old-20 (0) | 2024.04.30 |
[Webhacking.kr | 웹해킹] old-19 (0) | 2024.04.04 |
[Webhacking.kr | 웹해킹] old-18 (0) | 2024.03.28 |