本系列側(cè)重方法論,各工具只是實現(xiàn)目標的載體。
命令與工具只做簡單介紹,其使用另見《安全工具錄》。
本文以 kali-linux-2022.3-vmware-amd64 為例。
1:服務識別
識別開放端口上運行的應用與服務,可以提高攻擊效率。
方法:
-
Banner 捕獲
- 建立連接后獲取 Banner
- 服務指紋識別
-
另類識別方法
- 特征行為
- 可用于識別操作系統(tǒng)
Banner:指目標主機在響應請求時返回的服務標識信息。通常是一個文本字符串,包含了軟件開發(fā)商、軟件名稱、服務類型,版本號等。
根據(jù) Banner 抓取的信息有限,且不完全準確。
得到服務版本號可以直接發(fā)現(xiàn)已知漏洞和弱點。
1.1:NetCat
基本語法:nc 選項
部分選項:
參數(shù) | 說明 |
---|---|
-n |
numeric-only IP addresses, no DNS. |
-v |
verbose [use twice to be more verbose]. |
示例01:嘗試連接端口以獲取服務信息。nc -nv 1.1.1.1 22
基于 banner 捕獲。
1.2:Socket
在 Python 中,socket 標準庫用于網(wǎng)絡通信,提供的編程接口用于創(chuàng)建網(wǎng)絡套接字(socket)對象,以實現(xiàn)網(wǎng)絡連接、數(shù)據(jù)傳輸和通信協(xié)議。
示例01:banner_grab.py。基于 banner 捕獲。
#!/usr/bin/python
import socket
import select
import sys
if len(sys.argv) != 4:
print("Usage - ./banner_grab.py <target-ip> <first port> <last port>")
print("Example - ./banner_grab.py 10.1.1.1 1 250")
sys.exit()
ip = sys.argv[1]
start_ip = int(sys.argv[2])
end_ip = int(sys.argv[3])
for port in range(start_ip, end_ip):
try:
target = (ip, port)
ban_grab = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ban_grab.connect(target)
ready = select.select([ban_grab], [], [], 1)
if ready[0]:
print("TCP Port " + str(port) + " - " + ban_grab.recv(4096).decode())
ban_grab.close()
except Exception as e:
# print(e)
pass
1.3:dmitry
Deepmagic Information Gathering Tool
“There be some deep magic going on”
基本語法:dmitry 選項
部分選項:
參數(shù) | 說明 |
---|---|
-p |
Perform a TCP port scan on a host. |
-b |
Read in the banner received from the scanned port. |
示例01:
dmitry -pb 1.1.1.1
1.4:nmap
Nmap 可以發(fā)送一些列復雜的探測,根據(jù)響應特征來分析識別服務。
基本語法:nmap 選項
部分選項:
參數(shù) | 說明 |
---|---|
-sS/sT/sA/sW/sM |
TCP SYN/Connect()/ACK/Window/Maimon scans. |
-sV |
Probe open ports to determine service/version info. |
示例01:基于 banner 捕獲識別。
nmap -sT 1.1.1.1 -p 1-100 --script=banner
“ banner ” 腳本用于服務識別?;?banner 捕獲。
示例02:基于 nmap 的識別方法。
nmap 1.1.1.1 -p 1-100 -sV
2:操作系統(tǒng)識別
操作系統(tǒng)識別技術種類繁多。好的工具往往采用多種技術組合來識別。
一個簡易識別方法,TTL 起始值:
- Windows:128
- Linux:64
- 某些 Unix:256
2.1:Scapy
命令行輸入 scapy
進入或作為 python 模塊使用。
示例01:ttl_os.py?;?ttl 的簡單驗證。
#!/usr/bin/python
import logging
from scapy.all import *
from scapy.layers.inet import IP, ICMP
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
if len(sys.argv) != 2:
print('Usage - ./ttl_os.py <IP address>')
print('Example - ./ttl_os.py 10.1.1.1')
sys.exit()
ip = sys.argv[1]
ans = sr1(IP(dst=str(ip))/ICMP(), timeout=1, verbose=0)
if ans == None:
print('No response')
elif int(ans[IP].ttl) <= 64:
print('Host is Linux/Unix')
else:
print('Host is Windows')
2.2:nmap
Nmap 使用多種技術識別操作系統(tǒng)。
基本語法:nmap 選項
部分選項:
參數(shù) | 說明 |
---|---|
-O |
Enable OS detection. |
示例01:
nmap 1.1.1.1 -O
2.3:p0f
p0f(Passive OS Fingerprinting),用于被動操作系統(tǒng)指紋識別。
通過監(jiān)控網(wǎng)絡流量中的數(shù)據(jù)包并分析其特征,來確定操作系統(tǒng)類型和版本。
被動操作系統(tǒng)識別在有 IDS(Intrusion Detection System,入侵檢測系統(tǒng))時能派上用場。
基本語法:p0f [選項]
示例01:開始流量監(jiān)控并分析。
p0f
3:SNMP 掃描
信息的金礦。
經(jīng)常被錯誤配置。
SNMP(Simple Network Management Protocol)是一種用于網(wǎng)絡設備管理和監(jiān)控的協(xié)議,提供了一種標準的方式來收集、組織和傳輸網(wǎng)絡設備的信息。
- SNMP 常使用 161 端口。
SNMP 允許網(wǎng)絡管理員監(jiān)視和管理網(wǎng)絡中的設備,例如路由器、交換機、服務器和打印機等。
SNMP 基本工作原理:
管理器發(fā)送請求(Get、Set、Trap 等)到目標設備,目標設備響應請求并提供所需的信息。包括設備狀態(tài)、性能指標、配置參數(shù)、事件通知等。
MIB(Management Information Base)是 SNMP 協(xié)議定義的一種樹形網(wǎng)絡設備管理功能數(shù)據(jù)庫,用于描述網(wǎng)絡設備中可管理的對象和屬性。
每個網(wǎng)絡設備都有一個特定的 MIB,其中包含了可查詢和操作的對象。通過 SNMP 協(xié)議,管理器可以使用 OID(對象標識符)來訪問和操作 MIB 中的信息。
3.1:onesixtyone
onesixtyone 用于 SNMP 字典攻擊。
主要原理是嘗試使用不同的社區(qū)字符串(community string)對目標設備執(zhí)行 SNMP 查詢,以發(fā)現(xiàn)設備的 MIB 數(shù)據(jù)。
Community String 是用于訪問和管理網(wǎng)絡設備的一種憑證或密碼。SNMP 中,Community String 被用作一種簡單的身份驗證機制,用于控制對設備的訪問權限。
基本語法:onesixtyone 選項
部分選項:
參數(shù) | 說明 |
---|---|
Community String |
指定社區(qū)字符串。 |
-c <communityfile> |
file with community names to try. |
-o <outputfile> |
output log. |
-w n |
wait n milliseconds (1/1000 of a second) between sending packets (default 10). |
示例01:使用 public 作為社區(qū)字符串。
onesixtyone 1.1.1.1 public
示例02:
onesixtyone -c /usr/share/doc/onesixtyone/dict.txt 1.1.1.1 -o my.log -w 100
3.2:snmpwalk
snmpwalk 用于執(zhí)行 SNMP Walk 操作,用于獲取網(wǎng)絡設備的管理信息。
SNMP Walk 操作:
是一種遍歷 SNMP 設備的 MIB 樹的過程,以收集設備上可用的 SNMP 對象和相關信息。
基本語法:snmpwalk 選項
部分選項:
參數(shù) | 說明 |
---|---|
-c COMMUNITY |
set the community string. |
-v 1/2c/3 |
specifies SNMP version to use. |
示例01:
snmpwalk 1.1.1.1 -c public -v 2c
3.3:snmpcheck
snmpcheck 通過執(zhí)行一系列 SNMP 查詢和測試,檢查目標設備的 SNMP 實現(xiàn)和配置,并提供相關的信息和報告。
基本語法:snmpcheck 選項
4:SMB 掃描
SMB(Server Message Block)是一種用于在計算機網(wǎng)絡上共享文件、打印機和其他資源的協(xié)議。最初由微軟開發(fā),已成為主流網(wǎng)絡操作系統(tǒng)中常見的文件和打印共享協(xié)議之一。
- SMP 常使用 139 或 445 端口。
SMB 協(xié)議允許客戶端通過網(wǎng)絡與服務器通信,并請求對文件和資源的訪問、讀取、寫入和管理。通過 SMB,用戶可以在局域網(wǎng)或廣域網(wǎng)上共享文件夾、打印機和其他網(wǎng)絡資源。
- 微軟歷史上出現(xiàn)安全問題最多的協(xié)議
- 實現(xiàn)復雜
- 默認開放
- 文件共享
4.1:nmap
基本語法:nmap 選項
部分選項:
參數(shù) | 說明 |
---|---|
--script=<Lua scripts> |
Lua scripts is a comma separated list of directories, script-files or script-categories. |
--script-args=<n1=v1,[n2=v2,...]> |
provide arguments to scripts. |
可以到 /usr/share/nmap/scripts/ 目錄下查看所有 nmap 腳本。
可以查看某個腳本內(nèi)容以了解其功能與參數(shù)使用。
示例01:簡單掃描 139,445 端口。
nmap -v -p 139,445 1.1.1.1-20
示例02:
nmap 1.1.1.1 -p 139,445 --script=smb-os-discovery.nse
smb-os-discovery.nse 腳本用于通過 SMB 協(xié)議進行信息發(fā)現(xiàn)和識別。
4.2:nbtscan
nbtscan 用于掃描局域網(wǎng)中的 NetBIOS(Network Basic Input/Output System)信息。
NetBIOS 是一種在早期 Windows 網(wǎng)絡中廣泛使用的協(xié)議,用于在局域網(wǎng)上識別和通信。
鑒于現(xiàn)在的發(fā)展,nbtscan 在對付古老的系統(tǒng)時可能會起到作用,現(xiàn)在可能用處已經(jīng)不大。
基本語法:nbtscan 選項
部分選項:
參數(shù) | 說明 |
---|---|
-r |
use local port 137 for scans. Win95 boxes respond to this only. |
示例01:
nbtscan -r 192.168.60.0/24
4.3:enum4linux
enum4linux 用于枚舉和收集信息。通過與目標系統(tǒng)的 SMB 協(xié)議交互獲取信息。
基本語法:enum4linux 選項
部分選項:
參數(shù) | 說明 |
---|---|
-a |
Do all simple enumeration (-U -S -G -P -r -o -n -i). |
示例01:
enum4linux -a 192.168.60.10
5:SMTP 掃描
SMTP(Simple Mail Transfer Protocol)是一種用于電子郵件傳輸?shù)臉藴蕝f(xié)議。
SMTP 本身沒有提供任何身份驗證或加密機制,需要結(jié)合其他安全機制確保郵件傳輸?shù)陌踩浴?/p>
SMTP 掃描主要用來發(fā)現(xiàn)郵件賬號。
5.1:NetCat
基本語法:nc 選項
示例01:
nc -nv 1.1.1.1 25
5.2:nmap
基本語法:nmap 選項
示例01:
nmap smtp.163.com -p 25 --script=smtp-enum-users.nse --script-args=smtp-enumusers.methods={VRFY}
smtp-enum-users.nse 用于枚舉SMTP服務器上存在的有效用戶。
smtp-enumusers.methods={VRFY} 指定腳本使用 VRFY 方法進行用戶枚舉。
示例02:
nmap smtp.163.com -p 25 --script=smtp-open-relay.nse
smtp-open-relay.nse 用于檢測 SMTP 服務器是否開放了中繼(Open Relay)功能。
中繼是指允許未經(jīng)身份驗證的第三方通過 SMTP 服務器發(fā)送電子郵件的功能。
5.3:smtp-user-enum
smtp-user-enum 用于枚舉 SMTP 服務器上存在的有效用戶。
基本語法:smtp-user-enum 選項
部分選項:
參數(shù) | 說明 |
---|---|
-M mode |
Method to use for username guessing EXPN, VRFY or RCPT (default: VRFY). |
-U file |
File of usernames to check via smtp service. |
-t host |
Server host running smtp service. |
示例01:
smtp-user-enum -M VRFY -U users.txt -t 10.0.0.1
6:防火墻識別
通過發(fā)送數(shù)據(jù)包并檢查回包,可能識別端口是否經(jīng)過防火墻過濾。
主要情況有以下四種:
由于設備的不同,結(jié)果存在一定誤差。
6.1:Scapy
示例01:FW.py?;诎l(fā)送包并檢查回包。
#!/usr/bin/python
import logging
import sys
from scapy.all import *
from scapy.layers.inet import IP, TCP
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
if len(sys.argv) != 3:
print('Usage - ./FW.py <IP address> <Port>')
print('Example - ./FW.py 10.1.1.1 443')
sys.exit()
ip = sys.argv[1]
port = int(sys.argv[2])
ACK_response = sr1(IP(dst=str(ip))/TCP(dport=port, flags='A'), timeout=1, verbose=0)
SYN_response = sr1(IP(dst=str(ip))/TCP(dport=port, flags='S'), timeout=1, verbose=0)
if (ACK_response == None) and (SYN_response == None):
print('Port is either unstatefully filtered or host is down')
elif ((ACK_response == None) or (SYN_response == None)) and not ((ACK_response == None) and (SYN_response == None)):
print('Stateful filtering in place')
elif int(SYN_response[TCP].flags == 18):
print('Port is unfiltered and open')
elif int(SYN_response[TCP].flags == 20):
print('Port is unfiltered and closed')
else:
print('Unable to determine if the port is filtered')
6.2:nmap
nmap 帶有一系列防火墻過濾檢測功能。
基本語法:nmap 選項
示例01:
nmap -sA 1.1.1.1 -p 22
7:負載均衡識別
負載均衡器是一種網(wǎng)絡設備或軟件,用于在多個服務器之間平衡傳入流量,以提高性能和可靠性。
- DNS-Loadbalancing:DNS 輪巡,智能 DNS。
- HTTP-Loadbalancing。
7.1:lbd
LBD 用于查詢和檢測負載均衡。
lbd - load balancing detector.
基本語法:lbd 選項
示例01:
lbd www.baidu.com
8:WAF 識別
WAF(Web Application Firewall,Web 應用防火墻)用于保護 Web 應用程序免受常見的網(wǎng)絡攻擊。
8.1:wafw00f
wafw00f 用于識別 WAF。通過分析 HTTP 響應頭、頁面內(nèi)容和錯誤消息等信息,來識別是否存在 WAF 及可能的 WAF 類型。
The Web Application Firewall Fingerprinting Toolkit.
基本語法:wafw00f 選項
部分選項:
參數(shù) | 說明 |
---|---|
url |
要探測的網(wǎng)站 url。 |
-l, --list |
List all WAFs that WAFW00F is able to detect. |
示例01:
wafw00f http://www.baidu.com
8.2:nmap
基本語法:nmap 選項
示例01:
nmap www.baidu.com --script=http-waf-detect.nse
http-waf-detect.nse 腳本用于檢測 WAF 的存在。
人世幾回傷往事,山形依舊枕寒流。 文章來源:http://www.zghlxwxcb.cn/news/detail-478233.html
——《西塞山懷古》(唐)劉禹錫 文章來源地址http://www.zghlxwxcb.cn/news/detail-478233.html
到了這里,關于《Kali滲透基礎》06. 主動信息收集(三)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!