본문 바로가기

4-4. 2023-1 심화 스터디/오픈된 환경에서의 RCE(원격코드 실행) 취약점 분석 및 공격 시나리오

[2023.05.06] Text4Shell 취약점 분석

 

Prisma Cloud Analysis of CVE-2022-42889: Text4Shell Vulnerability

Mitigate critical vulnerability with CVSS rating of 9.8 recently discovered in Apache Commons Text, identified as CVE-2022-42889 and known as "Text4Shell"

www.paloaltonetworks.com

Paloalto Networks의 블로그를 참고했습니다 (__)

 

One of the main functions of the Apache Commons Text library is the evaluation and substitution of placeholders by their respective values, similar to what Bash does when executing a command like "echo ${HOME}", replacing the HOME variable with the corresponding value.

The StringSubstitutor class is responsible for substituting all variables within a given text. An application can be exposed to a variety of security risks when StringSubstitutor is used with default interpolators.

 

StringSubstitutor 클래스는 주어진 텍스트 내의 모든 변수를 대체하는 역할을 한다. StringSubstitutor가 기본 보간기와 함께 사용될 때 보안 위험에 노출될 수 있다.

 

StringSubstitutor interpolator = StringSubstitutor.createInterpolator();

 

StringSubstitutor.createInterpolator()는 interpolatorStringLookup을 사용하여 기본 보간기를 사용하는 새 인스턴스를 생성한다. 이렇게 되면 "${prefix}" 변수 내부에 default.properties에 포함된 속성키가 있다면 보간기가 문자열 조회를 수행할 수 있다. 취약한 버전의 Apache Commoms Text 버전에는 "script", "url" 및 "dns" 문자열 조회가 포함되어 있으며, 이것이 취약점을 야기한다.

 

Default Properties

 

이는 우리가 가장 처음 살펴본 T4S의 공격 방식에 포함된 키 3가지와 동일하며, PoC는 이들 중 scriptStringLookup()을 사용한다.

 

 

StringLookupFactory에 DEFAULT_RESOURCE에 defaults.properties가 포함되어 있고, DEFAULTS에선 loadProperties()를 포함한다.

 

 

addDefaultStringLookups 함수에서도 DEFAULTS를 사용하는데, 이는 처음 코드의 StringSubstitutor.createInterpolator()가 interpolatorStringLookup을 사용하는 것과 이어진다. InterpolatorStringLookup은 StringLookupFactory의 addDefaultStringLookups 함수를 사용한다.

 

기본 보간기를 사용하면 StringSubstitutor.replace() 또는 StringSubstitutor.replaceIn()에 악의적인 스크립트가 전달되어도 이를 실행시킬 수 있다. scriptStringLookup은 "script" 속성키를 통해 스크립트를 전달하게 되는데, 따라서 텍스트에 ${script} 변수를 지정하고 콜론 뒤에 "ScriptEngineName:Script" 키 값을 작성하면 된다.

이는 사용자의 입력을 신뢰해 텍스트를 명령어처럼 실행한다는 부분에서 Log4Shell 취약점과 유사하다. 그러나 Rapid7의 보고서에 따르면, 신뢰할 수 없고 잠재적으로 악의적인 입력을 처리하기 위해 취약한 Commons Text의 구성 요소를 사용하는 경우는 드물기 때문에 우려할 만한 파급력은 아닐 것으로 전망된다.