织梦CMS - 轻松建站从此开始!

罗索

迅雷UPnP数据抓包分析

落鹤生 发布于 2012-03-19 17:55 点击:次 
落鹤生:原来的代码由于没分XML tag与HTML代码,结果看上去乱七八糟的,我稍微整理了一下。
TAG:

写UPNP路由端口映射程序时抓的迅雷的数据包,由UPNP协议在路由上进行端口映射的全过程都在这里了。有了过程思路,想要自己在路由上增加端口映射就容易了,只是发送数据包,接收并解析XML数据的问题了。

//设备发现消息
[2009-9-21 23:54:07:033]
M-SEARCH * HTTP/1.1
HOST:239.255.255.250:1900
MAN:"ssdp:discover"
MX:6
ST:urn:schemas-upnp-org:service:WANPPPConnection:1

M-SEARCH * HTTP/1.1
HOST:239.255.255.250:1900
MAN:"ssdp:discover"
MX:6
ST:urn:schemas-upnp-org:service:WANIPConnection:1

///////////////////////////////////////////////
[2009-9-21 23:54:07:043]
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=100
DATE: Thu, 01 Jan 1970 00:46:40 GMT
EXT:
LOCATION: http://192.168.1.1:1900/igd.xml
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
ST: urn:schemas-upnp-org:service:WANIPConnection:1
USN: uuid:upnp-WANConnectionDevice-192168115678900001::urn:schemas-upnp-org:service:WANIPConnection:1

///////////////////////////////////////////////////////////
[2009-9-22 0:03:56:811]
GET /igd.xml HTTP/1.1
Host: 192.168.1.1:1900


[2009-9-22 0:03:56:811]
HTTP/1.1 200 OK
CONTENT-LENGTH: 2746
CONTENT-TYPE: text/xml
DATE: Thu, 01 Jan 1970 00:56:29 GMT
LAST-MODIFIED: Tue, 28 Oct 2003 08:46:08 GMT
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
CONNECTION: close



<specversion>
<major>1
<minor>0
</specversion>
<urlbase>
<device>
<devicetype>urn:schemas-upnp-org:device:InternetGatewayDevice:1</devicetype>
<presentationurl>http://192.168.1.1:80  <friendlyname>TP-LINK SOHO Router R402 Serie
<manufacturer>TP-LINK
<manufacturerurl>http://www.tp-link.com.cn
<modeldescription>TL-R402 Series 2.0
<modelname>TL-R402 Series
<modelnumber>2.0
<udn>uuid:upnp-InternetGatewayDevice-192168115678900001
<upc>123456789001
<servicelist>
<service>
<servicetype>urn:schemas-upnp-org:service:Layer3Forwarding:1</servicetype>
<serviceid>urn:upnp-org:serviceId:L3Forwarding1</serviceid>
<controlurl>/l3f
<eventsuburl>/l3f
<scpdurl>/l3f.xml</scpdurl>
</service>
</servicelist>
<devicelist>
<device>
<devicetype>urn:schemas-upnp-org:device:WANDevice:1</devicetype>
<friendlyname>WAN Device
<manufacturer>TP-LINK
<manufacturerurl>http://www.tp-link.com.cn
<modeldescription>WAN Device
<modelname>WAN Device
<modelnumber>1
<modelurl>
<serialnumber>12345678900001</serialnumber>
<udn>uuid:upnp-WANDevice-192168115678900001
<upc>123456789001
<servicelist>
<service>
<servicetype>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</servicetype>
<serviceid>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceid>
<controlurl>/ifc
<eventsuburl>/ifc
<scpdurl>/ifc.xml</scpdurl>
</service>
</servicelist>
<devicelist>
<device>
<devicetype>urn:schemas-upnp-org:device:WANConnectionDevice:1</devicetype>
<friendlyname>WAN Connection Device
<manufacturer>TP-LINK
<manufacturerurl>http://www.tp-link.com.cn
<modeldescription>WAN Connection Device
<modelname>WAN Connection Device
<modelnumber>1
<modelurl>
<serialnumber>12345678900001</serialnumber>
<udn>uuid:upnp-WANConnectionDevice-192168115678900001
<upc>123456789001
<servicelist>
<service>
<servicetype>urn:schemas-upnp-org:service:WANIPConnection:1</servicetype>
<serviceid>urn:upnp-org:serviceId:WANIPConnection</serviceid>
<controlurl>/ipc
<eventsuburl>/ipc
<scpdurl>/ipc.xml</scpdurl>
</service>
</servicelist>
</device>
</devicelist>
</device>
</devicelist>
</device>


得到外部IP地址
///////////////////////////////////////////////////////////////////
[2009-9-22 0:03:56:831]
POST /ipc HTTP/1.1
HOST: 192.168.1.1:1900
Content-Length: 296 
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"

<s:envelope>
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"<
<s:body>
<u:getexternalipaddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">

</s:body>
</s:envelope>


[2009-9-22 0:03:56:841]
HTTP/1.1 200 OK
CONNECTION: close
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
CONTENT-LENGTH: 404
CONTENT-TYPE: text/xml; charset="utf-8"


<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<u:getexternalipaddressresponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><newexternalipaddress>220.112.102.188</soap-env:body>
</soap-env:envelope>


增加端口映射
////////////////////////////////////////////////////////////////////////////

[2009-9-22 0:03:56:851]
POST /ipc HTTP/1.1
HOST: 192.168.1.1:1900
Content-Length: 665 
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"

<s:envelope>
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"<
<s:body>
<u:addportmapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<newremotehost>
<newexternalport>10141
<newprotocol>TCP
<newinternalport>80
<newinternalclient>192.168.1.103
<newenabled>1
<newportmappingdescription>Thunder5
<newleaseduration>0

</s:body>
</s:envelope>


[2009-9-22 0:03:56:861]
HTTP/1.1 200 OK
CONNECTION: close
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
CONTENT-LENGTH: 332
CONTENT-TYPE: text/xml; charset="utf-8"


<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<u:addportmappingresponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></soap-env:body>
</soap-env:envelope>

增加端口映射
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[2009-9-22 0:03:56:881]
POST /ipc HTTP/1.1
HOST: 192.168.1.1:1900
Content-Length: 668 
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"

<s:envelope>
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"<
<s:body>
<u:addportmapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<newremotehost>
<newexternalport>10141
<newprotocol>UDP
<newinternalport>19369
<newinternalclient>192.168.1.103
<newenabled>1
<newportmappingdescription>Thunder5
<newleaseduration>0

</s:body>
</s:envelope>


[2009-9-22 0:03:56:891]
HTTP/1.1 200 OK
CONNECTION: close
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
CONTENT-LENGTH: 332
CONTENT-TYPE: text/xml; charset="utf-8"


<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<u:addportmappingresponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></soap-env:body>
</soap-env:envelope>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[2009-9-22 0:17:16:651]
SUBSCRIBE /ifc HTTP/1.1
SID: uuid:16842752-2147511038
Timeout: Second-1800
User-Agent: Mozilla/4.0 (compatible; UPnP/1.0; Windows 9x)
Host: 192.168.1.1:1900
Content-Length: 0
Connection: Keep-Alive
Cache-Control: no-cache
Pragma: no-cache


[2009-9-22 0:17:16:661]
HTTP/1.1 200 OK
DATE: Thu, 01 Jan 1970 01:09:49 GMT
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
SID: uuid:16842752-2147511038
TIMEOUT: Second-1800

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[2009-9-22 0:17:16:691]
SUBSCRIBE /ipc HTTP/1.1
SID: uuid:16842752-2281728766
Timeout: Second-1800
User-Agent: Mozilla/4.0 (compatible; UPnP/1.0; Windows 9x)
Host: 192.168.1.1:1900
Content-Length: 0
Connection: Keep-Alive
Cache-Control: no-cache
Pragma: no-cache


[2009-9-22 0:17:16:711]
HTTP/1.1 200 OK
DATE: Thu, 01 Jan 1970 01:09:49 GMT
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
SID: uuid:16842752-2281728766
TIMEOUT: Second-1800

//删除端口映射
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[2009-9-22 0:18:38:349]
POST /ipc HTTP/1.1
HOST: 192.168.1.1:1900
Content-Length: 399 
Connection: close
CONTENT-TYPE: text/xml ; charset="utf-8"
SOAPACTION:"urn:schemas-upnp-org:service:WANIPConnection:1#DeletePortMapping"

<s:envelope>
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"<
<s:body>
<u:deleteportmapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<newremotehost>
<newexternalport>10141
<newprotocol>TCP

</s:body>
</s:envelope>


[2009-9-22 0:18:38:349]
HTTP/1.1 200 OK
CONNECTION: close
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
CONTENT-LENGTH: 338
CONTENT-TYPE: text/xml; charset="utf-8"


<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<u:deleteportmappingresponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></soap-env:body>
</soap-env:envelope>

//删除端口映射
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[2009-9-22 0:18:38:359]
POST /ipc HTTP/1.1
HOST: 192.168.1.1:1900
Content-Length: 399 
Connection: close
CONTENT-TYPE: text/xml ; charset="utf-8"
SOAPACTION:"urn:schemas-upnp-org:service:WANIPConnection:1#DeletePortMapping"

<s:envelope>
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"<
<s:body>
<u:deleteportmapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<newremotehost>
<newexternalport>10141
<newprotocol>UDP

</s:body>
</s:envelope>


[2009-9-22 0:18:38:369]
HTTP/1.1 200 OK
CONNECTION: close
SERVER: TP-LINK SOHO Router R402 Series Router, UPnP/1.0
CONTENT-LENGTH: 338
CONTENT-TYPE: text/xml; charset="utf-8"


<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<u:deleteportmappingresponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></soap-env:body>
</soap-env:envelope>


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(fwxjj)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201203/15845.html]
本文出处:cppblog.com/fwxjj 作者:fwxjj 原文
顶一下
(0)
0%
踩一下
(1)
100%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容