Chaining of three vulnerabilities allows unauthenticated attackers to execute arbitrary command with root privileges on Zyxel VPN firewall (VPN50, VPN100, VPN300, VPN500, VPN1000). Due to recent attack surface changes in Zyxel, the chain described below broke and become unusable – we have decided to disclose this even though it is no longer exploitable.
Credit
An independent security researcher, delsploit, working with SSD Secure Disclosure.
Affected Versions
The affected models are VPN50, VPN100, VPN300, VPN500, and VPN1000. The affected firmware version is 5.21 thru to 5.36.
Technical Analysis
By examining the httpd.conf you can notice a few paths that require no authentication:
However this alone is useless to execute arbitrary commands. Additional bugs were required to gain RCE.
When running commands in the product, the functions use execve function to avoid injection in most of the code.
A vulnerability can however be triggered when sdwan_interface and sdwan_iface_ipc are doing Inter-Process Communication.
Let’s see it at the code level. You can see something is written in v31 buffer:
After setting the buffer, it is sent to sdwan_interface by pic_sdwan_send_config.
Pay attention to v31.offset_584 copied to argument[3]. It’s the only injection point because other arguments are filtered or formatted by some rules, like ip format and number type.
sdwan_interface will then run the injected command after receiving payload. (v75->offset_584 is equal to v31.offset_584.)
Now let’s take a look at how we can trigger the IPC.
parse_result is called in main of parse_config.py. And you can see handle_gre is called:
with open(ztpinclude.ZTPFILEPATH + ‘parsed_config’, ‘w+’) as fout:
for configlist in config:
try:
if configlist[‘proto’] == “cellular”:
#### skip ####
elif configlist[‘proto’] == “static”:
#### skip ####
elif configlist[‘proto’] == “pppoe”:
#### skip ####
elif configlist[‘proto’] == “deviceha”:
#### skip ####
elif configlist[‘proto’] == “certificate”:
#### skip ####
elif configlist[‘proto’] == “vti”:
if not handle_vti(configlist, vti_cnt):
break
vti_cnt += 1
elif configlist[‘proto’] == “gre”:
if not handle_gre(configlist, gre_cnt):
break
gre_cnt += 1
except Exception as e:
#### skip ####
return(applyresult, parm_ou, parm_o, parm_cn)
else:
#### skip ####
handle_gre runs a process named sdwan_iface_ipc. And the arguments can be controlled by users. It runs the process, like executing command sdwan_iface_ipc 8 inp0 inp1 inp2 inp3 …:
defhandle_gre(configlist, idx):
ok = False
logging.info(“setting up gre interface”)
logging.info(“; “.join([“=”.join(_)for _ in configlist.items()]))
At this point, we can perform the command injection. There’s good news and bad news. The good news is that sdwan_interface is running with root privileges, while httpd is running with nobody privileges. It means we don’t need additional LPE exploit.
The bad news is there’s a length limit, because only 0x14 bytes of argument[3] are copied. It means that we can enter only 0x14 bytes command including command separators.
But using a third vulnerability we can overcome this.
There’re two vulnerability in handle_vti. One allows us to traverse arbitrary path with ‘.qsr’ postfix, and the other one allows us to write arbitrary contents in the file. Our focus is on the second one, because if it can write the shell command in a file and execute it, freeing us from the length limit.
defhandle_vti(configlist, idx):
ok = False
qsrname = “/tmp/%s.qsr” % configlist[“name”]
logging.info(“setting up vti interface”)
logging.info(“; “.join([“=”.join(_)for _ in configlist.items()]))