A Chinese cyberespionage group hacked Barracuda Email Security Gateway (ESG) appliances through a zero-day vulnerability until May. They have now rushed to deploy new malware implants on victims' devices once the attack was discovered and remediation efforts started. The group is tracked as UNC4841, and based on its target selection and espionage focus, it's suspected to serve the interests of the Chinese government.\n\n"UNC4841 has continued to show sophistication and adaptability in response to remediation efforts," researchers from Google-owned incident response firm Mandiant said in a new report. "UNC4841\u2019s deployment select backdoors suggests this threat actor anticipated, and prepared for remediation efforts, by creating tooling in advance to remain embedded in high-value targets, should the campaign be compromised."\n\nAn eight-month long cyberespionage campaign\n\nUNC4841 started compromising Barracuda ESG devices globally in November 2022 through an unknown -- at the time -- remote command injection vulnerability that is now tracked as CVE-2023-2868. The flaw was identified on May 19 and was patched on May 30, but the attack was so sophisticated that Barracuda Networks, Mandiant and the FBI advised impacted customers to replace their devices.\n\nThe flaw was located in the ESG code that inspected attachments in the TAR archive format, so attackers sent specially crafted emails to select organizations that used vulnerable appliances knowing that the emails will be scanned and the exploit will execute. It's estimated that 5% of Barracuda ESG appliances were exploited, but this means a lot of organizations across many countries. A third of the victims were local and national government entities -- many from countries or regions where China has geopolitical interests -- supporting the belief that the main goal was espionage.\n\nThe group used its access to deploy a variety of backdoors and tools, some of which involved trojanizing legitimate Lua modules that already existed on Barracuda ESG devices. Some of these implants were dubbed SALTWATER, SEASPY, SEASIDE, and WHIRLPOOL by Mandiant in June.\n\nThree new Barracuda malware implants\n\nAs soon as Barracuda announced the vulnerability's existence publicly and organizations started remediation efforts, the attackers began deploying an additional implant on some appliances belonging to select victims. The US Cybersecurity and Infrastructure Security Agency (CISA) warned about this implant that it dubbed SUBMARINE in July.\n\n"SUBMARINE is a novel persistent backdoor that lives in a Structured Query Language (SQL) database on the ESG appliance," CISA wrote at the time in its advisory. "SUBMARINE comprises multiple artifacts that, in a multi-step process, enable execution with root privileges, persistence, command and control, and cleanup."\n\nMandiant refers to this implant as DEPTHCHARGE and released more details about how it works in its new report this week. The malware is delivered as a Linux shared object library and is loaded into the Barracuda SMTP (BSMTP) daemon using LD_PRELOAD.\n\nThe malware is deployed through a malicious trigger inserted in the MySQL database that contains the configuration information for the Barracuda ESG appliance. This trigger is activated every time a row is removed from the configuration database which according to Mandiant's analysis occurs frequently during normal operation, as well as when a configuration backup is restored. In other words, this is a persistence mechanism that also allows attackers to infect a new appliance if the configuration from the old one is imported into it and applied.\n\nThe trigger writes an installer script to a location on disk from encrypted code stored in the trigger itself. However, it can't execute the payload. To achieve execution the attackers used a novel technique that involves using a filename that would cause other Barracuda code to execute it due to a two-argument form of Perl\u2019s open( ) function. This shows good knowledge of the Barracuda codebase.\n\nDEPTHCHARGE is a backdoor that can accept incoming TCP connections but also listens for commands that masquerade as SMTP commands that start with the string EHLO and are encrypted with AES-256. According to Mandiant, this implant was deployed on 2.6% of compromised appliances, including those belonging to US and foreign government entities, as well as high tech and information technology providers.\n\n"It was common practice for impacted victims to export their configuration from compromised appliances so it could be restored into a clean one," Mandiant warns. "Therefore, if the DEPTHCHARGE trigger was present in the exported configuration, it would effectively enable UNC4841 to infect the clean device with the DEPTHCHARGE backdoor through this execution chain, and potentially maintain access even after complete replacement of the appliance."\n\nMandiant and Barracuda Networks identified cases where this might have happened and notified those victims. Additionally, the attackers harvested credentials from the MySQL configuration database and used them for lateral movement.\n\nYet another implant that incident responders saw UNC4841 deploy on select victims after the vulnerability became public is called SKIPJACK. This is another passive backdoor that listens for commands sent via specially crafted emails, particularly via the Content-ID and X-Barracuda-Spam-Info email header fields.\n\nSKIP\u200b\u200bJACK is deployed by injecting malicious Lua code into a legitimate Barracuda ESG module called mod_content.lua. The implant was deployed on 5.8% of compromised appliances and selected victims included primarily government and technology organizations, but also targets from the military, defense, aerospace, and telecom sectors.\n\nThe final new implant observed on some victim devices is called FOXTROT. This is a backdoor written in C++ that listens for TCP connections and can act as a proxy. It can capture keystrokes, execute shell commands, open reverse shells, and transfer files.\n\nWhat's interesting is that unlike DEPTHCHARGE and SKIPJACK, FOXTROT does not appear designed for Barracuda ESG appliances but for any Linux system. It was probably part of UNC4841's arsenal already and used in other operations. Its code has some overlap with an open-source tool called REPTILE.\n\nFOXTROT is deployed on systems through a simple launcher written in C that uses Base64, Mod(13) and XOR with a hard-coded key to encrypt execution arguments for FOXTROT. The Mandiant researchers dubbed this launcher FOXGLOVE. The FOXGLOVE and FOXTROT combination was the least used one by UNC4841 on Barracuda ESG victims. It was deployed primarily on appliances at government related organizations that were high priority targets for the Chinese government.\n\nLateral movement after compromise\n\nMandiant Incident responders have also seen UNC4841 attempt to move laterally inside networks to maintain their access if victims replaced their compromised Barracuda appliances. This included network reconnaissance activity with open-source tools such as fscan and using the harvested credentials from Barracuda ESG configurations to access other systems via Active Directory, SSH, VPNs, Proxy servers and Outlook Web Access (OWA).\n\nThe attackers tried to access mailboxes via OWA but did not perform any malicious action inside, highlighting yet again that their goal was likely espionage. On some compromised appliances the attackers added new users to the \/etc\/passwd file to maintain backdoor access via SSH in addition to the access provided by the malware implants.\n\n"Organizations that received these post-remediation malware families were weighted towards government (national), high tech, and information technology sectors," Mandiant said. "This may suggest a threat actor prioritization towards conventional espionage targets and maintaining access to IT and managed service providers."\n\nIn response to Mandiant's report, CISA also issued an updated list of indicators of compromise to include the newly identified implants.