1. 程式人生 > >linux Scapy 進行arp數據包詳細過程

linux Scapy 進行arp數據包詳細過程

Scapy kali-linu

root@hak:~# 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 (unknown.version)

>> a=Ether()/ARP()
>> a.show()
###[ Ethernet ]###
dst= 00:50:56:ef:49:1f
src= 00:0c:29:e2:bb:15
type= 0x806

###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= who-has
hwsrc= 00:0c:29:e2:bb:15
psrc= 192.168.80.250
hwdst= 00:00:00:00:00:00
pdst= 0.0.0.0

>>arp1=srp(Ether(src=‘00:0c:29:e2:bb:15‘,dst=‘FF:FF:FF:FF:FF:FF‘)/ARP(op=1,hwsrc=‘00:0c:29:e2:bb:15‘,hwdst=‘00:00:00:00:00:00‘,psrc=‘192.168.80.250‘,pdst=‘192.168.80.251‘,))
Begin emission:
*Finished to send 1 packets.

Received 1 packets, got 1 answers, remaining 0 packets
1)>>> print(arp1)
(<Results: TCP:0 UDP:0 ICMP:0 Other:1>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>)
產生收到響應與沒收到響應元組;
2)查看arp1的數據類型:

>> print(type(arp1))
<type ‘tuple‘> 為元組
3)用元組的方法只打印接收報文:
>> print(arp1[0])
<Results: TCP:0 UDP:0 ICMP:0 Other:1>

4)顯示arp1[0]數據類型:
>> print(type(arp1[0]))
<class ‘scapy.plist.SndRcvList‘>
5)查看該‘scapy.plist.SndRcvList數據類型處理方法(上網查看https://fossies.org/dox/scapy-2.3.3/)用res的方法
6)產生響應數據包中的發送與接收的包,並把包res方法列出來
>> print(arp1[0].res)*第一對發送包與收發包
[(<Ether dst=FF:FF:FF:FF:FF:FF src=00:0c:29:e2:bb:15 type=0x806 |<ARP op=who-has hwsrc=00:0c:29:e2:bb:15 psrc=192.168.80.250 hwdst=00:00:00:00:00:00 pdst=192.168.80.251 |>>, <Ether dst=00:0c:29:e2:bb:15 src=00:0c:29:21:fd:03 type=0x806 |<ARP hwtype=0x1 ptype=0x800 hwlen=6 plen=4 op=is-at hwsrc=00:0c:29:21:fd:03 psrc=192.168.80.251 hwdst=00:0c:29:e2:bb:15 pdst=192.168.80.250 |<Padding load=‘\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00‘ |>>>)]
7)提出收包數據
>> print(arp1[0].res[0][1])
8)查看arp1[0].res[0][1]數據類型:
>> print(type(arp1[0].res[0][1]))
<class ‘scapy.layers.l2.Ether‘>
9)查看該scapy.layers.l2.Ether數據類型處理方法(上網查看https://fossies.org/dox/scapy-2.3.3/)用
Static Public Attributes
string name = "Ethernet"

list fields_desc

的方法
10)用fields方法(產生相應得字典)提取收包數據:
print(arp1[0].res[0][1].fields)
{‘src‘: ‘00:0c:29:21:fd:03‘, ‘dst‘: ‘00:0c:29:e2:bb:15‘, ‘type‘: 2054}
11)用show方法讀取收包數據:
print(arp1[0].res[0][1].show())
###[ Ethernet ]###
dst= 00:0c:29:e2:bb:15
src= 00:0c:29:21:fd:03
type= 0x806
###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= is-at
hwsrc= 00:0c:29:21:fd:03
psrc= 192.168.80.251
hwdst= 00:0c:29:e2:bb:15
pdst= 192.168.80.250
###[ Padding ]###
load= ‘\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00‘
12)用show方法讀取收包數據中ARP:

>> print(arp1[0].res[0][1][1].show())
###[ ARP ]###
hwtype= 0x1
ptype= 0x800
hwlen= 6
plen= 4
op= is-at
hwsrc= 00:0c:29:21:fd:03
psrc= 192.168.80.251
hwdst= 00:0c:29:e2:bb:15
pdst= 192.168.80.250
###[ Padding ]###
load= ‘\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00‘
13)產生自己想要的print結果:
>> print(‘ip:‘ + arp1[0].res[0][1][1].fields[‘psrc‘]+ ‘ mac:‘ + arp1[0].res[0][1][1].fields[‘hwsrc‘])
ip:192.168.80.251 mac:00:0c:29:21:fd:03
14)數據結構:

linux Scapy 進行arp數據包詳細過程