해당 페이지의 원하는 주소를 넣는다면 Ping을 때리는 모습을 볼 수가 있다.

여기서 Command injection으로 flag파일을 열람하여 flag을 획득하는 문제다.

그렇다면 단순히 Command injection 구문을 삼입한다면 어떻게 될까?

형식에 맞게 입력하라며 입력이 불가능한 것을 확인할 수 있다.

개발자 도구를 열어보면

<input type="text" class="form-control" id="Host" placeholder="8.8.8.8" name="host" pattern="[A-Za-z0-9.]{5,20}" required="">

pattern="" 이 부분에서 형식에 맞게 출력 방식임을 알 수가 있다. 즉 HTML 소스코드를 편집하여 패턴을 없애면 Command injection 코드를 수행할 수 있을지도 모른다.

일단 코드를 봐보자.

@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')

일단 HTMl코드를 편집하고 요청을 보냈다.

더블쿼터에 씌여서 작통하지 않음을 확인할 수 있다. ( 위에 문제 소스코드 속 Host 부분을 보면 알 수 있다. )

이를 우회하기 위해

8.8.8.8";"ls

코드를 입력하여 요청을 해보자.