Python协议攻击脚本(一): Scapy基本的使用
简介
Scapy是一个Python程序,使用户能够发送,嗅探和剖析并伪造网络数据包。此功能允许构建可以探测,扫描或攻击网络的工具。Scapy可以轻松处理大多数经典任务,如扫描,跟踪路由,探测,单元测试,攻击或网络发现。它可以取代hping,arpspoof,arp-sk,arping,p0f甚至是Nmap,tcpdump和tshark的某些部分。
安装
捆绑 | 包含 | 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安装
-
更新Homebrew:
brew update
-
安装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安装
-
更新MacPorts:
$ sudo port -d selfupdate
-
安装Python绑定:
$ sudo port install py-libdnet py-pylibpcap
Windows
Scapy主要是针对类Unix系统开发的,在这些平台上运行得最好。但最新版本的Scapy支持Windows开箱即用。因此,您也可以在Windows机器上使用几乎所有Scapy的功能。
- Python:Python 2.7.X或3.4+。安装后,将Python安装目录及其Scripts子目录添加到PATH。根据您的Python版本,默认值分别为
C:\Python27
和C:\Python27\Scripts
。 - Npcap:建议使用默认值。Scapy也可以使用Winpcap
-
安装Npcap
Npcap下载
-
安装Scapy
Dos中输入:
pip install --pre scapy[basic] #需要配置Python的环境变量,如上
基本使用
交互式
主要用来做测试,或者进行简单操作
Linux从终端启动
Windows cmd中启动
列出用户命令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 : 发送和接受