本文整理汇总了Python中scapy.all.ARP属性的典型用法代码示例。如果您正苦于以下问题:Python all.ARP属性的具体用法?Python all.ARP怎么用?Python all.ARP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类scapy.all
的用法示例。
在下文中一共展示了all.ARP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def run(self):
"""Starts the thread, which is sniffing incoming ARP packets and sends out packets to spoof
all clients on the network and the gateway. This packets are sent every __SLEEP seconds.
Note:
First, a ARP request packet is generated for every possible client of the network.
This packets are directed at the gateway and update existing entries of the gateway's ARP table.
So the gateway is not flooded with entries for non-existing clients.
Second, a GARP broadcast request packet is generated to spoof every client on the network.
"""
# start sniffing thread
self.sniffthread.start()
# generates a packet for each possible client of the network
# these packets update existing entries in the arp table of the gateway
# packets = [Ether(dst=self.gate_mac) / ARP(op=1, psrc=str(x), pdst=str(x)) for x in self.ip_range]
# gratuitous arp to clients
# updates the gateway entry of the clients arp table
packets = [Ether(dst=ETHER_BROADCAST) / ARP(op=1, psrc=self.ipv4.gateway, pdst=self.ipv4.gateway, hwdst=ETHER_BROADCAST)]
while True:
sendp(packets)
time.sleep(self.__SLEEP)
示例2: scan_ips
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def scan_ips(interface='wlan0', ips='192.168.1.0/24'):
"""a simple ARP scan with Scapy"""
try:
print('[*] Start to scan')
conf.verb = 0 # hide all verbose of scapy
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
arp = ARP(pdst = ips)
answer, unanswered = srp(ether/arp, timeout = 2, iface = interface, inter = 0.1)
for sent, received in answer:
print(received.summary())
except KeyboardInterrupt:
print('[*] User requested Shutdown')
print('[*] Quitting...')
sys.exit(1)
示例3: restore
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def restore(self, index):
try:
victimIP = self._devices[index][0]
victimMAC = self._devices[index][1]
_LOGGER.info("Enabling internet for device IP: %s MAC: %s",
victimIP, victimMAC)
del self._devices[index]
send(ARP(op=2, pdst=victimIP, hwdst=victimMAC, psrc=self._router_ip,
hwsrc=self._router_mac), count=4, iface=self._interface, verbose=False)
send(ARP(op=2, pdst=self._router_ip, hwdst=self._router_mac, psrc=victimIP,
hwsrc=victimMAC), count=4, iface=self._interface, verbose=False)
except:
_LOGGER.error("Error when restoring device index: %s", index)
示例4: parsepacket
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def parsepacket(p):
if DHCP6_Solicit in p:
target = get_target(p)
if should_spoof_dhcpv6(target.host):
send_dhcp_advertise(p[DHCP6_Solicit], p, target)
if DHCP6_Request in p:
target = get_target(p)
if p[DHCP6OptServerId].duid == config.selfduid and should_spoof_dhcpv6(target.host):
send_dhcp_reply(p[DHCP6_Request], p)
print('IPv6 address %s is now assigned to %s' % (p[DHCP6OptIA_NA].ianaopts[0].addr, pcdict[p.src]))
if DHCP6_Renew in p:
target = get_target(p)
if p[DHCP6OptServerId].duid == config.selfduid and should_spoof_dhcpv6(target.host):
send_dhcp_reply(p[DHCP6_Renew],p)
print('Renew reply sent to %s' % p[DHCP6OptIA_NA].ianaopts[0].addr)
if ARP in p:
arpp = p[ARP]
if arpp.op is 2:
#Arp is-at package, update internal arp table
arptable[arpp.hwsrc] = arpp.psrc
if DNS in p:
if p.dst == config.selfmac:
send_dns_reply(p)
示例5: build_arp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def build_arp_packet(source_mac, src=None, dst=None):
""" forge arp packets used to poison and reset target connection """
arp = dpkt.arp.ARP()
packet = dpkt.ethernet.Ethernet()
if not src or not dst:
return False
arp.sha = string_to_binary(source_mac)
arp.spa = inet_aton(dst)
arp.tha = '\x00' * 6
arp.tpa = inet_aton(src)
arp.op = dpkt.arp.ARP_OP_REPLY
packet.src = string_to_binary(source_mac)
packet.dst = '\xff' * 6 # broadcast address
packet.data = arp
packet.type = dpkt.ethernet.ETH_TYPE_ARP
return packet
示例6: restore
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def restore(self, delay, target_b=None):
if not target_b:
target_b = self.gateway
src_mac = ':'.join(a+b for a, b in zip(self.src_mac[::2], self.src_mac[1::2]))
if not isinstance(self.target, list):
dst_mac = utils.get_mac_by_ip(self.target)
send(ARP(op=2, pdst=target_b, psrc=self.target,
hwdst="ff:" * 5 + "ff", hwsrc=dst_mac), count=3, verbose=False)
send(ARP(op=2, pdst=self.target, psrc=target_b,
hwdst="ff:" * 5 + "ff", hwsrc=src_mac), count=3, verbose=False)
else:
for addr in self.target:
dst_mac = utils.get_mac_by_ip(addr)
send(ARP(op=2, pdst=target_b, psrc=addr,
hwdst="ff:" * 5 + "ff", hwsrc=dst_mac), count=3, verbose=False)
send(ARP(op=2, pdst=addr, psrc=target_b,
hwdst="ff:" * 5 + "ff", hwsrc=src_mac), count=3, verbose=False)
示例7: get_kube_dns_ip_mac
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def get_kube_dns_ip_mac(self):
config = get_config()
kubedns_svc_ip = self.extract_nameserver_ip()
# getting actual pod ip of kube-dns service, by comparing the src mac of a dns response and arp scanning.
dns_info_res = srp1(
Ether() / IP(dst=kubedns_svc_ip) / UDP(dport=53) / DNS(rd=1, qd=DNSQR()),
verbose=0,
timeout=config.network_timeout,
)
kubedns_pod_mac = dns_info_res.src
self_ip = dns_info_res[IP].dst
arp_responses, _ = srp(
Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst=f"{self_ip}/24"), timeout=config.network_timeout, verbose=0,
)
for _, response in arp_responses:
if response[Ether].src == kubedns_pod_mac:
return response[ARP].psrc, response.src
示例8: poison
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def poison():
v = scapy.ARP(pdst=target, psrc=gateway)
while True:
try:
scapy.send(v,verbose=0,inter=1,loop=1)
except KeyboardInterupt:
print(bcolours.OKBLUE + ' [Warning] Stopping...' + bcolours.ENDC)
sys.exit(3)
示例9: gw_poison
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def gw_poison():
gw = scapy.ARP(pdst=gateway, psrc=target)
while True:
try:
scapy.send(gw,verbose=0,inter=1,loop=1)
except KeyboardInterrupt:
print(bcolours.OKBLUE + ' [Warning] Stopping...' + bcolours.ENDC)
sys.exit(3)
示例10: raw_packet_send_arp_requests
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def raw_packet_send_arp_requests(number_of_packets):
for _ in range(number_of_packets):
arp_request = arp.make_request(ethernet_src_mac=ethernet_src,
ethernet_dst_mac="ff:ff:ff:ff:ff:ff",
sender_mac=ethernet_src,
sender_ip=ip_src,
target_mac="00:00:00:00:00:00",
target_ip=ip_dst)
global_socket.send(arp_request)
# endregion
# region Send ARP packets in scapy
示例11: scapy_send_arp_requests
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def scapy_send_arp_requests(number_of_packets):
arp_request = Ether(src=ethernet_src, dst='ff:ff:ff:ff:ff:ff') /\
ARP(op=1, hwsrc=ethernet_src, hwdst='00:00:00:00:00:00', psrc=ip_src, pdst=ip_dst)
sendp(arp_request, count=number_of_packets, verbose=False)
# endregion
# region Send DHCP Discover packets in raw-packet
示例12: _process_arp
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def _process_arp(self, pkt):
"""
Updates ARP cache upon receiving ARP packets, only if the packet is not
spoofed.
"""
try:
if pkt.op == 2 and pkt.hwsrc != self._host_state.host_mac:
self._host_state.set_ip_mac_mapping(pkt.psrc, pkt.hwsrc)
except AttributeError:
return
示例13: start
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def start(self):
with self._lock:
self._active = True
utils.log('[ARP Scanning] Starting.')
self._thread.start()
示例14: _arp_scan_thread_helper
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def _arp_scan_thread_helper(self):
fast_scan_start_ts = None
while True:
if not self._host_state.is_inspecting():
time.sleep(1)
continue
for ip in utils.get_network_ip_range():
sleep_time = SLOW_SCAN_SLEEP_TIME
# Whether we should scan fast or slow
with self._host_state.lock:
fast_arp_scan = self._host_state.fast_arp_scan
# If fast scan, we do it for at most 5 mins
if fast_arp_scan:
sleep_time = FAST_SCAN_SLEEP_TIME
if fast_scan_start_ts is None:
fast_scan_start_ts = time.time()
else:
if time.time() - fast_scan_start_ts > 300:
fast_scan_start_ts = None
sleep_time = SLOW_SCAN_SLEEP_TIME
with self._host_state.lock:
self._host_state.fast_arp_scan = False
time.sleep(sleep_time)
arp_pkt = sc.Ether(dst="ff:ff:ff:ff:ff:ff") / \
sc.ARP(pdst=ip, hwdst="ff:ff:ff:ff:ff:ff")
sc.sendp(arp_pkt, verbose=0)
with self._lock:
if not self._active:
return
示例15: stop
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import ARP [as 别名]
def stop(self):
with self._lock:
self._active = False
self._thread.join()
utils.log('[ARP Scanning] Stopped.')