linux Scapy 进行arp数据包详细过程

发布时间:2020-08-05 19:42:06 作者:wangbaoping1
来源:网络 阅读:4696

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)数据结构:

推荐阅读:
  1. linux 高性能读书笔记之小工具tcpdump
  2. kali linux内网嗅探

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

scapy kali linu

上一篇:ftp实现通过数据库的虚拟用户认证

下一篇:js调用HttpPrinter(web打印插件)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》