Python协议攻击脚本(一): Scapy的使用

本文介绍了Python库Scapy的基本使用,包括安装步骤和在Linux、Mac、Windows平台上的注意事项。Scapy可用于发送、嗅探和伪造网络数据包,支持多种网络任务,如探测、扫描和攻击。文章还展示了如何在交互式模式下使用Scapy,以及如何构造和发送数据包。
摘要由CSDN通过智能技术生成

Python协议攻击脚本(一): Scapy基本的使用

简介

Scapy官网

Scapy是一个Python程序,使用户能够发送,嗅探和剖析并伪造网络数据包。此功能允许构建可以探测,扫描或攻击网络的工具。Scapy可以轻松处理大多数经典任务,如扫描,跟踪路由,探测,单元测试,攻击或网络发现。它可以取代hping,arpspoof,arp-sk,arping,p0f甚至是Nmap,tcpdump和tshark的某些部分。

安装

详见Scapy官方文档

捆绑 包含 Pip命令
默认 只有Scapy pip install scapy
基本 Scapy和IPython。强烈推荐 pip install --pre scapy[basic]
完成 Scapy及其所有主要依赖项 pip install --pre scapy[complete]

Linux

  • 安装Python 2.7或3.4+
  • 安装tcpdump并确保它在$ PATH中。(它仅用于编译BPF过滤器())-ddd option
  • 确保你的内核选择了Packet套接字(CONFIG_PACKET
  • 如果您的内核<2.6,请确保选择了Socket过滤CONFIG_FILTER

Debian / Ubuntu /

python3

sudo apt-get install python3 python3-pip tcpdump
pip3 install --pre scapy[basic]

python

sudo apt-get install python python-pip tcpdump
pip install --pre scapy[basic]

kali

默认已安装,但是安装在Python2.7下

如果需要在Python3中使用:

apt-get install python3 python3-pip
pip3 install scapy

Mac

使用Homebrew安装

  1. 更新Homebrew:

    brew update
    
  2. 安装Python绑定:

    brew install --with-python libdnet
    brew install https://raw.githubusercontent.com/secdev/scapy/master/.travis/pylibpcap.rb
    sudo brew install --with-python libdnet
    sudo brew install https://raw.githubusercontent.com/secdev/scapy/master/.travis/pylibpcap.rb
    

使用MacPorts安装

  1. 更新MacPorts:

    $ sudo port -d selfupdate
    
  2. 安装Python绑定:

    $ sudo port install py-libdnet py-pylibpcap
    

Windows

Scapy主要是针对类Unix系统开发的,在这些平台上运行得最好。但最新版本的Scapy支持Windows开箱即用。因此,您也可以在Windows机器上使用几乎所有Scapy的功能。

  • PythonPython 2.7.X或3.4+。安装后,将Python安装目录及其Scripts子目录添加到PATH。根据您的Python版本,默认值分别为C:\Python27C:\Python27\Scripts
  • Npcap:建议使用默认值。Scapy也可以使用Winpcap
  1. 安装Npcap
    Npcap下载
    mark

  2. 安装Scapy

Dos中输入:

pip install --pre scapy[basic]	#需要配置Python的环境变量,如上

基本使用

交互式

主要用来做测试,或者进行简单操作

Linux从终端启动

mark

Windows cmd中启动

mark

列出用户命令lsc()

>>> lsc()
sr               : Send and receive packets at layer 3 
sr1              : Send packets at layer 3 and return only the first answer 
srp              : Send and receive packets at layer 2
srp1             : Send and receive packets at layer 2 and return only the first answer
srloop           : Send a packet at layer 3 in loop and print the answer each time
srploop          : Send a packet at layer 2 in loop and print the answer each time
sniff            : Sniff packets
p0f              : Passive OS fingerprinting: which OS emitted this TCP SYN ?
arpcachepoison   : Poison target's cache with (your MAC,victim's IP) couple
send             : Send packets at layer 3
sendp            : Send packets at layer 2
traceroute       : Instant TCP traceroute
arping           : Send ARP who-has requests to determine which hosts are up
ls               : List  available layers, or infos on a given layer
lsc              : List user commands
queso            : Queso OS fingerprinting
nmap_fp          : nmap fingerprinting
report_ports     : portscan a target and output a LaTeX table
dyndns_add       : Send a DNS add message to a nameserver for "name" to have a new "rdata"
dyndns_del       : Send a DNS delete message to a nameserver for "name"
[...]

常用的方法

sr               : 发送和接受
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值