CVE-2019-8662 : Detail

CVE-2019-8662

9.8
/
Critical
Memory Corruption
A08-Soft and Data Integrity Fail
16.01%V4
Network
2019-12-18
16h33 +00:00
2019-12-18
16h33 +00:00
Notifications for a CVE
Stay informed of any changes for a specific CVE.
Notifications manage

CVE Descriptions

This issue was addressed with improved checks. This issue is fixed in iOS 12.4, macOS Mojave 10.14.6, tvOS 12.4, watchOS 5.3. An attacker may be able to trigger a use-after-free in an application deserializing an untrusted NSDictionary.

CVE Informations

Related Weaknesses

CWE-ID Weakness Name Source
CWE-416 Use After Free
The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer.
CWE-502 Deserialization of Untrusted Data
The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.

Metrics

Metrics Score Severity CVSS Vector Source
V3.1 9.8 CRITICAL CVSS:3.1/AV:N/AC:L/PR:N/UI:N/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

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).

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 when attacking 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 of the vulnerable system to carry out an attack.

User Interaction

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

None

The vulnerable system can be exploited without interaction from any user.

Base: Scope Metrics

The Scope metric captures whether a vulnerability in one vulnerable component impacts resources in components beyond its security scope.

Scope

Formally, a security authority is a mechanism (e.g., an application, an operating system, firmware, a sandbox environment) that defines and enforces access control in terms of how certain subjects/actors (e.g., human users, processes) can access certain restricted objects/resources (e.g., files, CPU, memory) in a controlled manner. All the subjects and objects under the jurisdiction of a single security authority are considered to be under one security scope. If a vulnerability in a vulnerable component can affect a component which is in a different security scope than the vulnerable component, a Scope change occurs. Intuitively, whenever the impact of a vulnerability breaches a security/trust boundary and impacts components outside the security scope in which vulnerable component resides, a Scope change occurs.

Unchanged

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.

Base: Impact Metrics

The Impact metrics capture the effects of a successfully exploited vulnerability on the component that suffers the worst outcome that is most directly and predictably associated with the attack. Analysts should constrain impacts to a reasonable, final outcome which they are confident an attacker is able to achieve.

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 a 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 a 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 in the description of a vulnerability.

Environmental Metrics

These metrics enable the analyst to customize the CVSS score depending on the importance of the affected IT asset to a user’s organization, measured in terms of Confidentiality, Integrity, and Availability.

nvd@nist.gov
V2 7.5 AV:N/AC:L/Au:N/C:P/I:P/A:P 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 : 47608

Publication date : 2019-11-10 23h00 +00:00
Author : Google Security Research
EDB Verified : Yes

During processing of incoming iMessages, attacker controlled data is deserialized using the NSUnarchiver API. One of the classes that is allowed to be decoded from the incoming data is NSDictionary. However, due to the logic of NSUnarchiver, all subclasses of NSDictionary that also implement secure coding can then be deserialized as well. NSSharedKeyDictionary is an example of such a subclass. A NSSharedKeyDictionary is a dictionary for which, for performance reasons, the keys are predefined using a NSSharedKeySet. A NSSharedKeyDictionary is essentially a linear array of values and a pointer to its NSSharedKeySet. An NSSharedKeySet on the other hand looks roughly like this (with some fields omitted for simplicity and translated to pseudo-C): struct NSSharedKeySet { unsigned int _numKeys; // The number of keys in the _keys array id* _keys; // A pointer to an array containing the key values unsigned int _rankTable; // A table basically mapping the hashes of // the keys to an index into _keys unsigned int _M; // The size of the _rankTable unsigned int _factor; // Used to compute the index into _rankTable from a hash. NSSharedKeySet* _subKeySet; // The next KeySet in the chain }; The value lookup on an NSSharedKeyDictionary then works roughly as follows: * NSSharedKeyDictionary invokes [NSSharedKeySet indexForKey:] on its associated keySet * indexForKey: computes the hash of the key, basically computes rti = hash % _factor, bounds-checks that against _M, and finally uses it to lookup the index in its rankTable: idx = _rankTable[rti] * It verifies that idx < _numKeys * It loads _keys[idx] and invokes [key isEqual:candidate] with it as argument * If the result is true, the index has been found and is returned to the NSSharedKeyDictionary where it is used to index into its values array * If not, indexForKey: recursively processes the subKeySet in the same way until it either finds the key or there is no subKeySet left, in which case it returns -1 The NSArchiver format is powerful enough to allow reference cycles between decoded objects. This now enables the following attack: SharedKeyDictionary1 --[ keySet ]-> SharedKeySet1 --[ subKeySet ]-> SharedKeySet2 --+ ^ | | [ subKeySet ] | | +-----------------------------------------+ What will happen now is the following: * The SharedKeyDictionary1 is decoded and its initWithCoder: executed * [NSSharedKeyDictionary initWithCoder:] decodes its _keySet, which is SharedKeySet1 * The [NSSharedKeySet initWithCoder:] for SharedKeyDictionary1 reads and initializes the following fields: * _numKeys, which at this point is unchecked and can be any unsigned integer value. Only later will it be checked to be equal to the number of keys in the _keys array. * _rankTable, with completely attacker controlled content * _M, which must be equal to the size of the _rankTable * _factor, which must be a prime but otherwise can be arbitrarily chosen At this point, _numKeys = 0xffffffff but _keys is still nullptr (because ObjC objects are allocated with calloc) * Next, *before* initializing _keys, it deserializes the _subKeySet, SharedKeySet2 * [NSSharedKeySet initWithCoder:] of SharedKeySet2 finishes, and at the end verifies that it is a valid SharedKeySet. It does that by checking that all its keys correctly map to an index. For that it calls [NSSharedKeySet indexForKey:] on itself for every key. * (At least) one of the keys will, however, not be found on SharedKeySet2. As such, indexForKey: will proceed to search for the key in its _subKeySet, which is actually SharedKeySet1 * The lookup proceeds and determines that the index should be (in our case) 2189591170, which is less than SharedKeySet1->numKey (which is still 0xffffffff) * It then loads SharedKeySet1->keys[2189591170], which, as ->_keys is still nullptr, reads an objc_object* from 0x414141410 and thus crashes The attached PoC demonstrates this on the latest macOS 10.14.6 > clang -o tester tester.m -framework Foundation > ./generator.py > lldb -- ./tester payload.xml (lldb) target create "./tester" Current executable set to './tester' (x86_64). (lldb) settings set -- target.run-args "payload.xml" (lldb) r 2019-07-29 15:40:28.989305+0200 tester[71168:496831] Let's go Process 71168 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x414141410) frame #0: 0x00007fff3390d3e7 CoreFoundation`-[NSSharedKeySet indexForKey:] + 566 CoreFoundation`-[NSSharedKeySet indexForKey:]: -> 0x7fff3390d3e7 <+566>: mov rdx, qword ptr [rax + 8*r13] Combined with a heap spray, this bug could likely be remotely exploitable. Ideally, this issue and similar ones can be prevented by removing the NSSharedKeyDictionary attack surface completely, as originally suggested by Natalie. Alternatively, I think another solution might be to stop encoding all the internal fields of the NSSharedKeyDictionary/NSSharedKeySet (rankTable, numKeys, especially the subKeySet, ...) and only encode the keys and values. The new [initWithCoder:] implementations could then just call +[NSSharedKeySet keySetWithKeys:] and +[NSSharedKeyDictionary sharedKeyDictionaryWithKeySet:] to construct new instances with the decoded keys and values. This should be fine as all the other fields are implementation details anyway. Proof of Concept: https://gitlab.com/exploit-database/exploitdb-bin-sploits/-/raw/main/bin-sploits/47608.zip
Exploit Database EDB-ID : 47189

Publication date : 2019-07-29 22h00 +00:00
Author : Google Security Research
EDB Verified : Yes

When deserializing NSObjects with the NSArchiver API [1], one can supply a whitelist of classes that are allowed to be unarchived. In that case, any object in the archive whose class is not whitelisted will not be deserialized. Doing so will also cause the NSKeyedUnarchiver to "requireSecureCoding", ensuring that the archived classes conform to the NSSecureCoding protocol before deserializing them. With that, deserialization of untrusted archives is expected to now be possible in a secure manner. However, a child class of a class in the whitelist will also be deserialized by NSKeyedUnarchiver if one of the following is true (see -[NSCoder _validateAllowedClass:forKey:allowingInvocations:] in Foundation.framework for the exact logic): * It implements initWithCoder: and supportsSecureCoding, and calling the supportsSecureCoding method returns true * It doesn't implement initWithCoder and the first superclass that implements initWithCoder: also implements supportsSecureCoding which returns true In the latter case, deserializing such an object will invoke initWithCoder: of the superclass, which may then end up invoking methods of the child class. One such example is OITSUIntDictionary from the OfficeImport framework. This class inherits from NSDictionary, whose initWithCoder: will be called during unarchiving. Then the following happens: * initWithCoder invokes initWithCapacity: with the number of key-value pairs in the archive. This ends up calling -[OITSUIntDictionary initWithCapacity:] which sets the backing storage for the dict to the result of `CFDictionaryCreateMutable(0LL, v3, 0LL, 0LL)`. Note that neither key- nor value callbacks are provided (arguments #3 and #4). As such, elements stored in the dictionary will not be retained. Presumably, this is because the dictionary is only supposed to store integers which are not reference counted * Next, initWithCoder invokes setObject:forKey for each key-value pair of the archive. This will now store the keys and values in the OITSUIntDictionary *without* retaining them, thus their refcount will still be 1 and they are only kept alive by the NSKeyedUnarchiver instance * Unarchiving finishes, the NSKeyedUnarchiver is destroyed and it releases all its references to the deserialized objects. These objects are then freed and the deserialized OITSUIntDictionary now contains stale pointers. Accessing the elements of the deserialized dictionary then leads to use-after-free issues. The OfficeImport library appears to be loaded by the QuickLook.framework on demand (in _getOfficeImportLibrary()), and QuickLook is loaded into the Springboard process. As such, there might be scenarios in which OfficeImport is loaded in Springboard, making this bug remotely triggerable via iMessage without any user interaction. In any case, any process that has the OfficeImport library loaded and deserializes untrusted NSDictionaries is vulnerable even if secureCoding is enforced during unarchiving. These type of bugs can be found somewhat automatically: the attached IDAPython script, when run in IDA Pro with the iOS dyld_shared_cache loaded, will enumerate all system libraries and determine classes that inherit from one of the whitelisted classes. It then writes a list of all candidates (classes that are allowed to be deserialized by NSKeyedUnarchiver with the whitelists present in iMessage parsing) to disk. Afterwards, these classes can be unarchived by first archiving a valid parent class (e.g. NSDictionary) and replacing the name of the parent class with the name of the child class in the serialized archive, then deserializing the archive again and invoking a few common methods on the resulting object, e.g. "count" or "objectForKey:". With that, the program will potentially crash when deserializing buggy child classes (as is the case for PFArray and OITSUIntDictionary). The attached archiveDict.m program can generate a valid NSDictionary archive, which can then be converted to xml format for easier editing with `plutil -convert xml1 archive`. unarchiveDict.m can afterwards deserialize the archive again into an NSDictionary instance. This approach, however, requires that all libraries loaded in the target process are also loaded in unarchiveDict, or else some of the classes won't be found and can thus not be deserialized. Proof of Concept: https://gitlab.com/exploit-database/exploitdb-bin-sploits/-/raw/main/bin-sploits/47189.zip

Products Mentioned

Configuraton 0

Apple>>Iphone_os >> Version To (excluding) 12.4

Apple>>Mac_os_x >> Version To (excluding) 10.14.6

Apple>>Tvos >> Version To (excluding) 12.4

Apple>>Watchos >> Version To (excluding) 5.3

References