
html2xhtml의 Out-Of-Bounds Read : CVE-2022-44311
Html2xhtml v1.3에서 함수 static void elm_close(tree_node_t *nodo) (procesador.c)에 Out-Of-Bounds 읽기 취약점이 발견되었습니다. 이 취약점을 통해 공격자는 조작된 html 파일을 사용하여 민감한 파일에 접근하거나 서비스 거부(DoS)를 일으킬 수 있습니다.
CWE-125 Out-of-Bounds Read는 메모리에서 데이터를 읽을 때 발생할 수 있는 소프트웨어 오류 유형입니다. 예를 들어 프로그램이 배열의 끝을 넘어 읽으려고 할 때 발생할 수 있습니다. Out-of-bounds 읽기는 충돌이나 기타 예기치 않은 취약점으로 이어질 수 있으며, 공격자가 접근해서는 안 되는 민감한 정보를 읽을 수 있게 할 수 있습니다.
html2xhtml/src/procesador.c의 Out of Bounds 읽기 (GHSA-28fm-qh2h-3mch)Html2xhtml은 HTML 파일을 XHTML 파일로 변환하는 명령줄 도구입니다. Html2xhtml은 다음 문서 유형 중 하나를 준수하는 XHTML 출력을 생성할 수 있습니다: XHTML 1.0 (Transitional, Strict 및 Frameset), XHTML 1.1, XHTML Basic 및 XHTML Mobile Profile.
이 취약점은 -t frameset 옵션을 사용할 때 발생하는 세그폴트 오류로 인해 발견되었습니다. 세그멘테이션 폴트 또는 segfault는 자신에게 속하지 않은 메모리에 접근하여 발생하는 특정 종류의 오류입니다. 이는 메모리 손상을 막고 디버깅하기 어려운 메모리 버그를 방지하는 도우미 메커니즘입니다.
Valgrind(C 및 C++ 프로그램에서 힙 메모리(동적으로 new 또는 malloc으로 할당된 메모리)에 대한 메모리 접근 오류를 찾는 도구)를 사용하여 세그폴트 오류를 디버깅한 결과 테스트 케이스에서 invalid read of size 4가 보고되었습니다:
==1040381== Memcheck, a memory error detector
==1040381== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1040381== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==1040381== Command: ./src/html2xhtml -t frameset report/vuln/id:000000,sig:11,src:001386+001369,time:12081510,execs:2336913,op:splice,rep:16
==1040381==
==1040381== Invalid read of size 4
==1040381== at 0x40E911: elm_close (procesador.c:944)
==1040381== by 0x410617: err_html_struct (procesador.c:1889)
==1040381== by 0x40F20A: err_content_invalid (procesador.c:0)
==1040381== by 0x40F20A: elm_close (procesador.c:959)
==1040381== by 0x40E7C4: saxEndDocument (procesador.c:233)
==1040381== by 0x40DF7A: main (html2xhtml.c:117)
==1040381== Address 0x6f20d4 is not stack'd, malloc'd or (recently) free'd
==1040381==
==1040381==
==1040381== Process terminating with default action of signal 11 (SIGSEGV)
==1040381== Access not within mapped region at address 0x6F20D4
==1040381== at 0x40E911: elm_close (procesador.c:944)
==1040381== by 0x410617: err_html_struct (procesador.c:1889)
==1040381== by 0x40F20A: err_content_invalid (procesador.c:0)
==1040381== by 0x40F20A: elm_close (procesador.c:959)
==1040381== by 0x40E7C4: saxEndDocument (procesador.c:233)
==1040381== by 0x40DF7A: main (html2xhtml.c:117)
==1040381== If you believe this happened as a result of a stack
==1040381== overflow in your program's main thread (unlikely but
==1040381== possible), you can try to increase the size of the
==1040381== main thread stack using the --main-stacksize= flag.
==1040381== The main thread stack size used in this run was 8388608.
==1040381==
==1040381== HEAP SUMMARY:
==1040381== in use at exit: 88,190 bytes in 13 blocks
==1040381== total heap usage: 22 allocs, 9 frees, 2,218,413 bytes allocated
==1040381==
==1040381== LEAK SUMMARY:
==1040381== definitely lost: 0 bytes in 0 blocks
==1040381== indirectly lost: 0 bytes in 0 blocks
==1040381== possibly lost: 0 bytes in 0 blocks
==1040381== still reachable: 88,190 bytes in 13 blocks
==1040381== suppressed: 0 bytes in 0 blocks
==1040381== Rerun with --leak-check=full to see details of leaked memory
==1040381==
==1040381== For lists of detected and suppressed errors, rerun with: -s
==1040381== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==1040419== Memcheck, a memory error detector
Valgrind의 오류 로그를 통해 세그폴트가 발생한 다음 함수를 찾을 수 있었습니다:

함수에 타입 검사가 누락된 것으로 확인되었습니다. 사용자가 element 대신 comment 타입의 노드를 함수에 전달하여 out of bound 읽기 오류가 발생했습니다. 사용자는 ELM_PTR(nodo).contenttype[doctype]이 유효하지 않은 잘못된 형식의 문서를 제공할 수 있으며, 이로 인해 어셈블리에서 다음과 같은 비교가 발생합니다:
cmp dword ptr [rbp + rax*4 + 0xc], 4
공격자는 이 취약점을 활용하여 조작된 파일을 통해 민감한 파일, 메모리 또는 위치를 읽을 수 있습니다.
| 심각도 | 높음 8.1 / 10 |
|---|
| 공격 복잡성 | 낮음 |
| 필요한 권한 | 없음 |
| 사용자 상호작용 | 필요 |
| 범위 | 변경되지 않음 |
| 기밀성 | 높음 |
| 무결성 | 없음 |
| 가용성 | 높음 |