GHSA-fhh2-gg7w-gwpq nginx-ui Backup Restore Allows Tampering with Encrypted Backups
SummaryThe `nginx-ui` backup restore mechanism allows attackers to tamper with encrypted backup archives and inject malicious configuration during restoration.DetailsThe backup format lacks a trusted integrity root. Although files are encrypted, the encryption key and IV are provided to the client and the integrity metadata (`hash_info.txt`) is encrypted using the same key. As a result, an attacker who can access the backup token can decrypt the archive, modify its contents, recompute integrity hashes, and re-encrypt the bundle.Because the restore process does not enforce integrity verification and accepts backups even when hash mismatches are detected, the system restores attacker-controlled configuration even when integrity verification warnings are raised. In certain configurations this may lead to arbitrary command execution on the host.The backup system is built around the following workflow:Backup files are compressed into `nginx-ui.zip` and `nginx.zip`.The files are encrypted using AES-256-CBC.SHA-256 hashes of the encrypted files are stored in `hash_info.txt`.The hash file is also encrypted with the same AES key and IV.The AES key and IV are provided to the client as a "backup security token".This architecture creates a circular trust model:The encryption key is available to the client.The integrity metadata is encrypted with that same key.The restore process trusts hashes contained within the backup itself.Because the attacker can decrypt and re-encrypt all files using the provided token, they can also recompute valid hashes for any modified content.Environment**OS**: Kali Linux 6.17.10-1kali1 (6.17.10+kali-amd64)**Application Version**: nginx-ui v2.3.3 (513) e5da6dd (go1.26.0)**Deployment**: Docker Container default installation**Relevant Source Files**:`backup_crypto.go``backup.go``restore.go``SystemRestoreContent.vue`PoCGenerate a backup and extract the security token (Key and IV) from the HTTP response headers or the `.key` file.
 <img width="1483" height="586" alt="image" src="https://github.com/user-attachments/assets/857a1b3f-ce66-4929-a165-2f28393df17f" />Decrypt the `nginx-ui.zip` archive using the obtained token.Modify the contained `app.ini` to inject malicious configuration (e.g., `StartCmd = bash`).Re-compress the files and calculate the new SHA-256 hash.Update `hash_info.txt` with the new, legitimate-looking hashes for the modified files.Encrypt the bundle again using the original Key and IV.Upload the tampered backup to the `nginx-ui` restore interface.
<img width="1059" height="290" alt="image" src="https://github.com/user-attachments/assets/66872685-b85b-4c81-ae24-13c811acba9a" />**Observation**: The system accepts the modified backup. Although a warning may appear, the restoration proceeds and the malicious configuration is applied, granting the attacker arbitrary command execution on the host.
<img width="1316" height="627" alt="image" src="https://github.com/user-attachments/assets/2752749e-ac39-4d60-88ca-5058b8e840a6" />ImpactAn attacker capable of uploading or supplying a malicious backup can modify application configuration and internal state during restoration.Potential impacts include:Persistent configuration tamperingBackdoor insertion into nginx configurationExecution of attacker-controlled commands depending on configuration settingsFull compromise of the nginx-ui instanceThe severity depends on the restore permissions and deployment configuration.Recommended Mitigation**Introduce a trusted integrity root**
Integrity metadata must not be derived solely from data contained in the backup. Possible solutions include:Signing backup metadata using a server-side private keyStoring integrity metadata separately from the backup archive**Enforce integrity verification**
The restore operation must abort if hash verification fails.**Avoid circular trust models**
If encryption keys are distributed to clients, the backup must not rely on attacker-controlled metadata for integrity validation.**Optional cryptographic improvements**
While not sufficient alone, switching to an authenticated encryption scheme such as AES-GCM can simplify integrity protection if the encryption keys remain secret.This vulnerability arises from a circular trust model where integrity metadata is protected using the same key that is provided to the client, allowing attackers to recompute valid integrity data after modifying the archive.RegressionThe previously reported vulnerability (GHSA-g9w5-qffc-6762) addressed unauthorized access to backup files but did not resolve the underlying cryptographic design issue.The backup format still allows attacker-controlled modification of encrypted backup contents because integrity metadata is protected using the same key distributed to clients.As a result, the fundamental integrity weakness remains exploitable even after the previous fix.A patched version is available at https://github.com/0xJacky/nginx-ui/releases/tag/v2.3.4.
CVSS v4.0 score: 9.4