본문 바로가기

Dream hack/LEVEL 1

Dreamhack (command-injection-1)

접근할 수 있는 경로는 ('/', '/ping') 의 두 가지이다.

 

/은 단순한 시작 페이지 이다.

/ping 의 코드를 보면 다음과 같다.

 

@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를 입력받고, /bin/sh를 이용하여 그쪽으로 ping을 보내는 함수이다.

그런데, host를 입력받고 서버에서는 아무런 검사를 하지 않는다!

 

그러면 host에 원하는 명령어를 입력해보자.

프론트에서 검사를 하는 모습을 볼 수 있다.

 

프론트에서 형식을 검사한다.

 

프론트에서 요청을 보내는 것은 개발자 도구로 아주 쉽게 우회할 수 있다.

input 블럭에 pattern이 걸려있는 모습을 볼 수 있다.

 

프론트에서 pattern 속성으로 검사한다.

 

pattern 속성자체를 지워버리고 exploit 코드를 입력해보자!

 

최종적인 exploit message 이다.

 

 

'Dream hack > LEVEL 1' 카테고리의 다른 글

Dreamhack (Carve Party)  (0) 2023.03.26
Dreamhack (csrf-2)  (0) 2023.03.24
Dreamhack (xss-2)  (0) 2023.03.24
Dreamhack (csrf-1)  (0) 2023.03.23
Dreamhack (devtools-sources)  (0) 2023.03.22