rtsp协议 抓包分析

本文详细描述了使用Wireshark抓取并解析RTSP视频流的过程,涉及OPTIONS、DESCRIBE、AUTHENTICATION(尤其是摘要认证)以及SETUP和PLAY请求与响应,展示了如何通过Wireshark跟踪和理解RTSP通信协议的各个环节。
摘要由CSDN通过智能技术生成

RTPS 抓包解析

整体流程

利用 wireshark 完成的的一次抓取 RTSP 视频流播放。

OPTIONS

Transmission Control Protocol, Src Port: 4431, Dst Port: 8554, Seq: 1, Ack: 1, Len: 130
Real Time Streaming Protocol
    Request: OPTIONS rtsp://192.168.1.109:8554/live0.264 RTSP/1.0\r\n
    CSeq: 2\r\n
    User-Agent: LibVLC/3.0.18 (LIVE555 Streaming Media v2016.11.28)\r\n
    \r\n
Transmission Control Protocol, Src Port: 8554, Dst Port: 4431, Seq: 1, Ack: 131, Len: 146
Real Time Streaming Protocol
    Response: RTSP/1.0 200 OK\r\n
    CSeq: 2\r\n
    Server: LIBEASYRTSPD-JV/1/1.6\r\n
    Public: OPTIONS, DESCRIBE, SETUP, PLAY, PAUSE, TEARDOWN, GET_PARAMETER, SET_PARAMETER\r\n
    \r\n

DESCRIBE

此阶段完成用户认证、交换SDP等功能。
通常三种方式
1. RTSP URL认证
直接携带明文的用户名和密码(rtsp://用户名:密码@IP地址/Stream/Channels/101),安全性低。
2、基本认证(basic authentication)
基本认证是HTTP 1.0 提出的认证方案,其消息传输不经过加密转换因此存在严重的安全隐患。
3、摘要认证( digest authentication)
摘要认证是 HTTP 1.1 提出的基本认证的替代方案,其消息经过 MD5 哈希转换因此具有更高的安全性。

对于RTSP而言,采用的是第三种:摘要认证。
当客户端发送给服务端 DESCRIBE 报文时,若采取用户认证,则会返回带有 WWW-Authenticate 字段的响应报文,在 WWW-Authenticate 字段中,会携带:realmnonce 字段,以便产生 response 字段,供后续进行验证。
当客户端收到服务端带有的 WWW-Authenticate 的报文时,会根据下列方法产生 response 字段,以便在请求报文的 Authorization 中携带,完成用户鉴权。
对于 response 的产生,同 GB28181 鉴权生成 response方法一样,但只有 MD5 加密方式,具体方法如下:
response= md5(md5(username:realm:password):nonce:md5(public_method:url) );
后服务端收到Authorization Accept: application/sdp\r\n 请求报文,会在响应报文中携带 SDP 相关信息,以便完成相关编码方式的选择。
后续的请求报文,都将携带 Authorization 字段。

Transmission Control Protocol, Src Port: 4431, Dst Port: 8554, Seq: 131, Ack: 147, Len: 156
Real Time Streaming Protocol
    Request: DESCRIBE rtsp://192.168.1.109:8554/live0.264 RTSP/1.0\r\n
    CSeq: 3\r\n
    User-Agent: LibVLC/3.0.18 (LIVE555 Streaming Media v2016.11.28)\r\n
    Accept: application/sdp\r\n
    \r\n
Transmission Control Protocol, Src Port: 8554, Dst Port: 4431, Seq: 147, Ack: 287, Len: 182
Real Time Streaming Protocol
    Response: RTSP/1.0 401 Unauthorized\r\n
    CSeq: 3\r\n
    Date: Tue, May 16 2017 05:49:24 GMT\r\n
    WWW-Authenticate: Digest realm="LIBEASYRTSPD-JV", nonce="41b3fc540e909d63b1c8ff0444f1ed76", stale="FALSE"\r\n
    \r\n
Transmission Control Protocol, Src Port: 4431, Dst Port: 8554, Seq: 287, Ack: 329, Len: 351
Real Time Streaming Protocol
    Request: DESCRIBE rtsp://192.168.1.109:8554/live0.264 RTSP/1.0\r\n
    CSeq: 4\r\n
    Authorization: Digest username="admin", realm="LIBEASYRTSPD-JV", nonce="41b3fc540e909d63b1c8ff0444f1ed76", uri="rtsp://192.168.1.109:8554/live0.264", response="288c401e9abb17dd3ae10b044a72e9ee"\r\n
    User-Agent: LibVLC/3.0.18 (LIVE555 Streaming Media v2016.11.28)\r\n
    Accept: application/sdp\r\n
    \r\n
Transmission Control Protocol, Src Port: 8554, Dst Port: 4431, Seq: 329, Ack: 638, Len: 513
Real Time Streaming Protocol
    Response: RTSP/1.0 200 OK\r\n
    CSeq: 4\r\n
    Date: Tue, May 16 2017 05:49:24 GMT\r\n
    Content-Base: rtsp://192.168.1.109:8554/live0.264/\r\n
    Content-type: application/sdp
    Content-length: 318
    x-Accept-Dynamic-Rate: 1\r\n
    \r\n
    Session Description Protocol
        Session Description Protocol Version (v): 0
        Owner/Creator, Session Id (o): - 1398474260 1 IN IP4 192.168.1.109
        Session Name (s): Session Streamed by LIBEASYRTSPD-JV
        Session Information (i): live0.264
        Time Description, active time (t): 0 0
        Session Attribute (a): tool:LIBEASYRTSPD-JV v1/1.6
        Media Description, name and address (m): video 0 RTP/AVP 96
        Connection Information (c): IN IP4 192.168.1.109
        Bandwidth Information (b): AS:2
        Media Attribute (a): rtpmap:96 H265/90000
        Media Attribute (a): control:track1
        Media Description, name and address (m): audio 0 RTP/AVP 8
        Connection Information (c): IN IP4 0.0.0.0
        Bandwidth Information (b): AS:64
        Media Attribute (a): rtpmap:8 PCMA/8000
        Media Attribute (a): control:track2

SETUP

在 SETUP 阶段,根据视频流和音频流的两个是否存在,如果两个同时存在,则会进行两次 SETUP 阶段,否则只有一次,同时会建立一个 Session ,在后续都会存在。

Transmission Control Protocol, Src Port: 4431, Dst Port: 8554, Seq: 638, Ack: 842, Len: 383
Real Time Streaming Protocol
    Request: SETUP rtsp://192.168.1.109:8554/live0.264/track1 RTSP/1.0\r\n
    CSeq: 5\r\n
    Authorization: Digest username="admin", realm="LIBEASYRTSPD-JV", nonce="41b3fc540e909d63b1c8ff0444f1ed76", uri="rtsp://192.168.1.109:8554/live0.264/", response="d62bc1d2763c903b9dbdff7c01ee72b8"\r\n
    User-Agent: LibVLC/3.0.18 (LIVE555 Streaming Media v2016.11.28)\r\n
    Transport: RTP/AVP;unicast;client_port=58822-58823
    \r\n

Transmission Control Protocol, Src Port: 8554, Dst Port: 4431, Seq: 842, Ack: 1021, Len: 248
Real Time Streaming Protocol
    Response: RTSP/1.0 200 OK\r\n
    CSeq: 5\r\n
    Date: Thu, Oct 19 2023 13:49:32 GMT\r\n
    Session: 3C66DB38;timeout=60
    Transport: RTP/AVP;unicast;destination=192.168.1.104;source=192.168.1.109;client_port=58822-58823;server_port=40215-40216;mode=PLAY;
    x-Dynamic-Rate: 1\r\n
    \r\n
Transmission Control Protocol, Src Port: 4431, Dst Port: 8554, Seq: 1021, Ack: 1090, Len: 402
Real Time Streaming Protocol
    Request: SETUP rtsp://192.168.1.109:8554/live0.264/track2 RTSP/1.0\r\n
    CSeq: 6\r\n
    Authorization: Digest username="admin", realm="LIBEASYRTSPD-JV", nonce="41b3fc540e909d63b1c8ff0444f1ed76", uri="rtsp://192.168.1.109:8554/live0.264/", response="d62bc1d2763c903b9dbdff7c01ee72b8"\r\n
    User-Agent: LibVLC/3.0.18 (LIVE555 Streaming Media v2016.11.28)\r\n
    Transport: RTP/AVP;unicast;client_port=58824-58825
    Session: 3C66DB38
    \r\n

Transmission Control Protocol, Src Port: 8554, Dst Port: 4431, Seq: 1090, Ack: 1423, Len: 248
Real Time Streaming Protocol
    Response: RTSP/1.0 200 OK\r\n
    CSeq: 6\r\n
    Date: Thu, Oct 19 2023 13:49:32 GMT\r\n
    Session: 3C66DB38;timeout=60
    Transport: RTP/AVP;unicast;destination=192.168.1.104;source=192.168.1.109;client_port=58824-58825;server_port=40087-40088;mode=PLAY;
    x-Dynamic-Rate: 1\r\n
    \r\n

PLAY

Transmission Control Protocol, Src Port: 4431, Dst Port: 8554, Seq: 1423, Ack: 1338, Len: 362
Real Time Streaming Protocol
    Request: PLAY rtsp://192.168.1.109:8554/live0.264/ RTSP/1.0\r\n
    CSeq: 7\r\n
    Authorization: Digest username="admin", realm="LIBEASYRTSPD-JV", nonce="41b3fc540e909d63b1c8ff0444f1ed76", uri="rtsp://192.168.1.109:8554/live0.264/", response="135714bdbe4d768af5d1a2c40cc3a118"\r\n
    User-Agent: LibVLC/3.0.18 (LIVE555 Streaming Media v2016.11.28)\r\n
    Session: 3C66DB38
    Range: npt=0.000-\r\n
    \r\n

Transmission Control Protocol, Src Port: 8554, Dst Port: 4431, Seq: 1338, Ack: 1785, Len: 265
Real Time Streaming Protocol
    Response: RTSP/1.0 200 OK\r\n
    CSeq: 7\r\n
    Date: Tue, May 16 2017 05:49:24 GMT\r\n
    Session: 3C66DB38
    Range: npt=0.000-\r\n
    RTP-Info: url=rtsp://192.168.1.109:8554/live0.264/track1;seq=51013;rtptime=936573910,url=rtsp://192.168.1.109:8554/live0.264/track2;seq=50139;rtptime=1617512174\r\n
    \r\n
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值