相比人畜無害的被動信息收集,主動信息收集的動作有點攻擊性的暗示。
因為被動信息收集我們收集的是網絡上目標的有關信息並不會直接訪問目標,而主動信息收集是直接與目標系統進行交互通信的額,無法避免留下訪問的痕跡。
作為滲透測試者可以用一下幾點做好保護工作:
- 使用代理或者已被控制的靶機
- 使用噪聲迷惑目標,淹沒真實的探測流量
- 做好被封殺的准備
所謂主動信息收集,重要一筆就是掃描:發送不同的探測,根據返回結果判斷目標狀態
steps:
ip主機----端口-----服務---
二層發現(ARP掃描)----ARPING
只能發現本網段的,不能路由
root@kali:~# arping -h Usage: arping [-fqbDUAV] [-c count] [-w timeout] [-I device] [-s source] destination -f : quit on first reply -q : be quiet -b : keep broadcasting, don't go unicast -D : duplicate address detection mode -U : Unsolicited ARP mode, update your neighbours -A : ARP answer mode, update your neighbours -V : print version and exit -c count : how many packets to send -w timeout : how long to wait for a reply -I device : which ethernet device to use -s source : source ip address destination : ask for what ip address
-d : 發現重復回應
arping -c 1 1.1.1.1 arping -d 1.1.1.1 #用於探測網絡是否存在偽造路由 中間人,在網絡中從同一地址發包有兩個不同MAC有同一IP
arping -c 1 192.168.56.1 |grep "reply from" |cut -d " " -f 4 #|cut -d 分割符 -f 第幾片
插入一個小腳本學習:

#!/bin/bash if [ "$#" -ne 1 ];then #echo的都是廢話,忽略可 echo "Usage: ./arping.sh [interface]" echo "Example: ./arping.sh eth0" echo " Example will perform an arp scan of the local subnet to which is assigned" exit fi interface=$1 prefix=$(ifconfig $interface |grep "inet addr" |cut -d ":" -f 2 |cut -d "" -f 1 |cut -d "." -f 1-3) for addr in $(seq 1 254);do arping -I $interface -c 1 $prefix.$addr |grep "reply from" |cut -d " " -f 4 done
其實,最牛掰的還是數nmap,后面會單獨介紹。
這里用二層掃描,參數sn: ping scan
nmap -sn 10.0.4.0/24 #速度快、還可以探測主機設備信息
#還支持對文本文件傳入掃描
nmap -iL addr.text -sn
-iL <inputfilename>: Input from list of hosts/networks
二層發現還有一個工具:netdiscover
- 專用於二層發現
- 可用於無線和交換網絡環境
- 主動和被動發現
主動:(主動的容易引發報警)
netdiscover -i eth0 -r 1.1.1.0/24 netdiscover -l iplist.txt
被動:(混雜模式)
netdiscover -p
二層發現還有一個工具:scapy
(當然也可以用在三層發現)
- 可作為python庫進行調用
- 也可作為單獨的工具使用
- 抓包、分析、創建修改、注入網絡流量
INFO: Can't import matplotlib. Won't be able to plot. WARNING: No route found for IPv6 destination :: (no default route?) #如果首次啟用會有這個警告,可以安裝gnuplot apt-get install python3-gnuplot scapy ARP().display() sr1() //發包

root@kali:~# scapy INFO: Can't import matplotlib. Won't be able to plot. WARNING: No route found for IPv6 destination :: (no default route?) aSPY//YASa apyyyyCY//////////YCa | sY//////YSpcs scpCY//Pp | Welcome to Scapy ayp ayyyyyyySCP//Pp syY//C | Version 2.4.0 AYAsAYYYYYYYY///Ps cY//S | pCCCCY//p cSSps y//Y | https://github.com/secdev/scapy SPPPP///a pP///AC//Y | A//A cyP////C | Have fun! p///Ac sC///a | P////YCpc A//A | Craft packets like it is your last scccccp///pSP///p p//Y | day on earth. sY/////////y caa S//P | -- Lao-Tze cayCyayP//Ya pY/Ya | sY/PsY////YCc aC//Yp sc sccaCY//PCypaapyCP//YSs spCPY//////YPSps ccaacs using IPython 5.5.0 >>> ARP().display <bound method ARP.display of <ARP |>> >>> ARP().display() ###[ ARP ]### hwtype= 0x1 ptype= 0x800 hwlen= 6 plen= 4 op= who-has hwsrc= 00:0c:29:f0:7b:6e psrc= 192.168.56.134 hwdst= 00:00:00:00:00:00 pdst= 0.0.0.0 >>> arp=ARP() >>> arp.pdst="192.168.56.1" >>> arp.display() ###[ ARP ]### hwtype= 0x1 ptype= 0x800 hwlen= 6 plen= 4 op= who-has hwsrc= 00:0c:29:f0:7b:6e psrc= 192.168.56.134 hwdst= 00:00:00:00:00:00 pdst= 192.168.56.1 >>> sr1(arp) Begin emission: *Finished sending 1 packets. Received 1 packets, got 1 answers, remaining 0 packets <ARP hwtype=0x1 ptype=0x800 hwlen=6 plen=4 op=is-at hwsrc=00:50:56:c0:00:08 psrc=192.168.56.1 hwdst=00:0c:29:f0:7b:6e pdst=192.168.56.134 |<Padding load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |>> >>> anwser=sr1(arp) Begin emission: *Finished sending 1 packets. Received 1 packets, got 1 answers, remaining 0 packets >>> anwser.display() ###[ ARP ]### hwtype= 0x1 ptype= 0x800 hwlen= 6 plen= 4 op= is-at hwsrc= 00:50:56:c0:00:08 psrc= 192.168.56.1 hwdst= 00:0c:29:f0:7b:6e pdst= 192.168.56.134 ###[ Padding ]### load= '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' >>>
腳本示例:你看 len(sys.argv)!=2 也就是命令和參數一共2個;相比shell不同,那是1個
發現:三層發現
ICMP
ping
traceroute中的***是人家沒回你 人家牆ping了
nmap 1.1.1.1 -sn
fping 192.168.1.1

fping 是一個將 ICMP echo 探測器發送到網絡主機的程序,類似於 ping,可以看作是 ping 的增強版。但是 fping 在 ping多個主機時性能更好。 Usage: fping [options] [targets...] -a 顯示存活目標,即可ping通的目標 -A 將目標以ip地址的形式顯示 -b n ping 數據包的大小。(默認為56) -B f set exponential backoff factor to f -c n ping每個目標的次數 (默認為1) -C n 同-c, 返回的結果為冗長格式 -D 每個輸出行打印時間戳 -e 顯示返回數據包所費時間 -f file 從文件獲取目標列表( - 表示從標准輸入)(不能與 -g 同時使用) -g 生成目標列表(不能與 -f 同時使用) (可指定目標的開始和結束IP, 或者提供ip的子網掩碼) (例:fping -g 192.168.1.0 192.168.1.255 或 fping -g 192.168.1.0/24) -H n 設置ip的TTL值 (生存時間) -i n ping包之間的間隔(單位:毫秒)(默認25) -I if 綁定到特定的接口 -l 循環發送ping -m ping目標主機的多個網口 -M 設置不分段標記 -n 將目標以主機名或域名顯示(等價於 -d ) -N 輸出兼容netdata (-l -Q are required) -o 顯示累計中斷時間 (lost packets * packet interval) -O n 在ICMP包中設置服務的類型(tos)標志 -p n 對同一個目標的ping包間隔(毫秒) (在循環和統計模式中,默認為1000) -q 安靜模式(不顯示每個目標或每個ping的結果) -Q n 同-q, 但是每n秒顯示信息概要 -r n 當ping失敗時,最大重試次數(默認為3次) -R random packet data (to foil link data compression) -s 打印最后的統計數據 -S addr 設置源ip地址 -t n 單個目標的超時時間(毫秒)(默認500) -T n 請忽略(為兼容fping 2.4) -u 顯示不可到達的目標 -v 顯示版本號 targets 需要ping的目標列表(不能和 -f 同時使用)
fping可以對地址段進行ping
fping -g 192.168.1.100 192.168.1.200 -c 1
hping3 1.1.1.1 --icmp -c 2
- 功能強大但每次只能一個目標
- 能發送幾乎TCP\IP的任意包
hping3使用詳解
可參考:https://boke.wsfnk.com/archives/695.html
https://blog.csdn.net/X_namexi/article/details/98053818

[05:12:28][root@ubuntu]~# hping3 -h usage: hping3 host [options] -h --help show this help -v --version show version -c --count packet count -i --interval wait (uX for X microseconds, for example -i u1000) --fast alias for -i u10000 (10 packets for second) --faster alias for -i u1000 (100 packets for second) --flood sent packets as fast as possible. Don't show replies. -n --numeric numeric output -q --quiet quiet -I --interface interface name (otherwise default routing interface) -V --verbose verbose mode -D --debug debugging info -z --bind bind ctrl+z to ttl (default to dst port) -Z --unbind unbind ctrl+z --beep beep for every matching packet received Mode default mode TCP -0 --rawip RAW IP mode -1 --icmp ICMP mode -2 --udp UDP mode -8 --scan SCAN mode. Example: hping --scan 1-30,70-90 -S www.target.host -9 --listen listen mode IP -a --spoof spoof source address --rand-dest random destionation address mode. see the man. --rand-source random source address mode. see the man. -t --ttl ttl (default 64) -N --id id (default random) -W --winid use win* id byte ordering -r --rel relativize id field (to estimate host traffic) -f --frag split packets in more frag. (may pass weak acl) -x --morefrag set more fragments flag -y --dontfrag set don't fragment flag -g --fragoff set the fragment offset -m --mtu set virtual mtu, implies --frag if packet size > mtu -o --tos type of service (default 0x00), try --tos help -G --rroute includes RECORD_ROUTE option and display the route buffer --lsrr loose source routing and record route --ssrr strict source routing and record route -H --ipproto set the IP protocol field, only in RAW IP mode ICMP -C --icmptype icmp type (default echo request) -K --icmpcode icmp code (default 0) --force-icmp send all icmp types (default send only supported types) --icmp-gw set gateway address for ICMP redirect (default 0.0.0.0) --icmp-ts Alias for --icmp --icmptype 13 (ICMP timestamp) --icmp-addr Alias for --icmp --icmptype 17 (ICMP address subnet mask) --icmp-help display help for others icmp options UDP/TCP -s --baseport base source port (default random) -p --destport [+][+]<port> destination port(default 0) ctrl+z inc/dec -k --keep keep still source port -w --win winsize (default 64) -O --tcpoff set fake tcp data offset (instead of tcphdrlen / 4) -Q --seqnum shows only tcp sequence number -b --badcksum (try to) send packets with a bad IP checksum many systems will fix the IP checksum sending the packet so you'll get bad UDP/TCP checksum instead. -M --setseq set TCP sequence number -L --setack set TCP ack -F --fin set FIN flag -S --syn set SYN flag -R --rst set RST flag -P --push set PUSH flag -A --ack set ACK flag -U --urg set URG flag -X --xmas set X unused flag (0x40) -Y --ymas set Y unused flag (0x80) --tcpexitcode use last tcp->th_flags as exit code --tcp-mss enable the TCP MSS option with the given value --tcp-timestamp enable the TCP timestamp option to guess the HZ/uptime Common -d --data data size (default is 0) -E --file data from file -e --sign add 'signature' -j --dump dump packets in hex -J --print dump printable characters -B --safe enable 'safe' protocol -u --end tell you when --file reached EOF and prevent rewind -T --traceroute traceroute mode (implies --bind and --ttl 1) --tr-stop Exit when receive the first not ICMP in traceroute mode --tr-keep-ttl Keep the source TTL fixed, useful to monitor just one hop --tr-no-rtt Don't calculate/show RTT information in traceroute mode ARS packet description (new, unstable) --apd-send Send the packet described with APD (see docs/APD.txt) [05:12:45][root@ubuntu]~#
hping 是 面向命令行的用於生成和解析TCP/IP協議數據包匯編/分析的開源工具。作者是Salvatore Sanfilippo,界面靈感來自ping(8)unix命令,目前最新版是 hping3,它支持TCP,UDP,ICMP和RAW-IP協議,具有跟蹤路由模式,能夠在覆蓋的信道之間發送文件以及許多其他功能,支持使用tcl腳本自動化地調用其API。hping是安全審計、防火牆測試等工作的標配工具。hping 優勢在於能夠定制數據包的各個部分,因此用戶可以靈活對目標機進行細致地探測。
雖然 hping 以前主要用作安全工具,但它可以在許多方面被不太關心安全性的人員用於測試網絡和主機,您可以使用hping的一小部分內容:
- 防火牆測試 - 高級端口掃描 - 網絡測試,使用不同的協議,TOS,分片 - 手動路徑MTU發現 - 在所有支持的協議下,高級traceroute - 遠程操作系統指紋 - 遠程正常運行時間猜測 - TCP/IP協議棧審計 - hping也可以用於學習TCP/IP的學生
用法: hping3 host [options] -h --help 顯示幫助 -v --version 顯示版本 -c --count 發送數據包的數目 -i --interval 發送數據包間隔的時間 (uX即X微秒, 例如: -i u1000) --fast 等同 -i u10000 (每秒10個包) --faster 等同 -i u1000 (每秒100個包) --flood 盡最快發送數據包,不顯示回復。 -n --numeric 數字化輸出,象征性輸出主機地址。 -q --quiet 安靜模式 -I --interface 網卡接口 (默認路由接口) -V --verbose 詳細模式 -D --debug 調試信息 -z --bind 綁定ctrl+z到ttl(默認為目的端口) -Z --unbind 取消綁定ctrl+z鍵 --beep 對於接收到的每個匹配數據包蜂鳴聲提示
模式選擇
default mode TCP // 默認模式是 TCP -0 --rawip RAWIP模式,原始IP模式。在此模式下HPING會發送帶數據的IP頭。即裸IP方式。使用RAWSOCKET方式。 -1 --icmp ICMP模式,此模式下HPING會發送IGMP應答報,你可以用--ICMPTYPE --ICMPCODE選項發送其他類型/模式的ICMP報文。 -2 --udp UDP 模式,缺省下,HPING會發送UDP報文到主機的0端口,你可以用--baseport --destport --keep選項指定其模式。 -8 --scan SCAN mode. //掃描模式 指定掃描對應的端口。 Example: hping --scan 1-30,70-90 -S www.target.host // 掃描 -9 --listen listen mode // 監聽模式
IP 模式
-a --spoof spoof source address //源地址欺騙。偽造IP攻擊,防火牆就不會記錄你的真實IP了,當然回應的包你也接收不到了。 --rand-dest random destionation address mode. see the man. // 隨機目的地址模式。詳細使用 man 命令 --rand-source random source address mode. see the man. // 隨機源地址模式。詳細使用 man 命令 -t --ttl ttl (默認 64) //修改 ttl 值 -N --id id (默認 隨機) // hping 中的 ID 值,缺省為隨機值 -W --winid 使用win* id字節順序 //使用winid模式,針對不同的操作系統。UNIX ,WINDIWS的id回應不同的,這選項可以讓你的ID回應和WINDOWS一樣。 -r --rel 相對id字段(估計主機流量) //更改ID的,可以讓ID曾遞減輸出,詳見HPING-HOWTO。 -f --frag 拆分數據包更多的frag. (may pass weak acl) //分段,可以測試對方或者交換機碎片處理能力,缺省16字節。 -x --morefrag 設置更多的分段標志 // 大量碎片,淚滴攻擊。 -y --dontfrag 設置不分段標志 // 發送不可恢復的IP碎片,這可以讓你了解更多的MTU PATH DISCOVERY。 -g --fragoff set the fragment offset // 設置斷偏移。 -m --mtu 設置虛擬最大傳輸單元, implies --frag if packet size > mtu // 設置虛擬MTU值,當大於mtu的時候分段。 -o --tos type of service (default 0x00), try --tos help // tos字段,缺省0x00,盡力而為? -G --rroute includes RECORD_ROUTE option and display the route buffer // 記錄IP路由,並顯示路由緩沖。 --lsrr 松散源路由並記錄路由 // 松散源路由 --ssrr 嚴格源路由並記錄路由 // 嚴格源路由 -H --ipproto 設置IP協議字段,僅在RAW IP模式下使用 //在RAW IP模式里選擇IP協議。設置ip協議域,僅在RAW ip模式使用。
ICMP 模式
-C --icmptype icmp類型(默認echo請求) // ICMP類型,缺省回顯請求。 -K --icmpcode icmp代號(默認0) // ICMP代碼。 --force-icmp 發送所有icmp類型(默認僅發送支持的類型) // 強制ICMP類型。 --icmp-gw 設置ICMP重定向網關地址(默認0.0.0.0) // ICMP重定向 --icmp-ts 等同 --icmp --icmptype 13 (ICMP 時間戳) // icmp時間戳 --icmp-addr 等同 --icmp --icmptype 17 (ICMP 地址子網掩碼) // icmp子網地址 --icmp-help 顯示其他icmp選項幫助 // ICMP幫助
UDP/TCP 模式
-s --baseport base source port (default random) // 缺省隨機源端口 -p --destport [+][+]<port> destination port(default 0) ctrl+z inc/dec // 缺省隨機源端口 -k --keep keep still source port // 保持源端口 -w --win winsize (default 64) // win的滑動窗口。windows發送字節(默認64) -O --tcpoff set fake tcp data offset (instead of tcphdrlen / 4) // 設置偽造tcp數據偏移量(取代tcp地址長度除4) -Q --seqnum shows only tcp sequence number // 僅顯示tcp序列號 -b --badcksum (嘗試)發送具有錯誤IP校驗和數據包。許多系統將修復發送數據包的IP校驗和。所以你會得到錯誤UDP/TCP校驗和。 -M --setseq 設置TCP序列號 -L --setack 設置TCP的ack ------------------------------------- (不是 TCP 的 ACK 標志位) -F --fin set FIN flag -S --syn set SYN flag -R --rst set RST flag -P --push set PUSH flag -A --ack set ACK flag ------------------------------------- (設置 TCP 的 ACK 標志 位) -U --urg set URG flag // 一大堆IP包頭的設置。 -X --xmas set X unused flag (0x40) -Y --ymas set Y unused flag (0x80) --tcpexitcode 使用last tcp-> th_flags作為退出碼 --tcp-mss 啟用具有給定值的TCP MSS選項 --tcp-timestamp 啟用TCP時間戳選項來猜測HZ/uptime
Common //通用設置
-d --data data size (default is 0) // 發送數據包大小,缺省是0。 -E --file 文件數據 -e --sign 添加“簽名” -j --dump 轉儲為十六進制數據包 -J --print 轉儲為可打印字符 -B --safe 啟用“安全”協議 -u --end 告訴你什么時候--file達到EOF並防止倒回 -T --traceroute traceroute模式(等同使用 --bind 且--ttl 1) --tr-stop 在traceroute模式下收到第一個不是ICMP時退出 --tr-keep-ttl 保持源TTL固定,僅用於監視一跳 --tr-no-rtt 不要在跟蹤路由模式下計算/顯示RTT信息 ARS包描述(新增功能,不穩定) ARS packet description (new, unstable) --apd-send 發送APD描述數據包(參見docs / APD.txt)
應用實例:

#DOS攻擊(Syn Flood攻擊) -c 指定連接數 -p 目標端口 -d 指定數據部分的大小 -S 攻擊類型是Syn flood --flood 以泛洪的方式攻擊 --rand-source 隨機產生偽造源地址 hping3 -c 1000 -d 120 -S -p 80 --flood --rand-source 192.168.100.1 #-P flag置為Push -U flag置為Urge緊急(加這兩參數可以提高效率) hping3 -S -P -U -p 80 --flood --rand-source 192.168.100.1 #TCP Flood攻擊(使用以下命令建立全連接,經過測試把自己搞死了) hping3 -SARUPF -p 80 --flood --rand-source 192.168.100.1 #ICMP Flood攻擊 -q安靜模式 -n不解析域名 -a指定偽造IP hping3 -q -n -d 200 --icmp --flood -a 11.11.11.11 192.168.100.1 #UDP Flood 攻擊 hping3 --udp -s 6666 -p 53 -a 8.8.8.8 --flood 192.168.100.1 #LAND攻擊(大部分系統已經不會響應該種報文了,例如centos7,也就是說不會占用半連接) hping3 -n -S -p 80 -a 192.168.100.1 --flood 192.168.100.1 應對措施: 可以通過防火牆、路由設備,建立規則,丟掉源地址和目標地址相同的 SYN、SYN+ACK 和 TCP。
Ddos攻擊:
hping3 -c 1000 -d 120 -S -p 80 --flood --rand-source 192.168.100.1
#Hping3也可以對目標端口進行掃描。Hping3支持指定TCP各個標志位、長度等信息。以下示例可用於探測目標機的80端口是否開放:
hping3 -I eth0 -S 192.168.10.1 -p 80
#其中-I eth0指定使用eth0端口,-S指定TCP包的標志位SYN,-p 80指定探測的目的端口。
四層發現:TCP UDP掃描
端口掃描
隱蔽掃描——syn 不建立完整連接應用日志不記錄掃描行為-隱蔽
僵屍掃描
- 極度隱蔽
- 實施條件苛刻
- 可偽造源地址
- 選擇僵屍機
- 閑置系統系統
- 使用遞增的IPID
僵屍掃描
前提是要找到一個合格的僵屍機。幾乎閑置,沒有3層的通信。IPID是遞增的
就是實現源地址偽造。
實現的工具有兩種:
1.Scapy
2.namp
發現僵屍機 nmap -p445 192.168.1.133 --script=ipidseq.nse 掃描目標 nmap 172.16.36.135 -sI 172.16.36.133 -Pn -p 0-100
服務掃描
識別開放端口上運行的應用
識別目標操作系統
提高攻擊效率
- Banner捕獲
- 服務識別
- 操作系統識別
- SNMP分析
- 防火牆識別
1.基於pyhton socket的鏈接:
>>> import socket >>> banner=socket.socket(socket.AF_INET,socket.SOCK_STREAM) >>> banner.connect(("10.0.47.3",21)) >>> banner.recv(4096) ‘220 (vsFTPd 2.3.4)\r\n’
>>> banner.close()
2.基於nmap
nmap -sT 1.1.1.1 -p 22 --script=banner.nse // 端口也可以是 -p1-100
3.基於amap
amap就是專門一個針對發現開放端口開放什么服務的工具
amap -B 172.16.36.135 21 amap -B 172.16.36.135 1-65535
amap 192.168.1.1 1-100 -qb //詳細服務識別
4.基於nc
- Bannert信息抓取能力有限
- nmap響應特征分析識別服務
- 發送系列復雜的探測
- 依據響應特征 signature
- nc -nv 1.1.1.1 80
- nmap 1.1.1.1 -p80 -sV //不是基於banner,而是基於指紋特征值
操作系統識別
- TTL起始值Windows:128(65-128)
- Linux/Unix:64 (1-64)
- 某些Unix:255
每經過一個路由,TTL值就減一
使用nmap
nmap 1.1.1.1 -O
SNMP掃描
- snmp信息的金礦
- 經常被錯誤配置
- public prtvate /manager
MIB Tree
SNMP Management Information Base (MIB)
樹形的網絡設備管理功能數據庫
1.3.6.1.4.1.77.1.2.25
onesixtyone 1 1. 1.1 public
onesixtyone-c dict txt -i hosts -o my.log -w 100
SNMP掃描
snmpwalk 192. 168.20 199-c public -v 2C 用戶 snmpwalk -c public -v 2c 1.1.1.1 1.3.6.1.4.1.77.1.2.25 sumcheck -t 192.168.20.199 snmpcheck -t 192.168.20.199 -c private - 2 sumpcheck -t 192.168.20.199 -w
公眾號:ethtool