跳到主要内容

RustScan 端口扫描

RustScan 是用 Rust 编写的现代端口扫描器,能在数秒内完成 65535 端口的扫描,并将发现的开放端口自动传递给 Nmap 做服务识别。在靶场打靶和渗透测试的侦察阶段,它是替代 nmap -p- 全端口扫描的首选工具。


安装

Kali / Debian

GitHub Releases 下载 .deb 包(版本号以 Releases 页面最新版本为准):

wget https://github.com/RustScan/RustScan/releases/download/2.4.1/rustscan_2.4.1_amd64.deb
sudo dpkg -i rustscan_2.4.1_amd64.deb

Cargo

cargo install rustscan

Homebrew (macOS)

brew install rustscan

Docker

docker pull rustscan/rustscan:latest
docker run -it --rm rustscan/rustscan -a 192.168.1.108

Docker 方式无需安装,适合临时使用或 CI 环境。


核心参数速查

参数说明示例
-a <targets>目标地址,支持单 IP、CIDR、逗号分隔-a 192.168.1.108
-p <ports>指定端口范围-p 1-1000
--range <start>-<end>端口范围(替代 -p--range 1-65535
-gGreppable 输出,只输出 IP -> [ports] 格式-g
--ulimit <n>文件描述符上限,控制并发连接数--ulimit 5000
--batch-size <n>每批扫描的端口数--batch-size 2500
--timeout <ms>连接超时时间(毫秒)--timeout 3000
--tries <n>超时重试次数--tries 2
--scan-order serial顺序扫描(避免触发 IDS)--scan-order serial
-- <nmap_args>双短横线后面的参数直接传给 Nmap-- -sV -sC

常用扫描模式

1. 快速全端口扫描(Greppable 输出)

最常用的靶场打靶模式。先用 RustScan 扫出所有开放端口,再手动用 Nmap 做精细识别:

rustscan -a 192.168.1.108 -g --ulimit 5000 --batch-size 300 --timeout 3000

输出:

192.168.1.108 -> [21,22,25,53,80,139,445,2121,3128,8593,54787,62524]

然后把端口列表粘贴到 Nmap:

nmap -Pn -sV -sC -p 21,22,25,80,139,445,2121,3128,8593,54787,62524 192.168.1.108

2. RustScan + Nmap 一条龙

使用 -- 分隔符,RustScan 扫完端口后自动调用 Nmap:

rustscan -a 192.168.1.108 --ulimit 5000 -- -sV -sC

等同于先 RustScan 扫端口,再自动执行 nmap -sV -sC -p <发现的端口> 192.168.1.108

3. 指定端口范围

只扫常见端口:

rustscan -a 192.168.1.108 -p 1-1000 --ulimit 5000

4. 多目标扫描

# 逗号分隔
rustscan -a 192.168.1.1,192.168.1.2,192.168.1.3 -g

# CIDR
rustscan -a 192.168.1.0/24 -g --ulimit 3000

5. 从文件读取目标

rustscan -a targets.txt -g --ulimit 3000

性能调优

ulimit 与 batch-size 的关系

  • --ulimit:控制程序可以打开的最大文件描述符数量,直接决定并发连接上限。
  • --batch-size:每批次扫描的端口数量。RustScan 会分批次扫描,每批扫完再扫下一批。
场景ulimitbatch-size说明
本地靶场 (VirtualBox/VMware)50002500-5000本地网络延迟低,可以激进
远程 VPS / HackTheBox30001500避免丢包和误判
隐蔽扫描1000500降低速度,减少日志特征

常见问题

扫描结果不全 / 漏端口

# 增加超时和重试次数
rustscan -a target -g --ulimit 3000 --timeout 5000 --tries 3

ulimit 报错 "Too many open files"

# 临时提高系统限制(Linux)
ulimit -n 65535

# 或降低 RustScan 的 ulimit 值
rustscan -a target --ulimit 2000

Docker 用法

当系统不方便安装时,Docker 是最干净的方案:

# 基本扫描
docker run -it --rm rustscan/rustscan -a 192.168.1.108 -g

# 联动 Nmap
docker run -it --rm rustscan/rustscan -a 192.168.1.108 -- -sV -sC

# 挂载本地文件(目标列表)
docker run -it --rm -v $(pwd):/input rustscan/rustscan -a /input/targets.txt -g

Docker 内已内置 Nmap,-- 后的参数会直接传递。


实战工作流

靶场打靶的标准侦察流程:

1. RustScan 全端口扫描 → 拿到开放端口列表
2. Nmap 服务版本识别 (-sV) + 默认脚本 (-sC)
3. 针对发现的 HTTP 端口 → Gobuster / Feroxbuster 目录枚举
4. 针对特定服务 → 专用工具(smbclient、ftp、smtp 等)

与 Nmap 对比

对比项RustScanNmap (-p-)
全端口扫描速度本地靶场通常几秒到几十秒,取决于网络、超时和并发参数数分钟到数十分钟
服务识别不支持(依赖 Nmap)原生支持 -sV
脚本引擎支持(Python/Lua/Shell)NSE(Lua)
OS 检测不支持原生支持 -O
隐蔽扫描有限(TCP Connect)SYN/FIN/NULL 等多种
适用场景快速发现 → 交给 Nmap精细扫描和深度分析

最佳实践:RustScan 做端口发现,Nmap 做服务识别和漏洞探测。两者配合使用,而非替代。


相关知识