掃 port 最速工具軟體 – RustScan

by iok
發佈日期: 更新日期: 5.2K 人次瀏覽
rustscan

前言

*請留意文章中提到的掃描工具軟體,請在授權環境下執行。

若提到掃描通訊埠軟體,第一個想到的軟體一定是 老牌的 nmap。nmap 發展歷史悠久,擁有龐大的使用者社群,掃描的準確度佳,也有為數不少的擴充的 NSE 套件。但是, nmap 缺點就是掃描大量通訊埠 ( -p 1-65535 ) 時,速度很慢。

掃描語法如下:

$ nmap -sT -T4 -p 1-65535 -r 192.168.0.1

精選圖片來源: Github 上的 RustScan source code

RustScan 安裝與使用說明

今天本文的主角: RustScan ,是一套以Rust 程式語言所撰寫的掃描通訊埠軟體。能解決掃描大量通訊埠的效能問題。到官網依照安裝說明,安裝即可。

以 Kali Linux 為例,先到 RustScan 的 Releases 頁面,下載 AMD 64 平台版本的deb 檔 (rustscan_2.0.1_amd64.deb)。並使用 dpkg 工具進行安裝。

$ wget https://github.com/RustScan/RustScan/releases/download/2.0.1/rustscan_2.0.1_amd64.deb
..
$ sudo dpkg -i rustscan_2.0.1_amd64.deb
Selecting previously unselected package rustscan.
(Reading database ... 329668 files and directories currently installed.)
Preparing to unpack rustscan_2.0.1_amd64.deb ...
Unpacking rustscan (2.0.0) ...
Setting up rustscan (2.0.0) ...
Processing triggers for kali-menu (2021.4.1) ...

RustScan 最簡單的掃描語法,如下:

$ rustscan -a 192.168.0.1 --scripts none  --ulimit 5000
.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: https://discord.gg/GFrQsGy           :
: https://github.com/RustScan/RustScan :
 --------------------------------------
🌍HACK THE PLANET🌍

[~] The config file is expected to be at "/home/kali/.rustscan.toml"
[~] Automatically increasing ulimit value to 5000.
Open 192.168.0.1:80
192.168.0.1 -> [80]

參數 -a 接的是掃描標的 IP,–scripts 接 none 代表掃描結束後,不接續使用其他軟體(例如 nmap)。而 –ulimit 則是設定 RustScan 即將啟動的 Process 的 File Descriptors 的系統上限 (ulimit) 改為 5000。

ulimit 原先設計用意是限制單一 Process 可佔用的系統資源數量。但現在電腦效能優越,使用 RustScan 若不修正 ulimit 數值,而 Linux 預設的 soft limit 太低(預設為 1024)時,則會導致 RustScan 發揮不出原本應有的速度。

列出 Kali Linux 原有的 ulimit 設定:

$ ulimit -a                
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       59564
-n: file descriptors                1024
-l: locked-in-memory size (kbytes)  1916636
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 59564
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited

ulimit -a 列出來是 soft limit。可以看到 file descriptors 預設上限是 1024。

若掃瞄後要搭配其他的工具接續掃描,可以參考原廠此篇文件說明 – RustScan Script Engine

比較 RustScan 與 Nmap 進行全機掃 Port 速度

主機使用 VirtualBox 模擬一台 4 個 CPU、1.5 G 記憶體並安裝最新的 Kali Linux,都掃描同一台主機的 1- 65535 Ports。並使用 time 工具程式進行執行時間測量。

Nmap 掃描時間與結果如下:

$ time nmap -sT -T4 -p 1-65535 192.168.0.1                                                                       
Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-16 20:15 EST
Nmap scan report for 192.168.0.1
Host is up (0.23s latency).
Not shown: 65534 filtered tcp ports (no-response)
PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 303.40 seconds

real    303.42s
user    2.82s
sys     7.37s
cpu     3%

RustScan 掃描時間與結果如下:

$ time rustscan -a 192.168.0.1 --scripts none --ulimit 5000 
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: https://discord.gg/GFrQsGy           :
: https://github.com/RustScan/RustScan :
 --------------------------------------
😵 https://admin.tryhackme.com

[~] The config file is expected to be at "/home/kali/.rustscan.toml"
[~] Automatically increasing ulimit value to 5000.
Open 192.168.0.1:80
192.168.0.1 -> [80]

real    22.99s
user    1.36s
sys     4.85s
cpu     27%

實測結果雖然 RustScan 沒有跑出像官方所宣稱的 3 秒鐘完賽,但 RustScan 的執行時間,比起 Nmap 足足快了 280 秒,效率上提昇了 13 倍。

結論

本文並不是要 抨擊 Nmap 不好, 使用 RustScan 才是王道,而是要在合適情境挑選最適合的工具,完成任務。發揮資安專業工作者的價值。本站也有另外一篇 9個常見的 Nmap 通訊埠掃描情境,也歡迎讀者們點擊前往閱讀。

如果你也喜歡這篇文章,歡迎分享給你的朋友。或是在底下留言,寫下你的想法。

相關文章

留言