我們一起聊聊UPNP和DLNA協(xié)議
前言
沒有情情愛愛,只有技術(shù)相伴,給大家分享一下UPnP和DLNA協(xié)議;
UPnP的概念
通用即插即用(英語:Universal Plug and Play,簡稱UPnP)是由“通用即插即用論壇”(UPnP? Forum)推廣的一套網(wǎng)絡(luò)協(xié)議。該協(xié)議的目標是使家庭網(wǎng)絡(luò)(數(shù)據(jù)共享、通信和娛樂)和公司網(wǎng)絡(luò)中的各種設(shè)備能夠相互無縫連接,并簡化相關(guān)網(wǎng)絡(luò)的實現(xiàn)。UPnP通過定義和發(fā)布基于開放、因特網(wǎng)通訊網(wǎng)協(xié)議標準的UPnP設(shè)備控制協(xié)議來實現(xiàn)這一目標。 UPnP這個概念是從即插即用(Plug-and-play)派生而來的,即插即用是一種熱拔插技術(shù)。
通俗點講目前一般都用在路由器上面,如下截圖所示;
關(guān)于UPnP協(xié)議棧;
關(guān)于UPnP工作流程
1.尋址
DHCP協(xié)議;
2.發(fā)現(xiàn)
使用的是SSDP協(xié)議,這是一個工作在UDP上的HTTP協(xié)議;
3.描述
通過掃描端口,遍歷路徑,可以發(fā)現(xiàn)路由器的UPnP服務(wù)接口;當然每家廠商有自己的固定路徑后綴,也可以網(wǎng)上搜索;
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType> //設(shè)備類型,格式為:“urn:schemas-upnp-org:device:deviceType:v”,這里deviceType和v是由設(shè)備定義的。
<presentationURL>http://192.168.0.1:80</presentationURL>
<friendlyName>Wireless N Router MW313R</friendlyName> //一個更加友好的設(shè)備名
<manufacturer>MERCURY</manufacturer> //制造商
<manufacturerURL>http://www.mercurycom.com.cn</manufacturerURL>
<modelDescription>MW313R 5.0</modelDescription>
<modelName>MW313R</modelName>
<modelNumber>5.0</modelNumber>
<UDN>uuid:upnp-InternetGatewayDevice-4D5A5C269D27</UDN> //設(shè)備的UUID
<UPC>123456789001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
<controlURL>/l3f</controlURL> //用于控制的URL
<eventSubURL>/l3f</eventSubURL> //用于訂閱事件的URL
<SCPDURL>/l3f.xml</SCPDURL> //服務(wù)描述的URL
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>WAN Device</friendlyName>
<manufacturer>MERCURY</manufacturer>
<manufacturerURL>http://www.mercurycom.com.cn</manufacturerURL>
<modelDescription>WAN Device</modelDescription>
<modelName>WAN Device</modelName>
<modelNumber>1.0</modelNumber>
<modelURL></modelURL>
<serialNumber>12345678900001</serialNumber>
<UDN>uuid:upnp-WANDevice-4D5A5C269D27</UDN>
<UPC>123456789001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceId>
<controlURL>/ifc</controlURL>
<eventSubURL>/ifc</eventSubURL>
<SCPDURL>/ifc.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WAN Connection Device</friendlyName>
<manufacturer>MERCURY</manufacturer>
<manufacturerURL>http://www.mercurycom.com.cn</manufacturerURL>
<modelDescription>WAN Connection Device</modelDescription>
<modelName>WAN Connection Device</modelName>
<modelNumber>1</modelNumber>
<modelURL></modelURL>
<serialNumber>12345678900001</serialNumber>
<UDN>uuid:upnp-WANConnectionDevice-4D5A5C269D27</UDN>
<UPC>123456789001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConnection</serviceId>
<controlURL>/ipc</controlURL>
<eventSubURL>/ipc</eventSubURL>
<SCPDURL>/ipc.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>
4.控制
使用SOAP協(xié)議來完成控制;
5.事件
通過返回xml消息,使用GENA格式;
UPnP相關(guān)測試
miranda
了解到原來kali是自帶這個工具,但是新版本刪掉了,找到了github的源文件,可以使用;https://github.com/0x90/miranda-upnp;
沒太清楚為什么新版kali刪掉這個工具,但是了解下來,UPnP基本上路由器都會默認開啟,雖然UPnP協(xié)議沒有任何身份驗證機制,但是實際利用場景還是比較弱,如果路由器是公網(wǎng)ip還說可以建一條出網(wǎng)的通道,一般來說路由器是局域網(wǎng)ip,然后能開啟的場景下也就已經(jīng)進入內(nèi)網(wǎng)了,其他出網(wǎng)的辦法也很多,UPnP協(xié)議也只是建一條轉(zhuǎn)發(fā)路由,前提還得是轉(zhuǎn)發(fā)的ip存在問題;
掃描模式:
- pcap:被動發(fā)現(xiàn)設(shè)備通過嗅探設(shè)備接入網(wǎng)絡(luò)時發(fā)送的NOTIFY消息獲取設(shè)備信息。
- msearch:通過主動發(fā)送M-serach消息來發(fā)現(xiàn)設(shè)備。(一般使用msearch比較快) 測試下來,我是msearch發(fā)現(xiàn)不了,但是用msearch掃描了一段時間后,切pcap就可以立馬出現(xiàn)結(jié)果;
信息獲取
發(fā)現(xiàn)設(shè)備后可用host命令來查看詳細信息。
- host list:查看發(fā)現(xiàn)的設(shè)備列表;
- host get:獲取信息(查詢summary之前需執(zhí)行);
- host info:顯示查詢到的信息(n為設(shè)備在列表中的編號);
- host summary 0 :顯示xml文件的摘要信息;
利用
host info 0 deviceList //設(shè)備列表,或者說設(shè)備信息
host info 0 deviceList WANConnectionDevice services //設(shè)備服務(wù)列表
host info 0 deviceList WANConnectionDevice services WANIPConnection serviceStateVariables //服務(wù)狀態(tài)列表
host info 0 deviceList WANConnectionDevice services WANIPConnection actions //服務(wù)控制列表,操作功能
host send 0 WANConnectionDevice WANIPConnection AddPortMapping //規(guī)則配置
登陸后臺可以看到規(guī)則已配置,并且生效了;
其他功能解析,這部分其實有些是廠商自定義的,有些是默認自帶的功能;
AddPortMapping : {}
GetNATRSIPStatus : {}
GetGenericPortMappingEntry : {}
GetSpecificPortMappingEntry : {}
ForceTermination : {}
GetExternalIPAddress : {}
GetConnectionTypeInfo : {}
GetStatusInfo : {}
SetConnectionType : {}
DeletePortMapping : {}
RequestConnection : {}
小技巧:由于發(fā)現(xiàn)upnp服務(wù)比較困難,掉線或者退出進程后,需要重新發(fā)現(xiàn),又只能等;找了一下,官方提供了存儲和恢復(fù)的功能;
upnp> save info 0 wrt54g
Host info for '192.168.1.1:2869' saved to 'info_wrt54g.mir'
upnp> save data wrt54g
Host data saved to 'struct_wrt54g.mir'
upnp> load struct_wrt54g.mir
Host data restored:
[0] 192.168.1.1:2869
DLNA簡要概述
數(shù)字生活網(wǎng)絡(luò)聯(lián)盟(英語:Digital Living Network Alliance,簡稱:DLNA)是一個由消費性電子、移動電話以及電腦廠商組成的聯(lián)盟組織。該組織的目標在于創(chuàng)建一套可以使得各廠商的產(chǎn)品互相連接,互相適應(yīng)的工業(yè)標準,從而為消費者實現(xiàn)數(shù)字化生活。聯(lián)盟成員包括飛利浦、三星電子、松下、惠普、索尼、微軟、英特爾和諾基亞在內(nèi)的眾多業(yè)界領(lǐng)袖。
其實DLNA應(yīng)該是一系列協(xié)議棧的組合統(tǒng)稱,并不是一個單獨的協(xié)議;
NetWorking Connectivity 網(wǎng)絡(luò)互聯(lián)方式:802.3 以太網(wǎng),802.11WiFi,802.15 藍牙;
NetWorking Stack 網(wǎng)絡(luò)協(xié)議棧:IPv4、IPv6;
Device Discovery&Control 設(shè)備發(fā)現(xiàn)和控制:UPnP,具體參考UPnP的相關(guān)文檔;
Media Management媒體管理:識別、管理、分發(fā)、記錄;
Media Transport 媒體傳輸:HTTP;
Media Formats媒體格式:各種音頻圖片格式:avi、rmvb、mkv;
Remote UI 遠程用戶接口:接口;
可以看到風險點主要在3、5、7, 3的分析還是參考 UPnP部分章節(jié),5、7也就是常規(guī)的http服務(wù),由于不管是DLNA的設(shè)計還是UPnP原協(xié)議的設(shè)計均不存在認證授權(quán)這一環(huán)節(jié),主要是服務(wù)發(fā)現(xiàn),以及請求構(gòu)造;只要進入局域網(wǎng)能夠連接服務(wù),均可以任意調(diào)用服務(wù);
由于手上沒有DLNA服務(wù)的設(shè)備,可以參考: https://breezetemple.github.io/2019/02/25/dlan-introduction/。
從文章中可以發(fā)現(xiàn),不管是DLNA還是UPnP,都是通過soap來完成控制調(diào)用,格式也都是xml; 但是miranda-upnp是針對upnp的,不知道是否也能發(fā)現(xiàn)基于UPnP的DLNA服務(wù),即使能發(fā)現(xiàn)估計后續(xù)的服務(wù)發(fā)現(xiàn)需要調(diào)整源碼的xml解析;具體參考源代碼解析。
總結(jié)
不管是UPnP還是DLNA都是不存在驗證授權(quán)機制,也就是說只要進入局域網(wǎng)就可以任意調(diào)用,如果只是UPnP,一般用于路由器上路由配置,鏈路轉(zhuǎn)發(fā),然后服務(wù)一般默認開啟,這個利用場景相對風險較低一些,因為需要在其他設(shè)備存在問題,且路由器為公網(wǎng)ip的情況,才能實現(xiàn)公網(wǎng)直接訪問的利用場景,其他場景的利用都是沒有必要使用到這個場景的(也可能是我沒有想到);DLNA服務(wù)一般用于投屏,這個就是直接可以利用的;然后還有特殊場景,視頻流拉取,操作指令控制等。
留個坑,miranda源代碼解析;
參考:
https://blog.csdn.net/braddoris/article/details/41646789
https://breezetemple.github.io/2019/02/25/dlan-introduction/
https://github.com/CharonChui/AndroidNote/blob/master/VideoDevelopment/DLNA%E7%AE%80%E4%BB%8B.md