Fortinet Firmware decryption and analysis tools
A single static Go binary and library for decrypting and unpacking Fortinet firmware: FortiGate/FortiWiFi FortiOS images and tested FortiAnalyzer/FortiManager KVM installation packages. Supported containers, filesystems and crypto schemes are detected from their contents, without a product, version or CPU architecture flag. See Supported firmware for the tested products, package types and stages.
The format and crypto readers are implemented in Go. No openssl, xz,
tar, cpio, mount/debugfs, 7z, binwalk, vmlinux-to-elf, or Python
is required at runtime. FortiOS config-secret decryption and FortiGuard
PKCS#7 signature inspection are also included.
Historically, decrypting one firmware image meant picking the right tool
out of several version-specific ones (forticrack, fgx, forticrack_v8,
decrypt-fortigate-rootfs, ...) and chaining OS binaries by hand.
fortitool folds all of that into one command.
Download the archive for your platform from the
GitHub releases. Each release
includes a SHA-256 checksum file covering every prebuilt-binary archive.
Extract the archive, put fortitool (or fortitool.exe) on your PATH, and
run fortitool version to confirm the installed tag.
Alternatively, install with Go:
go install github.com/mosajjal/fortitool/cmd/fortitool@latest
Or build from source:
git clone https://github.com/mosajjal/fortitool
cd fortitool
CGO_ENABLED=0 go build -o fortitool ./cmd/fortitool
CGO_ENABLED=0 matters if you want the fully-static binary this project
promises — without it, Go links against glibc for the (unused) net
resolver. Verify with file fortitool (should say "statically linked") or
ldd fortitool (should say "not a dynamic executable").
fortitool decrypt -o outdir image.out # full pipeline, one command
fortitool inspect image.out # read-only format/support report
fortitool decrypt -o fmg image.out.kvm.zip # FAZ/FMG single-QCOW2 package
fortitool decrypt --boot-only -o boot faz.qcow2 # original boot files only
fortitool l1 -o out.img image.out # outer XOR layer only
fortitool rootfs -o out.gz kernel rootfs.gz # kernel is flatkc or vmlinuz
fortitool unpack -o outdir archive.tar.xz # generic gzip+tar / xz+tar
fortitool pkg inspect --content payload sig.x # verify a PKCS#7 signature
fortitool pkg scan datafs/ # classify files, find sigs
fortitool config decrypt --stdin < secret.txt # config-backup ENC secret
fortitool config decrypt --file secret.txt # file input without argv exposure
Every command has a full description, flags, and examples via
fortitool <command> -h (or run fortitool -h for the command list).
Flags must precede positional arguments — Go's flag package doesn't
permute argv the way getopt does.
inspect reports one image as stable, human-readable field: value lines.
It uses the same L1, disk-layout, required-member, rootfs-crypto and payload
classification decisions as decrypt, but does not extract or write anything
and never displays recovered key material. A readable image that is only
partially recognised reports status: partial, a last-successful-stage and
an unsupported-stage, and exits 0 because describing that boundary is a
successful inspection. An absent or inaccessible input exits 1; invalid flags
or argument count exit 2.
decrypt and unpack publish a completed tree only when the requested
output directory does not already exist. Linux uses an atomic no-replace
rename; other platforms perform a best-effort existence check before the
rename. Staged trees and standalone decrypted files are private to the
invoking identity: mode 0700 or 0600 on Unix, and a protected per-user DACL
on Windows. Archive and filesystem symlinks with absolute targets are rewritten
as confined relative links, so extracted links remain inside the output tree
rather than referring to paths on the host.
For config secrets, prefer --stdin or --file so the ciphertext does
not appear in process listings or shell history. The direct
fortitool config decrypt <base64-blob> form remains available only for
compatibility, and exactly one of the three input sources is accepted.
Input is limited to 1 MiB; surrounding whitespace is trimmed, and the
remaining value must be non-empty and contain no whitespace.
With pkg inspect --content, verification succeeds only when the wrapper
contains at least one signer and every SignerInfo validates against the
payload. This proves cryptographic integrity using the certificates embedded
in the PKCS#7 wrapper; it does not validate their trust chains to a trusted
root CA.
Coverage is specific to the product, package type and processing stage. FAZ/FMG firmware support does not establish support for their configuration backup secrets or for other Fortinet products.
Across 167 unique FortiOS images tested, with versions spanning 3.0 through 8.0, L1/header recovery succeeded for every image and matched an independent decoder byte-for-byte. This covers that stage and tested set only; later decryption and extraction remain format-dependent, as detailed below.
| Layer | Coverage | Status |
|---|---|---|
L1 .out outer cipher | Supported FortiOS .out layouts | Verified across the 167-image corpus described above; real FWF-60E 7.4.7/7.4.10/7.4.11 output is byte-identical to an independent decoder |
| rootfs.gz — ChaCha20+RSA+AES-CTR family | 7.4.1–7.4.11 (ARM + x86_64 splits) | ARM path verified byte-identical against real firmware; x86_64 splits ported from public write-ups, covered by a synthetic round-trip test, not run against a real x86 sample |
| rootfs.gz — ChaCha20 body (7.4.1–7.4.3 era) | seed-derived key/IV, non-RFC7539 counter | Ported from fortigate-crypto/Bishop Fox, covered by a synthetic round-trip test, not run against a real sample of that era |
| rootfs.gz — XOR+RSA+{FORT-RC4,modified-RC4} family | 7.6.x, 8.0 | Ported from public write-ups (fgx, forticrack_v8), covered by a synthetic round-trip test, not run against a real sample |
| Disk image layouts | appliance MBR+ext3 @512; QCOW2 VM disks; fixed-offset volumes | Appliance path verified byte-identical against real firmware; QCOW2/partition and ext4-extent discovery covered by synthetic tests, not run against a real FortiGate VM image |
| ext2/3 filesystem read | FSoC3/ARM appliance MBR+ext3 layout | Verified byte-identical against real firmware, including double-indirect block mapping |
| ext4 extent-mapped read | FortiOS 8.0 VM rootfs (xz-compressed ext4 image) | Synthetic round-trip tests only, no real 8.0 sample available |
| tar/gzip/xz unpack | any | Verified byte-identical against real firmware |
| PKCS#7 SignedData verify | detached signatures (.x files), incl. dual-signed | Verified against real signed engine/DB files, both signer chains |
Config-secret ENC <base64> decrypt | all eras | Legacy hardcoded AES-128 key verified against real device data through at least 7.2.3 (contrary to common belief it was never rotated at 6.2). The >=7.4 (build 2731) AES-256-CBC key was recovered by RE of the init monolith and verified against real device backups spanning both eras — both keys embedded, see Config-secret keys |
"Verified" means run against real firmware/config samples and checked byte-identical or semantically correct output. Everything else is a faithful port of a documented, working reference implementation, exercised by this repo's test suite, but not yet run against a real sample of that specific era — patches with real-firmware validation welcome.