Scapy是一款强大的交互式数据包处理工具、数据包生成器、网络扫描器、网络发现、攻击工具和包嗅探工具。能灵活地构造各种数据包、发送数据包、包嗅探、应答和反馈匹配等功能。
Nmap、Netdiscover、tcpdump和tshark介绍可参考:
- Nmap:Nmap扫描工具介绍
- tcpdump和tshark:tcpdump抓包及tshark解包方法介绍
- Netdiscover:Netdiscover网络扫描工具
本文主要介绍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=