CVE-2023-5372 - Post-auth blind Python code injection vulnerabilities in Zyxel’s NAS326 and NAS542 devices
Several functions in the Zyxel NAS web management interface passed user-supplied service and package parameters into Python's eval(), so an authenticated attacker could inject arbitrary Python code. Because the WSGI server runs as root, this could lead to remote code execution on the device.
Published on bugprove.com
Zyxel’s NAS326 and NAS542 model devices running firmware version V5.21(AAZF.15)C0 or V5.21(ABAG.13)C0 and earlier are affected. Note that both the vulnerable models reached end-of-vulnerability-support on Dec.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Zyxel's NAS326 and NAS542 are two-bay personal cloud storage devices with a web management interface. That interface exposes a service and package management mechanism: the application creates service_unit objects on the fly from user-supplied parameters and maps them to appclass objects, which are instances of applications such as the FTP server or the Print Server. Operations like enabling or disabling those applications are then performed on the mapped objects.
The relevant logic lives in the appzone_main_model.py component of the web management interface, specifically in the manipulate_services(), manipulate_services_dependency() and manipulate_packages() functions. CVE-2023-5372 covers post-auth blind Python code injection in that mechanism: an authenticated attacker can execute code remotely on an affected device, in the context of the WSGI server process, which runs as root.
This was the last in a series of vulnerabilities BugProve reported to Zyxel in the NAS devices in July and August 2023, a series that also included a critical authentication bypass tracked as CVE-2023-4473 and a high-severity command injection vulnerability known as CVE-2023-37927.
Setup
The analysis was performed on firmware version V5.21(AAZF.14)C0 of the NAS326. The researcher did not observe any differences compared to the latest V5.21(AAZF.15)C0.
Affected products are NAS326 and NAS542 devices running firmware V5.21(AAZF.15)C0 or V5.21(ABAG.13)C0 and earlier. Both vulnerable models reached end-of-vulnerability-support on 31 December 2023.
The vulnerabilities can be confirmed with an authenticated user. The command output does not appear in the application's responses, so confirmation relies on timing: the injected code makes the application wait for a specified time.
Finding it
The web management interface appeared to be vulnerable to Python code injection attacks. It was possible to use the parenthesis (), the double quote ", the single quote ' and various other shell metacharacters to inject arbitrary Python code in the appargs parameter at the path /cmd,/ck6fup6/appzone_main/manipulate_services or /cmd,/ck6fup6/mobile_main/manipulate_services. The manipulate_services_dependency() and manipulate_packages() functions in appzone_main_model.py also seemed to be affected by the same issue.
Because the command output is not returned in the application's responses, the researcher verified execution by causing the application to wait for a specified time.
Exploitation
Step 1: Inject into the appzone_main path
The payload ")!=os.system("sleep 5 was submitted in the appargs parameter at the path /cmd,/ck6fup6/appzone_main/manipulate_services. The application took longer to respond to the PoC request than to the original one, indicating that the injected sleep command caused a time delay.

Figure 1 shows the Python code injection vulnerability in the appargs parameter at /appzone_main/manipulate_services.
Step 2: Inject into the mobile_main path
The same vulnerability can be triggered via another path. The same payload, ")!=os.system("sleep 5, was submitted in the appargs parameter at the path /cmd,/ck6fup6/mobile_main/manipulate_services. Again the application took longer to respond to the PoC request than to the original one, indicating that the injected sleep command caused a time delay.

Figure 2 shows the Python code injection vulnerability in the appargs parameter at /mobile_main/manipulate_services.
Step 3: Confirm with full URLs
The vulnerabilities can be confirmed with an authenticated user via the following URLs:
http[:]//NAS326/cmd,/ck6fup6/appzone_main/manipulate_services?action=enable&appargs=%22)!%3dos.system(%22sleep%205
http[:]//NAS326/cmd,/ck6fup6/mobile_main/manipulate_services?action=enable&appargs=%22)!%3dos.system(%22sleep%205
The URLs carry the payload in the appargs parameter, URL-encoded. The delay in the response is the only observable signal, since the output is not returned.
Root cause
The vulnerability lies within the implementation of the service and package management mechanism. The application creates service_unit objects on the fly according to the user-provided parameters and maps them to appclass objects to perform operations such as enabling or disabling an application.
The manipulate_services(), manipulate_services_dependency() and manipulate_packages() functions map the received list of service_unit objects to their corresponding appclass object and invoke the specified action method using the eval() function. The relevant excerpt of the decompiled source code of the affected functions within appzone_main_model.py is:
def manipulate_services(service_list):
...SNIP...
for s_item in service_list:
if app_mapper.has_key(s_item.s_name):
s_instance = app_mapper[s_item.s_name]
eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args))
else:
...SNIP...
if package_list:
s_instance = app_mapper['Package']
eval('s_instance.%s("%s")' % (package_action, string.join(package_list, '|')))
return
def manipulate_services_dependency(usertype, service_list):
...SNIP...
for s_item in service_list:
if app_mapper.has_key(s_item.s_name):
s_instance = app_mapper[s_item.s_name]
eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args))
else:
package_list.append(s_item.s_name)
package_action = s_item.s_action
if package_list:
...SNIP...
s_instance = app_mapper['Package']
eval('s_instance.%s("%s")' % (package_action, string.join(package_list, '|')))
return
def manipulate_packages(service_list):
...SNIP...
for s_item in service_list:
if pkg_mapper.has_key(s_item.s_name):
s_instance = pkg_mapper[s_item.s_name]
rvalue.append(eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args)))
else:
...SNIP...
return rvalue
Python code injection vulnerabilities arise when the application incorporates user-controllable data into a string that is dynamically evaluated by a code interpreter, here via eval(). If the user data is not strictly validated, an attacker can use crafted input to modify the original code to be executed and inject arbitrary code that the server will run. The attacker must bypass the original s_instance.%s("%s") Python statement to execute malicious code.
Impact
An authenticated attacker can execute code on an affected device remotely. The code runs in the context of the WSGI server process, which runs as root. The output is not returned in the application's responses, so the injection is blind: an attacker has to infer execution through side effects such as time delays.
Fix
Zyxel released firmware versions V5.21(AAZF.16)C0 and V5.21(ABAG.13)C0 on 25 January 2024. The report does not describe the code changes in those releases.
Variants to test
- Send the same
appargspayload to/cmd,/ck6fup6/appzone_main/manipulate_servicesand/cmd,/ck6fup6/mobile_main/manipulate_serviceswith an authenticated session. A positive result is a response that takes noticeably longer than the baseline request, consistent with the injectedsleep 5. - Try the
manipulate_services_dependency()andmanipulate_packages()code paths, which the report says also seem to be affected. A positive result is the same timing difference when the payload reaches those functions.
What happened, in plain words
Zyxel makes small home and small-office storage boxes, called NAS devices. NAS stands for Network Attached Storage: a hard drive (or two) in a box that you plug into your home network, so that every computer in the house can save files to it and read files from it, a bit like a shared filing cabinet that everyone can reach. The two models in this story are the NAS326 and the NAS542, both two-bay devices, meaning they hold two hard drives. Zyxel advertises them as "personal cloud storage": you can reach your files from outside the house too, not just from the sofa.

Like most devices of this kind, they are configured through a web management interface. That is simply a small website that the box itself runs. You open your browser, type the box's address, log in with a username and password, and click around pages to change settings: create users, share folders, turn services on and off. There is no separate app to install; the browser is the control panel.
A security research team looked inside the software of these boxes and found a flaw. The flaw lets someone who has already logged in (that is what "post-auth" means: after authentication, after the login step) make the box run commands of their choosing. The code runs in the context of the WSGI server process, which runs as root, the all-powerful administrator account. The flaw was given the identifier CVE-2023-5372. A CVE is a public catalogue number for a known security bug, so that everyone in the world can refer to the same issue unambiguously.
This article walks through how the researchers found it, how they proved it was real, and why the code allowed it in the first place. You do not need to know how to program to follow along. Every technical word is explained the first time it appears, and there is a glossary at the end.
Disclosure timeline
Security research usually follows a rhythm: find a bug, tell the maker privately, give them time to fix it, then tell the public. The dates here show that rhythm.
- 23 August 2023: the research team reported several vulnerabilities to Zyxel. "Several" matters: this was not one bug but a batch.
- 16 October 2023: Zyxel assigned CVE-2023-5372 and said it aimed to have things settled by 30 January 2024. Assigning a CVE is like giving the bug an official case number.
- 30 November 2023: Zyxel marked the NAS326 and NAS542 as EOL, short for End Of Life. EOL means the manufacturer has stopped selling and supporting the product. In this case Zyxel also said there was no migration path, meaning it did not point owners to a newer model to move to.
- 19 January 2024: the research team asked Zyxel to confirm whether the fix had been released.
- 23 January 2024: Zyxel confirmed the 30 January 2024 target date.
- 25 January 2024: Zyxel released firmware versions V5.21(AAZF.16)C0 and V5.21(ABAG.13)C0. Firmware is the software built into the device, the equivalent of the operating system on a computer. Updating firmware is how you patch a NAS.
- 30 January 2024: the advisory was published publicly, on the agreed date. An advisory is the public write-up of a vulnerability, telling owners what is affected and what to do.
Affected products
Zyxel's NAS326 and NAS542 devices running firmware version V5.21(AAZF.15)C0 or V5.21(ABAG.13)C0 and earlier are affected. "And earlier" is the important part: if your box is on an older firmware than the listed one, it is in scope too.
Both vulnerable models reached end-of-vulnerability-support on 31 December 2023. That is a slightly different idea from end-of-life: it means the maker no longer promises to produce security fixes for newly found problems in these models.
Product URLs
The report links to the product pages for the NAS326, a two-bay personal cloud storage device, and to Zyxel's download library for the NAS326, where firmware files are published.
Summary
The research team reported many vulnerabilities to Zyxel in its NAS devices in July and August 2023. Zyxel decided to address them in a specific order and on a specific schedule, rather than all at once. CVE-2023-5372 is the last one in that series. The series also included a critical authentication bypass tracked as CVE-2023-4473 and a high-severity command injection vulnerability known as CVE-2023-37927.
Two of those terms deserve a plain explanation, because they come up again and again in security writing.
- An authentication bypass is a flaw that lets someone get past the login step without knowing the password. It is like a hotel where the room key check can be skipped by walking through a side door.
- Command injection is a flaw where the device is tricked into running an operating-system command that the attacker supplied, because it mixed the attacker's text into a command it was building. The device thinks the extra text is part of its own instruction.
CVE-2023-5372 itself is a Python code injection. Python is a programming language, and a great deal of the software inside network devices is written in it. Code injection means the attacker's text is treated as program code rather than as harmless data. The difference is like the difference between writing your name on a form (data) and writing an extra instruction on the form that the clerk then carries out (code).
The report calls these post-auth blind Python code injection vulnerabilities. We have covered post-auth. Blind means the attacker cannot see the result of what they ran. The device does not send back the output of the command. So how do you know it worked? You make the device do something you can observe indirectly, such as pause for five seconds. If the reply comes back five seconds late, you know your code ran.
The specific flaws sit in the implementation of the service and package management mechanism, inside three functions named manipulate_services(), manipulate_services_dependency() and manipulate_packages(), all in a component called appzone_main_model.py that is part of the web management interface. A function is a named block of code that does one job; you can think of it as a labelled drawer in a filing cabinet. A component or file is simply where that code lives.
A specially crafted query parameter attached to the URL of the web management interface can be used to execute arbitrary code. A query parameter is the part of a web address after the question mark, made of name and value pairs, like ?colour=blue&size=large. Websites use them to pass choices from the browser to the server. "Arbitrary code" means code of the attacker's choosing, not just the operations the page was designed to offer.
An attacker could use these flaws to execute code in the context of the WSGI server process, running as root. Two more terms:
- WSGI is a standard way for a Python web application to talk to a web server. The "WSGI server process" is the running program that handles the web pages of the management interface.
- root is the name of the all-powerful administrator account on Linux and similar systems. A process running as root can do anything on the machine: read any file, change any setting, install software. So code running "as root" is code with no restrictions.
Details
The analysis was performed on firmware version V5.21(AAZF.14)C0 of the NAS326. The researcher did not observe any differences compared to the latest V5.21(AAZF.15)C0.
The web management interface appeared to be vulnerable to Python code injection attacks. It was possible to use the parenthesis (), the double quote ", the single quote ' and various other shell metacharacters to inject arbitrary Python code in the appargs parameter at the path /cmd,/ck6fup6/appzone_main/manipulate_services or /cmd,/ck6fup6/mobile_main/manipulate_services.
Let us unpack that sentence, because it is dense.
- A parameter here means one of those name and value pairs in the URL.
appargsis the name; whatever follows the equals sign is the value the attacker controls. - A path is the part of the address that says which page or feature you are asking for, the equivalent of which corridor and door you walk to inside a building. The paths above are unusual-looking, with commas and a random-looking segment, but they are simply the addresses the interface uses internally.
- Metacharacters are characters that have a special meaning to a computer language rather than being plain text. In Python, a double quote starts or ends a piece of text (a string), and parentheses group things and mark a function call. If you can slip those characters into a place where the program builds code, you can change the shape of that code. It is like being allowed to write your name on a form and using the space to draw an extra box and a signature line.
The manipulate_services_dependency() and manipulate_packages() functions in the appzone_main_model.py file also seem to be affected by this issue. The word "seem" is deliberate: the report says these paths appear affected, not that they were each demonstrated with a payload.
The command output does not appear in the application's responses. In other words, if you make the box run a command that lists files, the list does not come back to your browser. This is why the flaw is called blind. However, it is possible to cause the application to wait for a specified time, to verify that a command was executed. That is the trick used throughout: instead of asking for output, ask for a delay.
Step 1: Inject into the appzone_main path
The payload ")!=os.system("sleep 5 was submitted in the appargs parameter at the path /cmd,/ck6fup6/appzone_main/manipulate_services. The application took longer to respond to the proof-of-concept request than to the original one, indicating that the injected sleep command caused a time delay.
A payload is the piece of text an attacker sends to trigger a bug. A proof of concept, or PoC, is a minimal demonstration that the bug is real, just enough to show it works without doing harm. Here the PoC does nothing more dangerous than pause the device for five seconds.

Figure 1 shows the Python code injection vulnerability in the appargs parameter at /appzone_main/manipulate_services. The comparison that matters is the response time: the request carrying the payload came back later than the ordinary request, which is the visible trace of the injected sleep 5.
Step 2: Inject into the mobile_main path
The same vulnerability can be triggered via another path. The same payload, ")!=os.system("sleep 5, was submitted in the appargs parameter at the path /cmd,/ck6fup6/mobile_main/manipulate_services. Again the application took longer to respond to the PoC request than to the original one, indicating that the injected sleep command caused a time delay.

Figure 2 shows the Python code injection vulnerability in the appargs parameter at /mobile_main/manipulate_services.
Step 3: Confirm with full URLs
The vulnerabilities can be confirmed with an authenticated user via the following URLs:
http[:]//NAS326/cmd,/ck6fup6/appzone_main/manipulate_services?action=enable&appargs=%22)!%3dos.system(%22sleep%205
http[:]//NAS326/cmd,/ck6fup6/mobile_main/manipulate_services?action=enable&appargs=%22)!%3dos.system(%22sleep%205
Line by line, in plain words:
http[:]//NAS326/is the address of the device on the local network. The square brackets around the colon are a common convention in security write-ups: they stop the address from turning into a clickable link, so nobody accidentally fires the request at a real machine while reading.NAS326stands in for the device's address./cmd,/ck6fup6/appzone_main/manipulate_servicesand/cmd,/ck6fup6/mobile_main/manipulate_servicesare the two paths from the previous steps. They are the doors the request knocks on.?marks the start of the query parameters, the name and value pairs described earlier.action=enableis one of the parameters in the URL.appargs=is the parameter that carries the payload.%22)!%3dos.system(%22sleep%205is the payload, written in URL encoding. Web addresses cannot contain spaces or certain punctuation safely, so browsers and tools replace them with a percent sign and two characters.%22is the double quote,%3dis the equals sign, and%20is the space. Decoded, the value is")!=os.system("sleep 5.
The payload is URL-encoded in the URL; decoded, the value is ")!=os.system("sleep 5. The delay in the response is the only observable signal, since the output is not returned.
os.system is a standard Python way of asking the operating system to run a command. sleep 5 is a command that does nothing for five seconds. Neither is harmful in itself; they are chosen precisely because they are harmless and easy to observe.
Root cause
The vulnerability lies within the implementation of the service and package management mechanism. The application creates service_unit objects on the fly according to the user-provided parameters and maps them to appclass objects to perform operations such as enabling or disabling an application.
An object in programming is a bundle of data and behaviour, a little like a record card that holds details about one thing and knows what can be done with it. A service_unit here represents one service the user wants to act on. An appclass object represents an actual application on the box, such as the FTP server or the Print Server. FTP is the old standard file transfer service; the Print Server shares a printer over the network. "On the fly" means the objects are created at the moment of the request, from whatever the user sent, rather than being picked from a fixed list.
The three functions map the received list of service_unit objects to their corresponding appclass object and invoke the specified action method using the eval() function. eval() is a Python function that takes a piece of text and runs it as code. It is the heart of the problem: if any part of that text came from the user, the user is effectively writing code for the server to run. The relevant excerpt of the decompiled source code of the affected functions within appzone_main_model.py is:
def manipulate_services(service_list):
...SNIP...
for s_item in service_list:
if app_mapper.has_key(s_item.s_name):
s_instance = app_mapper[s_item.s_name]
eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args))
else:
...SNIP...
if package_list:
s_instance = app_mapper['Package']
eval('s_instance.%s("%s")' % (package_action, string.join(package_list, '|')))
return
def manipulate_services_dependency(usertype, service_list):
...SNIP...
for s_item in service_list:
if app_mapper.has_key(s_item.s_name):
s_instance = app_mapper[s_item.s_name]
eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args))
else:
package_list.append(s_item.s_name)
package_action = s_item.s_action
if package_list:
...SNIP...
s_instance = app_mapper['Package']
eval('s_instance.%s("%s")' % (package_action, string.join(package_list, '|')))
return
def manipulate_packages(service_list):
...SNIP...
for s_item in service_list:
if pkg_mapper.has_key(s_item.s_name):
s_instance = pkg_mapper[s_item.s_name]
rvalue.append(eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args)))
else:
...SNIP...
return rvalue
Line by line, in plain words:
def manipulate_services(service_list):starts the definition of a function namedmanipulate_services, which takes one input, a list of services....SNIP...is not real code. It marks a place where the report cut out lines that are not relevant, to keep the excerpt readable.for s_item in service_list:begins a loop: do the following once for each service in the list.if app_mapper.has_key(s_item.s_name):checks whether the service's name exists in a lookup table calledapp_mapper. A lookup table maps a name to the object that handles it, like a phone book mapping a name to a number.s_instance = app_mapper[s_item.s_name]fetches the matching object and stores it ins_instance.eval('s_instance.%s(*%s)' % (s_item.s_action, s_item.s_args))is the dangerous line. It builds a piece of text by substituting the action and arguments supplied by the user into a template, then hands the result toeval(), which runs it. The%splaceholders are where the user's text lands.else:covers the case where the name is not in the table; the following lines (cut out here) deal with it.if package_list:checks whether any names ended up in a list of packages.s_instance = app_mapper['Package']fetches the object that handles packages.eval('s_instance.%s("%s")' % (package_action, string.join(package_list, '|')))is the second dangerous line. Here the user's text is placed inside double quotes in the built string, which is exactly why the payload starts with a double quote: it closes that quoted section early.returnends the function.- The second function,
manipulate_services_dependency, follows the same pattern, with an extra inputusertypeand a branch that collects names intopackage_listwhen they are not found in the table. - The third function,
manipulate_packages, uses a different lookup table,pkg_mapper, and collects results intorvalue, but the sameeval()pattern is present.
Python code injection vulnerabilities arise when the application incorporates user-controllable data into a string that is dynamically evaluated by a code interpreter, in this case via the eval() function. If the user data is not strictly validated, an attacker can use crafted input to modify the original code to be executed, and inject arbitrary code that will be executed by the server. Note that the attacker must bypass the original s_instance.%s("%s") Python statement to execute malicious code; the payload above does this by closing the string and the call before appending its own expression.
A useful comparison: imagine a clerk who fills in a form letter by copying what the customer wrote. If the customer writes a normal name, the letter reads sensibly. If the customer writes a name followed by "and also post this letter to everyone in the building", a careless clerk might copy that instruction into the letter and carry it out. eval() is that careless clerk.
Impact
An authenticated attacker can execute code on an affected device remotely. "Remotely" means over the network, without physical access to the box. The code runs in the context of the WSGI server process, which runs as root, so it inherits the highest privileges on the device. The output is not returned in the application's responses, so the injection is blind: an attacker has to infer execution through side effects such as time delays.
In everyday terms: someone who has a valid login to the box, perhaps a family member, a guest account, or someone who obtained a password by other means, can turn that ordinary access into full control of the machine. They cannot read the answers directly, but they can still make the box do things and watch for indirect signs.
Fix
Zyxel released firmware versions V5.21(AAZF.16)C0 and V5.21(ABAG.13)C0 on 25 January 2024. The report does not describe the code changes in those releases. The general remedy for this class of flaw is to stop passing user-controllable data into eval() and to dispatch actions through a fixed mapping of allowed methods and validated arguments instead.
Variants to test
These are the follow-up checks a tester would run to map the problem fully. Each one is a variation on the same idea: send the payload somewhere slightly different and look for the same timing signal.
- Send the same
appargspayload to/cmd,/ck6fup6/appzone_main/manipulate_servicesand/cmd,/ck6fup6/mobile_main/manipulate_serviceswith an authenticated session. A positive result is a response that takes noticeably longer than the baseline request, consistent with the injectedsleep 5. The baseline is an identical request without the payload, so you have something to compare against. - Try the
manipulate_services_dependency()andmanipulate_packages()code paths, which the report says also seem to be affected. A positive result is the same timing difference when the payload reaches those functions.
Glossary
- Advisory: the public write-up of a vulnerability, saying what is affected and what to do about it.
- appclass: in this report, an object representing an actual application on the device, such as the FTP server or the Print Server.
- Authentication: the login step, proving who you are with a username and password.
- Authentication bypass: a flaw that lets someone get past the login step without valid credentials.
- Blind (injection): a flaw where the attacker cannot see the result of the code they ran, so they infer success from side effects such as delays.
- Component: a file or module that is part of a larger piece of software.
- CVE: a public catalogue number for a known security vulnerability, so everyone can refer to the same issue.
- End of life (EOL): the manufacturer has stopped selling and supporting the product.
- End-of-vulnerability-support: the manufacturer no longer promises security fixes for newly found problems in the product.
- eval(): a Python function that takes text and runs it as code; dangerous when the text contains user input.
- Firmware: the software built into a device, the equivalent of its operating system.
- FTP: an old standard service for transferring files over a network.
- Function: a named block of code that performs one job.
- Lookup table: a structure that maps a name to the thing that handles it, like a phone book.
- Metacharacters: characters with special meaning to a computer language, such as quotes and parentheses, rather than plain text.
- NAS: Network Attached Storage, a box of hard drives shared over a network so several computers can store and read files.
- Object: a bundle of data and behaviour in programming, representing one thing and what can be done with it.
- Parameter: a name and value pair passed in a URL, such as
appargs=.... - Path: the part of a web address that identifies which page or feature is being requested.
- Payload: the text an attacker sends to trigger a vulnerability.
- Post-auth: after logging in; the attacker already has a valid session.
- Proof of concept (PoC): a minimal demonstration that a vulnerability is real.
- Python: a widely used programming language, common in the software inside network devices.
- Query parameter: the part of a web address after the question mark, made of name and value pairs.
- root: the all-powerful administrator account on Linux and similar systems; a process running as root can do anything on the machine.
- service_unit: in this report, an object created from user-supplied parameters that represents one service to act on.
- Shell: the program on a system that takes typed commands and runs them.
- URL encoding: replacing characters that are unsafe in a web address with a percent sign and two characters, such as
%20for a space. - Web management interface: a small website run by a device, used to configure it from a browser.
- WSGI: a standard way for a Python web application to talk to a web server; the WSGI server process handles the management interface's pages.