Remote Memory Exposure Affecting ws package, versions < 1.0.1
Threat Intelligence
EPSS
The probability is the direct output of the EPSS model, and conveys an overall sense of the threat of exploitation in the wild. The percentile measures the EPSS probability relative to all known EPSS scores. Note: This data is updated daily, relying on the latest available EPSS model version. Check out the EPSS documentation for more details.
2.02% (80th percentile)
Do your applications use this vulnerable package?
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applications- Snyk IDnpm:ws:20160104
- published5 Jan 2016
- disclosed4 Jan 2016
- creditFeross Aboukhadijeh, Mathias Buss Madsen
Introduced: 4 Jan 2016
CVE-2016-10518 (opens in a new tab) Common Vulnerabilities and Exposures (CVE) are common identifiers for publicly known security vulnerabilities
CWE-201 (opens in a new tab) Common Weakness Enumeration (CWE) is a category system for software weaknesses
Overview
ws is a simple to use websocket client, server and console for node.js.
Affected versions of the package are vulnerable to Uninitialized Memory Exposure.
A client side memory disclosure vulnerability exists in ping functionality of the ws service. When a client sends a ping request and provides an integer value as ping data, it will result in leaking an uninitialized memory buffer.
This is a result of unobstructed use of the Buffer constructor, whose insecure default constructor increases the odds of memory leakage.
ws's ping function uses the default Buffer constructor as-is, making it easy to append uninitialized memory to an existing list. If the value of the buffer list is exposed to users, it may expose raw memory, potentially holding secrets, private data and code.
Proof of Concept:
var ws = require('ws')var server = new ws.Server({ port: 9000 }) var client = new ws('ws://localhost:9000')
client.on('open', function () { console.log('open') client.ping(50) // this makes the client allocate an uninitialized buffer of 50 bytes and send it to the server
client.on('pong', function (data) { console.log('got pong') console.log(data) }) })
Details
The Buffer class on Node.js is a mutable array of binary data, and can be initialized with a string, array or number.
const buf1 = new Buffer([1,2,3]);
// creates a buffer containing [01, 02, 03]
const buf2 = new Buffer('test');
// creates a buffer containing ASCII bytes [74, 65, 73, 74]
const buf3 = new Buffer(10);
// creates a buffer of length 10
The first two variants simply create a binary representation of the value it received. The last one, however, pre-allocates a buffer of the specified size, making it a useful buffer, especially when reading data from a stream.
When using the number constructor of Buffer, it will allocate the memory, but will not fill it with zeros. Instead, the allocated buffer will hold whatever was in memory at the time. If the buffer is not zeroed by using buf.fill(0), it may leak sensitive information like keys, source code, and system info.
Similar vulnerabilities were discovered in request, mongoose, ws and sequelize.
CVSS Base Scores
version 3.1
Snyk
6.5 medium
Attack Vector (AV)
The vulnerable component is bound to the network stack and the set of possible attackers extends beyond the other options listed below, up to and including the entire Internet. Such a vulnerability is often termed “remotely exploitable” and can be thought of as an attack being exploitable at the protocol level one or more network hops away (e.g., across one or more routers).
Network
Attack Complexity (AC)
Specialized access conditions or extenuating circumstances do not exist. An attacker can expect repeatable success when attacking the vulnerable component.
Low
Privileges Required (PR)
The attacker is unauthorized prior to attack, and therefore does not require any access to settings or files of the vulnerable system to carry out an attack.
None
User Interaction (UI)
The vulnerable system can be exploited without interaction from any user.
None
Scope (S)
An exploited vulnerability can only affect resources managed by the same security authority. In this case, the vulnerable component and the impacted component are either the same, or both are managed by the same security authority.
Unchanged
Confidentiality (C)
There is some loss of confidentiality. Access to some restricted information is obtained, but the attacker does not have control over what information is obtained, or the amount or kind of loss is limited. The information disclosure does not cause a direct, serious loss to the impacted component.
Low
Integrity (I)
Modification of data is possible, but the attacker does not have control over the consequence of a modification, or the amount of modification is limited. The data modification does not have a direct, serious impact on the impacted component.
Low
Availability (A)
There is no impact to availability within the impacted component.
None