Computer Science%/System

라우터 취약점 분석

ch4rli3kop 2020. 6. 14. 17:47
반응형

[BoB8_박찬희] HW#1 라우터 취약점 분석

Contents : 2019년 1월 이후 펌웨어에 대해서 Bug hunting 상세 보고서

Due : 01/31/2020 PM:10:00:00

Target

Firmware : Taiwan, China TL-WR940N(TW)_V6_191024

Date : 2019-12-25

실제 기기를 대상으로 분석을 진행하였음.

Prior Analysis

binwak

가장 먼저 파일 시그니처 기반의 파일 탐색 도구인 binwalk를 이용하여 해당 firmware에 대해 조사합니다.

ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25$ binwalk -AE wr940nv6_tw_3_18_1_up_boot\(191024\).bin 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
2944         0xB80           MIPS instructions, function epilogue
3252         0xCB4           MIPS instructions, function epilogue
3556         0xDE4           MIPS instructions, function epilogue
3876         0xF24           MIPS instructions, function epilogue
4220         0x107C         MIPS instructions, function epilogue
4320         0x10E0         MIPS instructions, function epilogue
4824         0x12D8         MIPS instructions, function epilogue
4988         0x137C         MIPS instructions, function epilogue
6000         0x1770         MIPS instructions, function epilogue
6160         0x1810         MIPS instructions, function epilogue
8876         0x22AC         MIPS instructions, function epilogue
9056         0x2360         MIPS instructions, function epilogue
9432         0x24D8         MIPS instructions, function epilogue
10724         0x29E4         MIPS instructions, function epilogue
11828         0x2E34         MIPS instructions, function epilogue
12156         0x2F7C         MIPS instructions, function epilogue
12248         0x2FD8         MIPS instructions, function epilogue
12556         0x310C         MIPS instructions, function epilogue
13264         0x33D0         MIPS instructions, function epilogue
13560         0x34F8         MIPS instructions, function epilogue

분석 결과 MIPS 기반의 firmware 인 것을 알 수 있습니다.

다음으로는 해당 firmware의 파일 시스템을 조사합니다. 마찬가지로 binwalk를 이용하여 조사를 진행합니다.

ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25$ binwalk -BE wr940nv6_tw_3_18_1_up_boot\(191024\).bin 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             TP-Link firmware header, firmware version: 0.-6339.3, image version: "", product ID: 0x0, product version: 155189254, kernel load address: 0x0, kernel entry point: 0x80002000, kernel offset: 4063744, kernel length: 512, rootfs offset: 865638, rootfs length: 917504, bootloader offset: 3014656, bootloader length: 0
15520         0x3CA0         U-Boot version string, "U-Boot 1.1.4 (Oct 24 2019 - 10:16:42)"
15568         0x3CD0         CRC32 polynomial table, big endian
16868         0x41E4         uImage header, header size: 64 bytes, header CRC: 0xEC8FB47D, created: 2019-10-24 02:16:43, image size: 42777 bytes, Data Address: 0x80010000, Entry Point: 0x80010000, data CRC: 0x7BE6CB68, OS: Linux, CPU: MIPS, image type: Firmware Image, compression type: lzma, image name: "u-boot image"
16932         0x4224         LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 113496 bytes
131584       0x20200         TP-Link firmware header, firmware version: 0.0.3, image version: "", product ID: 0x0, product version: 155189254, kernel load address: 0x0, kernel entry point: 0x80002000, kernel offset: 3932160, kernel length: 512, rootfs offset: 865638, rootfs length: 917504, bootloader offset: 3014656, bootloader length: 0
132096       0x20400         LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 2496140 bytes
1049088       0x100200       Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 2872419 bytes, 657 inodes, blocksize: 131072 bytes, created: 2019-10-24 02:26:47

분석결과 Squashfs 파일 시스템인 것을 알 수 있습니다.

Firmware-Mod-Kit

앞선 분석 결과들을 토대로 얻은 정보들을 살펴보면, 분석 대상은 MIPS instruction을 사용하고 Squashfs 파일 시스템을 사용하는 firmware입니다. Firmware-Mod-Kit은 해당 환경들을 모두 지원하는 이미지 extract, rebuild 도구입니다. Firmware-Mod-Kit을 설치하여 해당 도구로 분석을 진행합니다. Firmware-Mod-Kit에 대한 자세한 사항은 다음의 경로에서 확인할 수 있습니다. https://github.com/rampageX/firmware-mod-kit/wiki

Firmware-Mod-Kit을 이용하여 이미지 파일을 압축해제합니다.

ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25$ ~/firmware-mod-kit/extract-firmware.sh wr940nv6_tw_3_18_1_up_boot\(191024\).bin
Firmware Mod Kit (extract) 0.99, (c)2011-2013 Craig Heffner, Jeremy Collake

Scanning firmware...

Scan Time:     2020-01-30 23:25:34
Target File:   /home/ch4rli3kop/Desktop/tp-link-taiwan-2019-12-25/wr940nv6_tw_3_18_1_up_boot(191024).bin
MD5 Checksum: 912ff0a2d73548f475488d000f0dfbff
Signatures:    344

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             TP-Link firmware header, firmware version: 0.-6339.3, image version: "", product ID: 0x0, product version: 155189254, kernel load address: 0x0, kernel entry point: 0x80002000, kernel offset: 4063744, kernel length: 512, rootfs offset: 865638, rootfs length: 917504, bootloader offset: 3014656, bootloader length: 0
15520         0x3CA0         U-Boot version string, "U-Boot 1.1.4 (Oct 24 2019 - 10:16:42)"
15568         0x3CD0         CRC32 polynomial table, big endian
16868         0x41E4         uImage header, header size: 64 bytes, header CRC: 0xEC8FB47D, created: 2019-10-24 02:16:43, image size: 42777 bytes, Data Address: 0x80010000, Entry Point: 0x80010000, data CRC: 0x7BE6CB68, OS: Linux, CPU: MIPS, image type: Firmware Image, compression type: lzma, image name: "u-boot image"
16932         0x4224         LZMA compressed data, properties: 0x5D, dictionary size: 33554432 bytes, uncompressed size: 113496 bytes
...

extract 결과, 다음과 같이 firmware의 파일 시스템을 복구해주는 것을 확인할 수 있습니다.

ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25$ ls -al
total 3984
drwxr-xr-x 3 ch4rli3kop ch4rli3kop    4096 Jan 30 23:25 .
drwxr-xr-x 8 ch4rli3kop ch4rli3kop    4096 Jan 31 04:33 ..
drwxr-xr-x 5 ch4rli3kop ch4rli3kop    4096 Jan 30 23:25 fmk
-rwxrw-rw- 1 ch4rli3kop ch4rli3kop 4063744 Dec 17 01:16 'wr940nv6_tw_3_18_1_up_boot(191024).bin'
ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25$ cd fmk
ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25/fmk$ ls -al
total 20
drwxr-xr-x  5 ch4rli3kop ch4rli3kop 4096 Jan 30 23:25 .
drwxr-xr-x  3 ch4rli3kop ch4rli3kop 4096 Jan 30 23:25 ..
drwxr-xr-x  2 ch4rli3kop ch4rli3kop 4096 Jan 30 23:25 image_parts
drwxr-xr-x  2 ch4rli3kop ch4rli3kop 4096 Jan 30 23:25 logs
drwxrwxr-x 15 root       root       4096 Oct 23 19:26 rootfs

Analysis

TP-Link의 관리자 창 바이너리는 다음의 경로에 존재하는 httpd 파일입니다.

ch4rli3kop@ubuntu:~/Desktop/tp-link-taiwan-2019-12-25/fmk/rootfs/usr/bin$ file httpd
httpd: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, corrupted section header size

MIPS 파일이기 때문에 Ghidra를 이용해서 진행했습니다.

해당 바이너리를 분석해보면 우선 다음과 같이 다양한 .htm 파일을 통해 이루어진 것을 확인할 수 있습니다.

여러 기능들을 살펴본 결과 무선 공유기를 먹통으로 만드는 버그를 발견하였습니다.

사용자가 TP-Link에 정상적으로 로그인을 한 경우, 무선 카테고리에서 다음과 같은 항목을 볼 수 있습니다.

무선 네트워크 이름에서 특정 문자들을 입력한 뒤 저장 버튼을 누르는 경우 오류가 발생합니다.

Proxy 도구를 이용하여 살펴본 결과 WlanNetworkRpm.htm를 이용하여 SSID 파라미터를 가져오는 것을 확인할 수 있었습니다.

GET /JLSQVVVBVRNPEHPA/userRpm/WlanNetworkRpm.htm?ssid1=TP-Link_F1BC%5C&ssid2=TP-Link_GUEST_F1BC&ssid3=TP-Link_F1BC_3&ssid4=TP-Link_F1BC_4&region=111&band=0&mode=6&chanWidth=2&channel=15&rate=83&ap=1&broadcast=2&brlssid=&brlbssid=&addrType=1&keytype=1&wepindex=1&authtype=1&keytext=&Save=%EC%A0%80%EC%9E%A5 HTTP/1.1

만약 SSID 값에 ", ', \와 같은 특별한 문자들이 들어가게 된다면 다음과 같이 라우터의 서비스가 정상적으로 동작하지 않는 것을 확인할 수 있습니다.

FUN_0046dae0()

ssid를 파싱하는 동작은 FUN_0046dae0()에서 이루어집니다.

자세히 보면 0x5870f4 시작하므로 "ssid1"인 파라미터를 가져오게 됩니다. 가져온 값은 acStack388에 저장합니다.

acStack388writePageParamSet()에서 사용됩니다.



command injection...

execFormatCmd()


/bin/sh


반응형