
오.. 챗지피티를 이용해서 대놓고 풀라는 문제는 처음이라 처음부터 되게 흥미로웠다
문제 파일 속 코드 먼저 분석해보면 사실 이 부분만 봐도 된다고 생각한다.
@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')
즉,
사용자가 웹 폼에 host 값 입력한다.
서버가 cmd= "ping -c 3" + host로 문자열을 만든다.
그 문자열을 /bin/sh -c <cmd>로 쉘에 던진다.
쉘이 그 문자열을 "쉘 명령어"로 해석해서 실행한다.
그래서 가장 먼저 8.8.8.8; ls를 통해 어떤 파일들이 있는지 확인하였다.

문제에서 설명해준 것처럼 flag.py를 확인할 수 있다.
그러면 간단하게 8.8.8.8; cat flag.py를 통해 flag를 확인할 수 있다.
