
Linux 커널 TLS 하위 시스템용 CVE-2024-58239 익스플로잇으로, tcp_rcv_state_process의 이중 해제(double-free) 취약점을 통해 권한 상승을 달성합니다. 클라이언트-서버 아키텍처와 로컬 테스트 스크립트를 포함합니다.
제 첫 1-day 익스플로잇입니다.
패치: tls: 초기 process_rx_list가 non-DATA를 반환하면 recv() 중지
kernelCTF 스프레드시트에서 exp407을 보고 익스플로잇 재현을 시도했습니다.
kernelCTF 환경에서 익스플로잇을 실행하여 플래그를 획득할 수 있었습니다:

이에 대한 상세한 write-up은 나중에 작성하겠습니다.
익스플로잇 로그는 중간에 커널 WARNING이 있어서 다소 깁니다. 하지만 warning은 error가 아니며 익스플로잇을 죽이지도 않습니다 ;)

이 폴더에서 용량이 큰 파일들을 많이 제거했습니다.
./rootfs_v3.img./ramdisk_v1.img./releases/mitigation-v4-6.6/bzImage./releases/mitigation-v4-6.6/vmlinux처음 3개 파일은 원본 local_runner.sh를 실행하면 얻을 수 있습니다.
네 번째 파일과 소스 코드는 kernelCTF 서버에 접속하면 다운로드 링크를 받을 수 있습니다.
하지만 편의를 위해 mitigation-v4-6.6 인스턴스의 정보를 정리하면 다음과 같습니다:
Kernel image (bzImage): https://storage.googleapis.com/kernelctf-build/releases/mitigation-v4-6.6/bzImage
Kernel image (vmlinux): https://storage.googleapis.com/kernelctf-build/releases/mitigation-v4-6.6/vmlinux.gz
Kernel config: https://storage.googleapis.com/kernelctf-build/releases/mitigation-v4-6.6/.config
-> derived from COS config: https://storage.googleapis.com/kernelctf-build/releases/mitigation-v4-6.6/lakitu_defconfig
Source code info: https://storage.googleapis.com/kernelctf-build/releases/mitigation-v4-6.6/COMMIT_INFO
또한 .img 파일을 다운로드하는 명령어는 다음과 같습니다:
wget https://storage.googleapis.com/kernelctf-build/files/rootfs_v3.img.gz
gzip -d rootfs_v3.img.gz
wget https://storage.googleapis.com/kernelctf-build/files/ramdisk_v1.img
cd ./exploit/mitigation-v4-6.6/
make
이 익스플로잇은 2개의 부분으로 나뉩니다:
서버:
./server --port <port>
클라이언트:
./client --ip <server_ip> --port <port>
익스플로잇을 로컬에서 테스트하기 위해 스크립트 2개를 작성했습니다:
이 스크립트는 서버를 백그라운드에서 시작한 다음 qemu VM에서 클라이언트를 실행합니다.
먼저 exploit/mitigation-v4-6.6 디렉터리로 이동하여 3000 포트에서 http 서버를 시작합니다. 이후 qemu VM으로 익스플로잇을 다운로드하기 위함입니다.
cd exploit/mitigation-v4-6.6
python3 -m http.server 3000
그런 다음 다른 터미널에서 스크립트를 실행합니다:
python3 test.py <your_ip> <port>
<your_ip>는 네트워크 카드의 IP입니다. 저의 경우 전체를 WSL에서 실행하며, ip a를 실행해 eth0 인터페이스의 IP인 172.30.248.93을 얻었습니다.➜ CVE-2024-58239 git:(main) ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 10.255.255.254/32 brd 10.255.255.254 scope global lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:22:a0:d1 brd ff:ff:ff:ff:ff:ff
inet 172.30.248.93/20 brd 172.30.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fe22:a0d1/64 scope link
valid_lft forever preferred_lft forever
<port>는 로컬 머신에서 사용하지 않는 임의의 포트입니다. 클라이언트와 서버 간 TLS 연결에 사용됩니다.이 스크립트는 익스플로잇을 여러 번 실행하여 성공률을 측정합니다.
test.py 사용법과 마찬가지로 exploit/mitigation-v4-6.6 디렉터리로 이동하여 3000 포트에서 http 서버를 시작합니다. 이후 qemu VM으로 익스플로잇을 다운로드하기 위함입니다.
cd exploit/mitigation-v4-6.6
python3 -m http.server 3000
python3 calc_AC_rate.py <your_ip> <port> <number_of_time_to_run>
예를 들어, 제 WSL에서는 python3 calc_AC_rate.py 172.30.248.93 1118 100으로 실행합니다.
현재 성공률이 다소 불안정해서 아직 개선 작업 중입니다.
calc_AC_rate.py를 실행해 익스플로잇을 100회 테스트했고, 결과는 50/100입니다.
실패한 시도는 중간에 common_interrupt가 나타나 커널 slab의 단순한 double free 탐지를 트리거했기 때문이며, 이는 다음 백트레이스에서 확인할 수 있습니다.
이를 비활성화할 방법을 찾아보겠습니다.
[ 4.050330] ? die+0x32/0x80
[ 4.050809] ? do_trap+0xd6/0x100
[ 4.051365] ? __slab_free+0x16c/0x380
[ 4.052198] ? do_error_trap+0x6a/0x90
[ 4.052767] ? __slab_free+0x16c/0x380
[ 4.053350] ? exc_invalid_op+0x4c/0x60
[ 4.053916] ? __slab_free+0x16c/0x380
[ 4.055031] ? asm_exc_invalid_op+0x16/0x20
[ 4.055675] ? tcp_rcv_state_process+0x791/0xef0
[ 4.056527] ? __slab_free+0x16c/0x380
[ 4.057097] ? lock_timer_base+0x61/0x80
[ 4.057795] ? tcp_get_metrics+0x142/0x380
[ 4.058560] ? tcp_rcv_state_process+0x791/0xef0
[ 4.059265] kmem_cache_free+0x599/0x5e0
[ 4.059915] tcp_rcv_state_process+0x791/0xef0
[ 4.060918] ? security_sock_rcv_skb+0x31/0x50
[ 4.061857] ? sk_filter_trim_cap+0x11a/0x290
[ 4.062558] tcp_v4_do_rcv+0xcd/0x280
[ 4.063281] tcp_v4_rcv+0xf81/0x1010
[ 4.063832] ? raw_local_deliver+0xcd/0x250
[ 4.064668] ip_protocol_deliver_rcu+0x32/0x320
[ 4.065355] ip_local_deliver_finish+0x7a/0xa0
[ 4.066455] ip_sublist_rcv_finish+0x7e/0x90
[ 4.067231] ip_sublist_rcv+0x1e1/0x220
[ 4.067919] ? __netif_receive_skb_core.constprop.0+0xbf/0x1080
[ 4.068822] ip_list_rcv+0x139/0x170
[ 4.069362] __netif_receive_skb_list_core+0x29d/0x2c0
[ 4.070173] ? __pfx_csum_block_add_ext+0x10/0x10
[ 4.071054] netif_receive_skb_list_internal+0x1e1/0x310
[ 4.072068] napi_complete_done+0x6e/0x1a0
[ 4.072752] virtnet_poll+0x40d/0x5a0
[ 4.073313] __napi_poll+0x28/0x1c0
[ 4.073854] net_rx_action+0x14c/0x2d0
[ 4.074622] ? vp_vring_interrupt+0x73/0x90
[ 4.075746] __do_softirq+0xf6/0x30f
[ 4.076379] __irq_exit_rcu+0x79/0xc0
[ 4.077356] common_interrupt+0xb9/0xd0