【渗透测试】主动信息收集——二层发现

信息收集
【二层发现(数据链路层)】:
优点:扫描速度快、可靠
缺点:不可路由
协议:Arp协议

工具:arping、nmap、netdiscover、Scapy

【arping实例】
arping 1.1.1.1 -c 1 #发一个Arp包
arping 1.1.1.1 -d   #发现重复的响应,可用于检测Arp欺骗
arping -c 1 1.1.1.1 | grep "bytes from" | cut -d" " -f

5 | cut -d "(" -f 2 | cut -d")" -f 1

备注:arping在实验中的实际效果并不好,容易被防火墙过滤掉


【nmap实例】
nmap -sn 192.168.1.0/24 #只做二层发现,不做端口扫描
nmap -iL iplist.txt -sn #扫描文件中给出的IP地址
备注:方便、速度快。在实验中发现并不可靠,经常出现一个网段下所有的主机都是UP状态。

【netdiscover实例】
netdiscovr -i eth0 -r 192.168.1.0/24
netdiscover -l iplist.txt
备注:专用于二层发现,可用于无线和交换网络环境、主动和被动探测(效率低下)

【scapy实例】
终端输入:scapy进入scapy
arp=ARP()#实例化一个对象
arp.display()#查看arp包的内容
arp.pdst=192.168.1.1#定制arp包中的目的IP
sr1(arp)#发送数据包

扫描整个地址段需要写一个脚本


总结:

二层发现利用ARP协议的扫描都不可靠,准确来说,任何单一协议的扫描都是不可靠的,

原因可能有多种,笔者认为极有可能与目标主机的防火墙有关,但还未做实验验证此种猜想。

ARP扫描脚本(由于实验环境不一样,不能保证脚本一定能正常运行,仅作参考):

 1 #!/bin/bash
 2 #扫描一个地址段的shell脚本
 3 if["$#"-ne 1];then
 4     echo "Usage - ./arping.sh [interfaace]"
 5     echo "Example - ./arping.sh eth0"
 6     echo "Example will perform an ARP scan of the local subnet to which eth0 is assigned"
 7     exit
 8 fi
 9 interface=$1
10 prefix=$(ifconfig $interface | grep 'inet addr'| cut -d ' ' -f 10|cut -d '.' -f 1-3)
11 for addr in $(seq 1 254):do
12     arping -c 1 $prefix.$addr|grep "bytes from"|cut -d '' -f 5|cut -d "("-f 2|cut -d ")" -f 1
13 done
 1 #!/usr/bin/env python
 2 # _*_ coding=utf-8 _*_
 3 #扫描一个地址段的Python脚本
 4 
 5 from scapy.all import *
 6 import sys,getopt
 7 
 8 def usage():
 9         print "Usage: sudo ./ArpScanner.py "
10 
11 def main(argv):
12         try:
13                 opts, args = getopt.getopt(argv, "")
14         except getopt.GetoptError:
15                 usage()
16                 sys.exit(2)
17 
18         for ipFix in range(1,254):
19                 ip = "192.168.1."+str(ipFix)
20                 arpPkt = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip, hwdst="ff:ff:ff:ff:ff:ff")
21                 res = srp1(arpPkt, timeout=1, verbose=0)
22                 if res:
23                         print "IP: " + res.psrc + "     MAC: " + res.hwsrc
24 
25 if __name__ == "__main__":
26         main(sys.argv[1:])

猜你喜欢

转载自www.cnblogs.com/peterzone/p/9116109.html