Description
An attacker was able to achieve code execution in the content process by exploiting a use-after-free in Animation timelines. This vulnerability affects Firefox < 131.0.2, Firefox ESR < 128.3.1, Firefox ESR < 115.16.1, Thunderbird < 131.0.1, Thunderbird < 128.3.1, and Thunderbird < 115.16.0
Use-After-Free와 Dangling Pointer
- Use-After-Free: 동적으로 할당된 메모리를 해제한 후, 해당 메모리를 가리키고 있는 포인터를 NULL로 초기화하지 않으면 해제된 메모리를 재사용할 수 있게 됩니다. 이는 보안 취약점으로 이어질 수 있습니다.
- Dangling Pointer: 해제된 메모리를 참조하는 포인터입니다. 이러한 포인터가 존재하면 Type Confusion이 발생할 수 있으며, 이는 Local Privilege Escalation(LPE)이나 Remote Code Execution(RCE) 공격으로 이어질 수 있습니다.
Senario
아래의 코드는 Use-After-Free를 의도적으로 발생시킨 코드입니다. 코드의 순서는 다음과 같습니다.
Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int *tmp = NULL;
tmp = (int *)malloc(0x10); // 16바이트 메모리 할당
memset(tmp, 0, 0x10); // 할당된 메모리를 0으로 초기화
tmp[0] = 1; // 첫 번째 요소에 1 저장
tmp[1] = 2; // 두 번째 요소에 2 저장
printf("tmp[0] @ %d\n", tmp[0]); // 첫 번째 요소 출력
free(tmp); // 메모리 해제
char *str = NULL;
str = (char *)malloc(0x10); // 16바이트 메모리 할당
memset(str, 0, 0x10); // 할당된 메모리를 0으로 초기화
memcpy(str, "hello", 5); // "hello" 문자열을 복사
printf("tmp @ %s\n", tmp); // 해제된 메모리 참조 (Use-After-Free)
return 0;
}
Output
tmp[0] @ 1
tmp @ hello
두 번째 tmp 포인터를 출력했을 때 "hello" 문자열이 출력된 이유는 Heap이 효율적인 메모리 관리를 위해서, 새로 할당하고자 하는 공간의 크기를 확인 후 해제된 공간 중 현재 할당하고자 하는 크기와 같은 공간이 있다면, 해당 공간을 재사용하기 때문입니다.
따라서 tmp가 16바이트로 할당되고 해제된 후에 str이 16바이트로 메모리 할당이 되었는데 같은 공간을 참조하게 되어 두 번째 printf가 "hello"를 출력하게 됩니다.
악용 가능성
- Memory Reallocation: 메모리가 해제된 후 공격자가 해제된 메모리에 배치되는 데이터를 제어할 수 있다면 프로그램이 원래 데이터 대신에 새로운 데이터를 사용하도록 할 수 있습니다.
- Code Injection: 메모리 위치에 악성 코드를 주입하여 프로그램의 흐름을 탈취하여 원격 코드 실행 및 권한 상승으로 이어질 수 있습니다.
방지 방법
- 해제 후 포인터를 NULL로 설정: 메모리를 해제한 후 포인터를 NULL로 설정하여 다시 참조하지 않도록 합니다.
- Smart Pointers: C++에서는 스마트 포인터(예: std::unique_ptr, std::shared_ptr)를 사용하여 메모리 관리를 자동화할 수 있습니다.
CVE-2024-9680
CVE-2024-9680은 CSS Animation Timeline에서 발생하였습니다. CSS Animation Timeline은 웹 페이지에서 애니메이션의 타이밍을 제어하는 역할을 하는 구성 요소입니다. 그러나 애니메이션 타임라인에 연결된 객체가 해제되었음에도 불구하고 여전히 사용되면서, 이는 보안 취약점으로 이어지게 되었습니다.
취약점 매커니즘
1. CSS Animation Timeline의 역할
Firefox의 CSS 애니메이션 타임라인은 애니메이션의 타이밍과 진행을 조정하는 역할을 합니다. 기본적으로 애니메이션이 키프레임에서 시작, 중지 및 전환되는 시기와 방법을 관리합니다. 애니메이션이 업데이트되거나 쿼리될 때마다 브라우저는 타임라인과 관련된 객체를 가져와서 조작해야 합니다.
2. 잘못된 객체 처리
CSS 애니메이션 타임라인을 Firefox에서 처리하는 데 결함이 있어, 애니메이션이 진행되는 동안 필요한 객체가 해제되었고, 이는 보호되어야 할 객체가 조기에 해제되는 결과를 초래했습니다. 해제된 메모리 공간에 대한 참조가 남아있게 되면서 Use-After-Free 조건이 발생하게 됩니다.
3. 공격자 제어
공격자는 이 취약점을 악용하기 위해 CSS 애니메이션을 트리거하는 악성 웹 페이지를 만들 수 있습니다. 타임라인에 연결된 메모리가 해제된 후, 공격자는 해당 메모리 공간을 제어된 데이터로 덮어쓸 수 있습니다. 이 과정에서 공격자가 삽입한 데이터를 CSS 애니메이션 타임라인이 참조하게 되면, 원격 코드 실행(RCE), 브라우저 충돌, 또는 기타 의도치 않은 동작이 발생할 수 있습니다.
예제 코드
이 코드에서는 애니메이션 클래스를 빠르게 추가하고 제거하여 브라우저가 객체 생성 및 파괴를 반복적으로 처리하도록 강제합니다. 이 과정에서 애니메이션 객체를 추적하는 방법에 결함이 있을 경우, 브라우저가 메모리를 부적절하게 관리하여 취약점이 발생할 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<style>
@keyframes exampleAnimation {
from { opacity: 0; }
to { opacity: 1; }
}
.animate {
animation: exampleAnimation 5s infinite;
}
</style>
</head>
<body>
<div id="targetElement" class="animate">Animating Element</div>
<script>
// Example setup: A function that continuously creates and destroys animations
// The goal here is to simulate rapid, repeated manipulations of the CSS animation timeline
function triggerVulnerability() {
const target = document.getElementById('targetElement');
// Create an animation, then remove it quickly in a loop
let i = 0;
const interval = setInterval(() => {
i++;
if (i % 2 === 0) {
target.classList.add('animate');
} else {
target.classList.remove('animate');
}
// Potentially causing a race condition or triggering the vulnerability
if (i > 1000) {
clearInterval(interval);
}
}, 1); // Rapid manipulation of the animation state
}
// Simulating dynamic DOM manipulation and timeline interaction
triggerVulnerability();
</script>
</body>
</html>
참조
https://nvd.nist.gov/vuln/detail/CVE-2024-9680
NVD - CVE-2024-9680
CVE-2024-9680 Detail Description An attacker was able to achieve code execution in the content process by exploiting a use-after-free in Animation timelines. We have had reports of this vulnerability being exploited in the wild. This vulnerability affects
nvd.nist.gov
https://cwe.mitre.org/data/definitions/416.html
CWE - CWE-416: Use After Free (4.15)
div.collapseblock { display:inline} Weakness ID: 416Vulnerability Mapping: ALLOWEDThis CWE ID may be used to map to real-world vulnerabilitiesAbstraction: VariantVariant - a weakness that is linked to a certain type of product, typically involving a specif
cwe.mitre.org
https://github.com/tdonaworth/Firefox-CVE-2024-9680?tab=readme-ov-file#exploitation-potential
GitHub - tdonaworth/Firefox-CVE-2024-9680
Contribute to tdonaworth/Firefox-CVE-2024-9680 development by creating an account on GitHub.
github.com