Python Scapy 报文构造和解析

Scapy是一款强大的交互式数据包处理工具、数据包生成器、网络扫描器、网络发现、攻击工具和包嗅探工具。能灵活地构造各种数据包、发送数据包、包嗅探、应答和反馈匹配等功能。

Nmap、Netdiscover、tcpdump和tshark介绍可参考:

本文主要介绍Scapy进行报文构造,报文发送和报文解析。

下载安装

官网:https://scapy.net/
github地址:https://github.com/secdev/scapy
官方文档:https://scapy.readthedocs.io/en/latest/

pip install scapy

Scapy 的使用

lsc() 命令:列出scapy通用的操作方法,常用的函数包括:

  • arpcachepoison(用于arp毒化攻击,也叫arp欺骗攻击)
  • arping(用于构造一个ARP的who-has包)
  • send:发送3层报文( 如TCP/UDP 协议),不接收数据包
  • sendp:发送2层报文(通过mac地址转发),不接收
  • sniff:用于网络嗅探,类似Wireshark和tcpdump抓包
  • sr:发送,接收3层报文,返回有回应的数据包和没有回应的数据包。
  • sr1:发送,只接收1个响应包
  • srp:发送,接收2层报文
  • srp1:发送,只接收1个响应包
  • rdpcap:读取报文
  • wrpcap:保存报文
>>> lsc()
arpcachepoison      : Poison target's cache with (your MAC,victim's IP) couple
arping              : Send ARP who-has requests to determine which hosts are up
chexdump            : Build a per byte hexadecimal representation
ls                  : List  available layers, or infos on a given layer class or name.
send                : 
sendp               : 
sendpfast           : Send packets at layer 2 using tcpreplay for performance
sniff               : 
split_layers        : Split 2 layers previously bound.
sr                  : 
sr1                 : 
sr1flood            : Flood and receive packets at layer 3 and return only the first answer
srp                 : 
srp1                : 

ls():查看支持的协议

ls(IP):查看IP包的默认参数

报文嗅探

sniff() 函数参数

Scapy使用 sniff() 函数进行报文嗅探, sniff() 方法有以下参数:

def _run(self,
            count=0, store=True, offline=None,
            quiet=False, prn=None, filter=None, lfilter=None,
            L2socket=None, timeout=
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值