https://www.exploit-db.com/exploits/34765
GNU Bash - 'Shellshock' Environment Variable Command Injection
GNU Bash - 'Shellshock' Environment Variable Command Injection Date: 2014-09-25
www.exploit-db.com
GNU Bash - 'Shellshock' Environment Variable Command Injection에 대해서 알아봅니다.
해당 취약점은 2014년 9월에 발견된 취약점으로, 당시에는 여파가 큰 취약점이었습니다.
위 사이트를 참고하여 실습을 진행했습니다.
Exploit Database Note:
The following is an excerpt from: https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/
Like “real” programming languages, Bash has functions, though in a somewhat limited implementation, and it is possible to put these bash functions into environment variables. This flaw is triggered when extra code is added to the end of these function definitions (inside the enivronment variable). Something like:
$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable
this is a test
The patch used to fix this flaw, ensures that no code is allowed after the end of a bash function. So if you run the above example with the patched version of bash, you should get an output similar to:
$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
this is a test
PoC 코드는 위와 같습니다.
그 중 핵심만 본다면 다음과 같습니다.
`$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"`
`vulnerable
this is a test`
- 첫 번째 코드가 본래 기능해야하는 것은 echo is a test가 출력되어야 하지만 vulnerable도 함께 출력됩니다.
- env x='() { :;}; echo vulnerable' 은 변수 x에 Shellshock를 악용하기 위한 코드를 담고 있습니다.
- ()는 Shellshock의 취약점을 악용하기 위한 함수입니다.
- :;는 빈 명령어로 추정됩니다.
- {}는 함수의 시작과 끝을 나타내며, echo vulnerable은 해당 함수가 실행될 때 출력할 문자열로 확인할 수 있습니다.
- bash -c "echo this is a test"는 위에서 생성한 변수 x를 사용하여 쉘 명령어 echo this is a test를 실행하게 됩니다.
실행 결과, "vulnerable"라는 문자열이 먼저 출력되고 그 다음에 "this is a test"가 출력됩니다. 이는 해당 시스템이 Shellshock 취약점을 가지고 있어서 위와 같은 코드가 실행될 수 있음을 나타냅니다.
환경 구성
CentOS 5.5
- Bash shellshock에 취약한 버전 중 하나인 bash-3.2-24.el5 를 사용하여 실습을 진행.

- bash 버전 확인

- echo this is a test만 출력되어야 하지만, vulnerable도 같이 출력되는 것이 확인되어진다.
- 공격자들이 흔히 사용하는 etc/passwd 를 응용하여 공격을 시도해볼 수 있다.

- 보이는 바와 같이 정보 획득이 가능하다.
결론
- 해당 취약점은 악성 스크립트를 삽입하여, 원격 코드 실행할 수 있는 취약점으로 볼 수 있다.
- 만일 웹 서버로 리눅스를 사용하며, 리눅스가 이러한 bash shellshock 취약점을 갖고 있는 버전이라면, http 메시지 안에 etc/passwd 를 인젝션해서 삽입하면 결과가 실행되어 위와 같은 정보를 획득할 수 있게 된다.
- → 정보를 획득 후에, 공격자의 권한을 상승시켜 원격으로 시스템 제어 및 해킹이 가능해진다.
- 2014년 9월 당시엔 인터넷 서버와 같은 리눅스/유닉스 시스템에서 심각한 보안 문제를 야기했다
대응 방안
- 현재 대부분의 리눅스 배포판에서 패치되어서 보안에 취약하지 않다.
- 그러나 아직 해당 취약점이 패치되지 않은 시스템이 있다면 여전히 위험할 수 있으며 최신 보안 패치를 적용하고 시스템을 최신으로 유지 및 업데이트하는 것이 중요하다.
- 현재 사용하고 있는 CentOS 5.5에서는 yum install -y bash 를 통해서 bash 버전을 업데이트하여 해당 취약점을 패치할 수 있다.
'CyberSecurity' 카테고리의 다른 글
| 악성 IP, 파일, URL 조회 사이트 (0) | 2023.05.14 |
|---|---|
| IoT란 무엇인가?, Shodan은 무엇인가? (2) | 2023.01.14 |