mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/network-services-pentesting/pentesting-ntp.md'] to zh
This commit is contained in:
parent
ad510cbd01
commit
e970d8e947
@ -4,59 +4,154 @@
|
||||
|
||||
## 基本信息
|
||||
|
||||
**网络时间协议 (NTP)** 确保计算机和网络设备在可变延迟网络中准确同步其时钟。它对于维护IT操作、安全和日志记录中的精确计时至关重要。NTP的准确性是必不可少的,但如果管理不当,也会带来安全风险。
|
||||
**网络时间协议 (NTP)** 确保计算机和网络设备在可变延迟网络中准确同步时钟。它对于维护 IT 操作、安全性和日志记录中的精确计时至关重要。由于时间在几乎每个身份验证、加密协议和取证过程中都被使用,**能够影响 NTP 的攻击者通常可以绕过安全控制或使攻击更难以调查。**
|
||||
|
||||
### 摘要与安全提示:
|
||||
### 摘要与安全提示
|
||||
|
||||
- **目的**:在网络上同步设备时钟。
|
||||
- **重要性**:对安全、日志记录和操作至关重要。
|
||||
- **重要性**:对安全性、日志记录、加密协议和分布式系统至关重要。
|
||||
- **安全措施**:
|
||||
- 使用带有身份验证的可信NTP源。
|
||||
- 限制NTP服务器的网络访问。
|
||||
- 监控同步以发现篡改迹象。
|
||||
- 使用经过验证的 NTP 或 NTS(网络时间安全)源并进行身份验证。
|
||||
- 限制可以查询/命令守护进程的用户(``restrict default noquery``、``kod`` 等)。
|
||||
- 禁用传统的 Mode-6/7 控制查询(``monlist``、``ntpdc``)或对其进行速率限制。
|
||||
- 监控同步漂移/闰秒状态以防篡改。
|
||||
- 保持守护进程更新(请参见下面的最新 CVE)。
|
||||
|
||||
**默认端口**
|
||||
```
|
||||
123/udp NTP (data + legacy control)
|
||||
4460/tcp NTS-KE (RFC 8915) – TLS key-establishment for NTP
|
||||
```
|
||||
|
||||
**默认端口:** 123/udp
|
||||
```
|
||||
PORT STATE SERVICE REASON
|
||||
123/udp open ntp udp-response
|
||||
```
|
||||
---
|
||||
## 枚举
|
||||
```bash
|
||||
ntpq -c readlist <IP_ADDRESS>
|
||||
ntpq -c readvar <IP_ADDRESS>
|
||||
ntpq -c peers <IP_ADDRESS>
|
||||
ntpq -c associations <IP_ADDRESS>
|
||||
ntpdc -c monlist <IP_ADDRESS>
|
||||
ntpdc -c listpeers <IP_ADDRESS>
|
||||
ntpdc -c sysinfo <IP_ADDRESS>
|
||||
```
|
||||
|
||||
### 经典 ntpd / ntpq / ntpdc
|
||||
```bash
|
||||
nmap -sU -sV --script "ntp* and (discovery or vuln) and not (dos or brute)" -p 123 <IP>
|
||||
# Information & variables
|
||||
ntpq -c rv <IP>
|
||||
ntpq -c readvar <IP>
|
||||
ntpq -c peers <IP>
|
||||
ntpq -c associations <IP>
|
||||
|
||||
# Legacy mode-7 (often disabled >=4.2.8p9)
|
||||
ntpdc -c monlist <IP>
|
||||
ntpdc -c listpeers <IP>
|
||||
ntpdc -c sysinfo <IP>
|
||||
```
|
||||
### chrony / chronyc (在大多数现代Linux发行版中)
|
||||
|
||||
当``cmdallow``启用时,仅接受来自远程IP的少数监控命令:
|
||||
```bash
|
||||
chronyc -a -n tracking -h <IP>
|
||||
chronyc -a -n sources -v -h <IP>
|
||||
chronyc -a -n sourcestats -h <IP>
|
||||
```
|
||||
查看 chronyc 手册页以了解 **M/S** 标志和其他字段(层次、可达性、抖动等)的含义。
|
||||
|
||||
### Nmap
|
||||
```bash
|
||||
# Safe discovery & vuln detection
|
||||
nmap -sU -sV --script "ntp* and (discovery or vuln) and not (dos or brute)" -p 123 <IP>
|
||||
|
||||
# Explicit monlist check
|
||||
nmap -sU -p123 --script ntp-monlist <IP>
|
||||
```
|
||||
### 大规模/互联网扫描
|
||||
```bash
|
||||
# Check if MONLIST is enabled (zgrab2 module)
|
||||
zgrab2 ntp --monlist --timeout 3 --output-file monlist.json -f "zmap_results.csv"
|
||||
```
|
||||
---
|
||||
## 检查配置文件
|
||||
|
||||
- ntp.conf
|
||||
- ``/etc/ntp.conf`` (ntpd)
|
||||
- ``/etc/chrony/chrony.conf`` (chrony)
|
||||
- ``/etc/systemd/timesyncd.conf`` (timesyncd – 仅客户端)
|
||||
|
||||
## NTP 放大攻击
|
||||
特别注意 ``restrict`` 行,``kod`` (Kiss-o'-Death) 设置,``disable monitor``/``includefile /etc/ntp/crypto`` 以及 *NTS* 是否启用 (``nts enable``)。
|
||||
|
||||
[**NTP DDoS 攻击是如何工作的**](https://resources.infosecinstitute.com/network-time-protocol-ntp-threats-countermeasures/#gref)
|
||||
---
|
||||
## 最近的漏洞 (2023-2025)
|
||||
|
||||
**NTP 协议**使用 UDP,允许在不需要握手程序的情况下操作,这与 TCP 不同。这个特性在**NTP DDoS 放大攻击**中被利用。在这里,攻击者创建带有假源 IP 的数据包,使攻击请求看起来像是来自受害者。这些最初较小的数据包促使 NTP 服务器以更大数据量进行响应,从而放大攻击。
|
||||
| 年份 | CVE | 组件 | 影响 |
|
||||
|------|-----|-----------|--------|
|
||||
| 2023 | **CVE-2023-26551→26555** | ntp 4.2.8p15 (libntp *mstolfp*, *praecis_parse*) | 多个越界写入可通过 **ntpq** 响应访问。补丁在 **4.2.8p16** 🡒 升级或回移修复。 citeturn1search1turn1search2turn1search0|
|
||||
| 2023 | **CVE-2023-33192** | **ntpd-rs** (Rust 实现) | 格式错误的 **NTS** cookie 导致 v0.3.3 之前的远程 **DoS** – 即使在 NTS **禁用** 时也影响 123 端口。 citeturn4view0|
|
||||
| 2024 | 发行版更新 | **chrony 4.4 / 4.5** – 多个安全加固和 NTS-KE 修复 (例如 SUSE-RU-2024:2022) citeturn2search2|
|
||||
| 2024 | 记录 DDoS | Cloudflare 报告 **5.6 Tbps UDP 反射** 攻击 (NTP 在使用的协议中)。保持 *monitor* 和 *monlist* 在面向互联网的主机上禁用。 citeturn5search0|
|
||||
|
||||
尽管 _**MONLIST**_ 命令使用较少,但可以报告最后 600 个连接到 NTP 服务的客户端。虽然该命令本身很简单,但在此类攻击中的误用突显了关键的安全漏洞。
|
||||
> **利用工具包**:2023 年 ntpq OOB-write 系列的概念验证有效载荷在 GitHub 上可用(参见 Meinberg 的总结),可以用于针对系统管理员的客户端钓鱼攻击。 citeturn1search4
|
||||
|
||||
---
|
||||
## 高级攻击
|
||||
|
||||
### 1. NTP 放大 / 反射
|
||||
|
||||
传统的 Mode-7 ``monlist`` 查询返回多达 **600 个主机地址**,并且仍然存在于数千个互联网主机上。由于回复(428-468 字节/条目)比 8 字节请求大 *~ 200×*,攻击者可以达到三位数的放大因子。缓解措施:
|
||||
|
||||
- 升级到 ntp 4.2.8p15+ 并 **添加** ``disable monitor``。
|
||||
- 在边缘对 UDP/123 进行速率限制或在 DDoS 设备上启用 *sessions-required*。
|
||||
- 启用 *BCP 38* 出口过滤以阻止源欺骗。
|
||||
|
||||
请参阅 Cloudflare 的学习中心文章以获取逐步分解。 citeturn5search1
|
||||
|
||||
### 2. 时间偏移 / 延迟攻击 (Khronos / Chronos 研究)
|
||||
|
||||
即使有身份验证,路径上的攻击者也可以通过丢弃/延迟数据包静默地 **移动客户端时钟**。IETF **Khronos(前称 Chronos)草案** 提议在后台查询多样化的服务器并对结果进行合理性检查,以检测偏移 > 𝚡 毫秒。现代 chrony (4.4+) 已经实现了类似的合理性过滤器 (``maxdistance`` / ``maxjitter``)。 citeturn9search1
|
||||
|
||||
### 3. NTS 滥用与 4460/tcp 暴露
|
||||
|
||||
NTS 将重型加密移至单独的 **TLS 1.3 通道在 4460/tcp** (``ntske/1``)。不良实现(参见 CVE-2023-33192)在解析 cookies 时崩溃或允许弱密码。渗透测试人员应:
|
||||
```bash
|
||||
ntpdc -n -c monlist <IP>
|
||||
# TLS reconnaissance
|
||||
nmap -sV -p 4460 --script ssl-enum-ciphers,ssl-cert <IP>
|
||||
|
||||
# Grab banner & ALPN
|
||||
openssl s_client -connect <IP>:4460 -alpn ntske/1 -tls1_3 -ign_eof
|
||||
```
|
||||
## Shodan
|
||||
查找自签名或过期证书以及弱密码套件(非 AEAD)。参考:RFC 8915 §4. citeturn11search0
|
||||
|
||||
- `ntp`
|
||||
---
|
||||
## 加固 / 最佳当前实践 (BCP-233 / RFC 8633)
|
||||
|
||||
*操作员应:*
|
||||
|
||||
1. 使用 **≥ 4** 个独立、多样的时间源(公共池、GPS、PTP-桥)以避免单一源中毒。
|
||||
2. 启用 ``kod`` 和 ``limited``/``nomodify`` 限制,以便滥用客户端接收 **Kiss-o'-Death** 限速数据包,而不是完整响应。
|
||||
3. 监控守护进程日志以查找 **panic** 事件或步进调整 > 1000 s。(根据 RFC 8633 §5.3 的攻击特征。)
|
||||
4. 考虑 **leap-smear** 以避免闰秒中断,但确保 *所有* 下游客户端使用相同的涂抹窗口。
|
||||
5. 保持轮询 ≤24 小时,以免错过闰秒标志。
|
||||
|
||||
有关全面检查清单,请参见 RFC 8633。 citeturn8search0turn8search1
|
||||
|
||||
---
|
||||
## Shodan / Censys Dorks
|
||||
```
|
||||
port:123 "ntpd" # Version banner
|
||||
udp port:123 monlist:true # Censys tag for vulnerable servers
|
||||
port:4460 "ntske" # NTS-KE
|
||||
```
|
||||
---
|
||||
## 有用的工具
|
||||
|
||||
| 工具 | 目的 | 示例 |
|
||||
|------|---------|---------|
|
||||
| ``ntpwn`` | 脚本小子包装器,用于喷射 monlist 和 peers 查询 | ``python ntpwn.py --monlist targets.txt`` |
|
||||
| **zgrab2 ntp** | 大规模扫描 / JSON 输出,包括 monlist 标志 | 见上面的命令 |
|
||||
| ``chronyd`` 与 ``allow`` | 在渗透测试实验室运行恶意 NTP 服务器 | ``chronyd -q 'server 127.127.1.0 iburst'`` |
|
||||
| ``BetterCap`` | 注入 NTP 数据包以进行 Wi-Fi 上的时间偏移 MITM | ``set arp.spoof.targets <victim>; set ntp.time.delta 30s; arp.spoof on`` |
|
||||
|
||||
---
|
||||
## HackTricks 自动命令
|
||||
```
|
||||
Protocol_Name: NTP #Protocol Abbreviation if there is one.
|
||||
Port_Number: 123 #Comma separated if there is more than one.
|
||||
Protocol_Description: Network Time Protocol #Protocol Abbreviation Spelled out
|
||||
Protocol_Name: NTP
|
||||
Port_Number: 123
|
||||
Protocol_Description: Network Time Protocol
|
||||
|
||||
Entry_1:
|
||||
Name: Notes
|
||||
@ -71,6 +166,17 @@ Name: Nmap
|
||||
Description: Enumerate NTP
|
||||
Command: nmap -sU -sV --script "ntp* and (discovery or vuln) and not (dos or brute)" -p 123 {IP}
|
||||
```
|
||||
|
||||
---
|
||||
## 参考文献
|
||||
|
||||
{{#include ../banners/hacktricks-training.md}}
|
||||
- RFC 8915 – *网络时间协议的网络时间安全* (端口 4460) citeturn11search0
|
||||
- RFC 8633 – *网络时间协议 BCP* citeturn8search0
|
||||
- Cloudflare DDoS 报告 2024 Q4 (5.6 Tbps) citeturn5search0
|
||||
- Cloudflare *NTP 放大攻击* 文章 citeturn5search1
|
||||
- NTP 4.2.8p15 CVE 系列 2023-04 citeturn1search4
|
||||
- NVD 条目 **CVE-2023-26551–55**, **CVE-2023-33192** citeturn1search1turn1search2turn1search0turn4view0
|
||||
- SUSE chrony 安全更新 2024 (chrony 4.5) citeturn2search2
|
||||
- Khronos/Chronos 草案 (时间偏移缓解) citeturn9search1
|
||||
- chronyc 手册/远程监控示例 citeturn3search0turn10search1
|
||||
- zgrab2 ntp 模块文档 citeturn7search0
|
||||
{{#include /banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user