二层采集(发送arp包)
arping工具收集二层信息
arping 192.168.1.1 -c 1
arping 192.168.1.1 -d 发现不同mac拥有同一个ip(中间人攻击)
arping -c 1.1.1.1 | grep "bytes from" | cut -d " " -f 5 |cut -d "(" -f 2 | cut -d ")" -f 1
编写脚本自动的去扫描二层的活地址
#!/bin/bash
#该脚本主要用户实现扫描文件中的IP地址列表
FILE=$1
for addr in $(cat $FILE)
do
arping -c 1 $addr | grep "reply from" | cut -d" " -f 4
done
nmap收集二层信息
nmap -sn 192.168.1.0/24 或者 192.168.1-254
nmap -iL ip.txt -sn
Netdiscover,专业于二层发现
可用于无线和交换网络环境
主动和被动探测
主动:
netdiscover -i eth0 -r 1.1.1.0/24
netdiscover -l iplist.txt
被动:(只是侦听)
netdiscover -p
Scapy,作为python库进行调用(做协议的编程学习很重要,可以灵活编辑数据包,搭配wireshark使用可以了解网络层协议)也可以作为单独的工具使用
抓包、分析、创建、修改、注入网络流量
使用python调用编写脚本扫描
(使用scapy给变脸赋值的时候需要先给方法赋予变量)
root@root:~# scapy
WARNING: No route found for IPv6 destination :: (no default route?)
INFO: Can't import python ecdsa lib. Disabled certificate manipulation tools
Welcome to Scapy (2.3.3)
>>> ARP().display() #显示ARP包中的信息
###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= who-has
hwsrc= 00:0c:29:3e:df:60
psrc= 192.168.37.131
hwdst= 00:00:00:00:00:00
pdst= 0.0.0.0
>>> arp=ARP()
>>> arp.display()
###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= who-has
hwsrc= 00:0c:29:3e:df:60
psrc= 192.168.37.131
hwdst= 00:00:00:00:00:00
pdst= 0.0.0.0
>>> arp.pdst="192.168.37.130"
>>> arp.display()
###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= who-has
hwsrc= 00:0c:29:3e:df:60
psrc= 192.168.37.131
hwdst= 00:00:00:00:00:00
pdst= 192.168.37.130
>>> sr1(arp) #发包
Begin emission:
*Finished to send 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:0c:29:b6:06:cc psrc=192.168.37.130 hwdst=00:0c:29:3e:df:60 pdst=192.168.37.131 |<Padding load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |>>
>>> answer=sr1(arp)
Begin emission:
Finished to send 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
>>> answer.display() #接收包,其中padding为部位,当包的大小小于最小包长时,就会采用16进制0补位
###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= is-at
hwsrc= 00:0c:29:b6:06:cc
psrc= 192.168.37.130
hwdst= 00:0c:29:3e:df:60
pdst= 192.168.37.131
###[ Padding ]###
load= '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
三层采集(发送icmp包)
ping工具
ping 1.1.1.1 -c 2 linux和windos ping包很不同
ping -R 1.1.1.1 / traceroute 1.1.1.1
ping 192.168.37.128 -c 1 | grep 'bytes from'|awk '{print $4}'|awk -F':' '{print $1}'
使用脚本进行扫描
#!/bin/bash
#该脚本用户实现整个局域网内的扫描
PREFIX=192.168.37
for addr in $(seq 1 254);
do
ping -c 1 $PREFIX.$addr | grep "bytes from" |awk '{print $4}'|awk -F':' '{print $1}'
done
scapy三层发现
root@root:~# scapy
WARNING: No route found for IPv6 destination :: (no default route?)
INFO: Can't import python ecdsa lib. Disabled certificate manipulation tools
Welcome to Scapy (2.3.3)
>>> i=IP()
>>> p=ICMP()
>>> ping=(i/p)
>>> ping.display()
###[ IP ]###
version= 4
ihl= None
tos= 0x0
len= None
id= 1
flags=
frag= 0
ttl= 64