Without a Break

[Dreamhack] command-injection-1 본문

Web/Wargame

[Dreamhack] command-injection-1

와븨 2022. 10. 5. 16:47

 

[문제 파일]

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')
  • ping 페이지에서 입력하는 값이 host 변수에 저장됨
  • 'ping -c 3' 명령어에 입력한 값인 host가 붙여져서 실행됨
  • /bin/sh 형태를 보아 리눅스를 사용하고 있음을 알 수 있음

 


[풀이]

 

개발자 도구의 Element에서 html 코드를 살펴보면

pattern 변수를 통해 입력창에 어떤 식으로 입력해야 하는지 형식이 나와있다.

"명령어" 형식으로 큰따옴표를 붙여서 명령어를 입력해야 함을 알 수 있다.

 

입력창에 리눅스 명령어를 입력해 공격해야하므로 개발자도구에서 pattern 변수와 pattern 변수의 값을 지워준다.

 

플래그는 flag.py 파일에 있다고 했으므로 flag.py 파일을 불러와야 한다.

파일을 불러오는 리눅스 명령어인 cat과 multi command인 세미콜론(;)을 사용하여 입력창에 명령어를 입력해준다.

  • 8.8.8.8 호스트의 flag.py 파일을 출력해라

명령어를 입력 후 ping! 버튼을 누르면

flag.py 파일의 내용이 출력되어 플래그를 찾을 수 있다.

 

답 : DH{pingpingppppppppping!!}

 

'Web > Wargame' 카테고리의 다른 글

[Dreamhack] pathtraversal  (0) 2022.10.05
[Dreamhack] carve party  (0) 2022.10.05
[Dreamhack] Mango  (0) 2022.10.01
[Dreamhack] simple_sqli  (0) 2022.09.24
[Dreamhack] SQL Injection  (0) 2022.09.24