
Draytek 방화벽용 리버스 엔지니어링 및 옵저버빌리티 툴킷
고급 공격자들은 점점 더 엣지 디바이스를 표적으로 삼고 있습니다. 그러나 이러한 디바이스는 종종 독점 형식으로 배포되는 펌웨어로 알려진 폐쇄 소스 소프트웨어에 의해 제어됩니다. 이는 보안을 평가하기 위해 펌웨어를 추출하는 방법을 이해해야 하는 방어자와 연구자에게 추가적인 어려움을 의미합니다.
이는 단지 가상의 시나리오에 그치지 않습니다. 최근 고객이 침해 사고를 당했을 때 우리가 직접 경험했기 때문입니다. 고객 인프라의 가장자리에 Draytek 장비가 있었기에 자연스러운 질문이 떠올랐습니다. 이것이 공격자의 진입점이었을까? 50만 대 이상의 Draytek 디바이스가 인터넷에 노출되어 있습니다. 그런데도 이들의 펌웨어를 추출하고 이러한 디바이스를 다루는 연구자와 방어자를 돕는 작동 가능한 도구는 존재하지 않습니다.
평가 과정에서 우리는 Draytek의 펌웨어 형식을 리버스 엔지니어링했으며, 이 형식에는 부트로더, 압축된 RTOS 커널, 그리고 두 개의 파일시스템이 포함되어 있습니다. 조사를 통해 우리는 이러한 구성 요소를 추출하는 도구를 개발했고, 실시간 운영 체제가 코드 모듈을 동적으로 로드할 수 있는 기능을 밝혀냈습니다. 이러한 모듈은 부팅 중에 펌웨어 이미지의 파일시스템 중 하나에서 로드되지만, 시스템이 실행되는 동안 로드되어 플래시 메모리의 별도 파일시스템에 저장될 수도 있습니다. 공격자는 이 기능을 악용하여 재부팅이나 펌웨어 업그레이드 후에도 활성 상태를 유지하는 모듈을 로드함으로써 지속성을 달성할 수 있으며, 최종 사용자는 이러한 유형의 공격을 탐지할 방법이 없습니다. 결과적으로 우리는 메모리에 로드된 모듈의 무결성을 검사하는 자체 모듈을 개발하여 이 잠재적 위협을 완화했습니다.
더 안전한 인터넷을 추구하기 위해, 우리는 Draytek 엣지 디바이스에 대한 관찰 가능성, 보안 강화, 투명성, 취약점 연구를 가능하게 하는 이 도구 세트를 커뮤니티에 공개합니다.
이 도구는 DEFCON HHV and La Villa Hacker에서 발표된 연구 프로젝트의 일환으로 개발되었습니다. 슬라이드와 PoC 영상은 여기에서 확인할 수 있습니다.
우리는 처음에 이 도구를 내부 도구로 개발했습니다. 단지 스크립트 모음에 불과했지만 큰 잠재력을 보여주었고, 그래서 오픈소스로 공개하게 되었습니다. 그 이후로 우리는 이 스크립트들을 이 저장소에서 찾을 수 있는 Python 패키지로 통합하고 다른 디바이스 모델과도 호환되도록 작업하고 있습니다.
요구 사항:
(선택 사항) python 가상 환경을 생성하고 활성화합니다:
$ python3 -m virtualenv .venv
$ source .venv/bin.activate
draytek_arsenal 설치:
$ cd draytek_arsenal
$ python3 -m pip install -r requirements.txt
$ python3 -m pip install .
설치를 테스트합니다:
$ python3 -m draytek_arsenal
이 설치는 로컬 코드 변경 사항의 영향을 받습니다.
$ python3 -m pip install -e .
mips_compile 및 mips_merge와 같은 일부 명령은 작동하기 위해 보조 Docker 이미지가 필요합니다.
이미지가 다운로드되지 않은 경우 다음 오류 메시지가 표시됩니다:
[x] Image 'draytek-arsenal' not found. Please build or download the image.
다음 명령으로 이미지를 다운로드할 수 있습니다:
$ docker pull ghcr.io/infobyte/draytek-arsenal:main
또는 다음 명령으로 빌드할 수 있습니다:
$ docker build -t draytek-arsenal ./mips-tools
draytek-arsenal은 python 패키지로 수집된 스크립트 모음입니다. 따라서 사용하려면 명령을 선택해야 합니다:
usage: draytek-arsenal [-h] [command] args..
일부 명령은 다음과 같습니다:
Draytec 펌웨어를 파싱하고 정보를 표시합니다.
usage: parse_firmware [-h] firmware
positional arguments:
firmware Path to the firmware
options:
-h, --help show this help message and exit
RTOS를 실행하는 Draytek 기기를 추출하고 압축 해제하는 데 사용되는 명령입니다.
usage: extract_rtos [-h] [--rtos RTOS] [--fs FS] [--dlm DLM] [--dlm-key1 DLM_KEY1]
[--dlm-key2 DLM_KEY2]
firmware
positional arguments:
firmware Path to the firmware
options:
-h, --help show this help message and exit
--rtos RTOS, -r RTOS File path where to extract and decompress the RTOS
--fs FS, -f FS Directory path where to extract and decompress the File
System
--dlm DLM, -d DLM Directory path where to extract and decompress the DLMs
--dlm-key1 DLM_KEY1 First key used to decrypt DLMs
--dlm-key2 DLM_KEY2 First key used to decrypt DLMs
linux를 실행하는 Draytek 기기를 추출하고 압축 해제하는 데 사용되는 명령입니다.
usage: extract_linux [-h] [--fs FS] --key KEY firmware
positional arguments:
firmware Path to the firmware
options:
-h, --help show this help message and exit
--fs FS, -f FS Directory path where to extract and decompress the File System
--key KEY Key used to decrypt
DLM 모듈의 해시를 가져옵니다.
usage: dlm_hash [-h] [-c] dlm
positional arguments:
dlm Path to the dlm
options:
-h, --help show this help message and exit
-c Print as .c code
첫 번째 점프 명령으로 RTOS가 로드되는 주소를 찾습니다.
usage: find_loading_addr [-h] rtos
positional arguments:
rtos Path to the rtos
options:
-h, --help show this help message and exit
RTOS가 리틀 엔디언인지 빅 엔디언인지 확인합니다.
usage: find_endianness [-h] rtos
positional arguments:
rtos Path to the rtos
options:
-h, --help show this help message and exit
MIPS 재배치 가능 바이너리를 컴파일합니다(DLM에 사용됨).
usage: mips_compile [-h] output [input ...]
positional arguments:
output Output file
input Output file
options:
-h, --help show this help message and exit
두 개의 ELF MIPS 재배치 가능 파일을 병합합니다.
usage: mips_merge [-h] first_input second_input output
positional arguments:
first_input First input file
second_input Second input file
output Output file
options:
-h, --help show this help message and exit