当前位置: 首页>>代码示例>>Python>>正文


Python inet.Ether方法代码示例

本文整理汇总了Python中scapy.layers.inet.Ether方法的典型用法代码示例。如果您正苦于以下问题:Python inet.Ether方法的具体用法?Python inet.Ether怎么用?Python inet.Ether使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scapy.layers.inet的用法示例。


在下文中一共展示了inet.Ether方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_tcp_packet

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def generate_tcp_packet(ip_src: str = "192.168.64.32", ip_dst: str = "192.168.64.48",
                        mac_src: str = "56:6D:D9:BC:70:1C", ttl: int = 64,
                        mac_dst: str = "F4:2B:95:B3:0E:1A", port_src: int = 1337, port_dst: int = 6442,
                        tcpflags: str = "S", payload: str = ""):
    """
    Builds a TCP packet with the values specified by the caller.

    :param ip_src: the source IP address of the IP header
    :param ip_dst the destination IP address of the IP header
    :param mac_src: the source MAC address of the MAC header
    :param ttl: the ttl value of the packet
    :param mac_dst: the destination MAC address of the MAC header
    :param port_src: the source port of the TCP header
    :param port_dst: the destination port of the TCP header
    :param tcpflags: the TCP flags of the TCP header
    :param payload: the payload of the packet
    :return: the corresponding TCP packet
    """

    ether = Ether(src=mac_src, dst=mac_dst)
    ip = IP(src=ip_src, dst=ip_dst, ttl=ttl)
    tcp = TCP(sport=port_src, dport=port_dst, flags=tcpflags)
    packet = ether / ip / tcp / Raw(load=payload)
    return packet 
开发者ID:tklab-tud,项目名称:ID2T,代码行数:26,代码来源:Generator.py

示例2: get_mblk_info

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def get_mblk_info(self, mblk_addr):
        print("{:-^{width}}".format("mblk info at %s" % hex(mblk_addr), width=80))
        mblk_data = self.get_mem_dump(mblk_addr, 0x38)  # 0x38 is length
        mblk = mBlk(mblk_data)
        mblk.show()

        print("##clblk at %s" % hex(mblk.pClBlkAddr))
        clblk_hdr_data = self.get_mem_dump(mblk.pClBlkAddr, 0x20)  # 0x38 is length
        clBlk_hdr = clBlk(clblk_hdr_data)
        clBlk_hdr.show()

        mData = self.get_mem_dump(mblk['mBlkHdr'].mData, mblk['mBlkHdr'].mLen)
        print("## mData at: %s with length: %s" % (hex(mblk['mBlkHdr'].mData), hex(mblk['mBlkHdr'].mLen)))
        if mData[:2] == "\x45\x00":
            mPacket = IP(mData)
        elif mData[:2] == "\x41\x41":
            mPacket = Raw(mData)
        else:
            mPacket = Ether(mData)
        mPacket.show() 
开发者ID:PAGalaxyLab,项目名称:vxhunter,代码行数:22,代码来源:vx5_mips_debugger.py

示例3: packets_to_convs

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def packets_to_convs(exploit_raw_packets):
        """
           Classifies a bunch of packets to conversations groups. A conversation is a set of packets go between host A
           (IP,port) to host B (IP,port)

           :param exploit_raw_packets: A set of packets contains several conversations.
           :return conversations: A set of arrays, each array contains the packet of specific conversation
           :return orderList_conversations: An array contains the conversations ids (IP_A,port_A, IP_b,port_B) in the
           order they appeared in the original packets.
           """
        conversations = {}
        order_list_conversations = []
        for pkt_num, pkt in enumerate(exploit_raw_packets):
            eth_frame = inet.Ether(pkt[0])

            ip_pkt = eth_frame.payload
            ip_dst = ip_pkt.getfieldval("dst")
            ip_src = ip_pkt.getfieldval("src")

            tcp_pkt = ip_pkt.payload
            port_dst = tcp_pkt.getfieldval("dport")
            port_src = tcp_pkt.getfieldval("sport")

            conv_req = (ip_src, port_src, ip_dst, port_dst)
            conv_rep = (ip_dst, port_dst, ip_src, port_src)
            if conv_req not in conversations and conv_rep not in conversations:
                pkt_list = [pkt]
                conversations[conv_req] = pkt_list
                # Order list of conv
                order_list_conversations.append(conv_req)
            else:
                if conv_req in conversations:
                    pkt_list = conversations[conv_req]
                    pkt_list.append(pkt)
                    conversations[conv_req] = pkt_list
                else:
                    pkt_list = conversations[conv_rep]
                    pkt_list.append(pkt)
                    conversations[conv_rep] = pkt_list
        return conversations, order_list_conversations 
开发者ID:tklab-tud,项目名称:ID2T,代码行数:42,代码来源:BaseAttack.py

示例4: generate_attack_packets

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def generate_attack_packets(self) -> None:
        ip_attacker = self.get_param_value(self.IP_SOURCE)
        mac_attacker = self.get_param_value(self.MAC_SOURCE)
        ip_amplifier = self.get_param_value(self.IP_DESTINATION)
        mac_amplifier = self.get_param_value(self.MAC_DESTINATION)
        ip_victim = self.get_param_value(self.IP_VICTIM)

        timestamp_next_pkt = self.get_param_value(self.INJECT_AT_TIMESTAMP)
        self.attack_start_utime = timestamp_next_pkt

        attack_duration = self.get_param_value(self.ATTACK_DURATION)
        attack_ends_time = timestamp_next_pkt + attack_duration

        _, src_ttl, _ = self.get_ip_data(ip_attacker)
        sport = Util.generate_source_port_from_platform('linux')

        # Use MAC of the actual source, but the IP of the victim
        attacker_ether = inet.Ether(src=mac_attacker, dst=mac_amplifier)
        attacker_ip = inet.IP(src=ip_victim, dst=ip_amplifier, ttl=src_ttl, flags='DF')

        while timestamp_next_pkt <= attack_ends_time:
            request_udp = inet.UDP(sport=sport, dport=Memcd.memcached_port)
            request_memcd = Memcd.Memcached_Request(Request=b'stats\r\n', RequestID=inet.RandShort())
            request = (attacker_ether / attacker_ip / request_udp / request_memcd)
            request.time = timestamp_next_pkt

            self.add_packet(request, ip_victim, ip_amplifier)

            timestamp_next_pkt = self.timestamp_controller.next_timestamp() 
开发者ID:tklab-tud,项目名称:ID2T,代码行数:31,代码来源:MemcrashedSpooferAttack.py

示例5: generate_udp_packet

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def generate_udp_packet(ip_src: str = "192.168.64.32", ip_dst: str = "192.168.64.48",
                        mac_src: str = "56:6D:D9:BC:70:1C", ttl: int = 64,
                        mac_dst: str = "F4:2B:95:B3:0E:1A", port_src: int = 1337, port_dst: int = 6442,
                        payload: str = ""):
    """
    Builds an UDP packet with the values specified by the caller.

    :param ip_src: the source IP address of the IP header
    :param ip_dst the destination IP address of the IP header
    :param mac_src: the source MAC address of the MAC header
    :param ttl: the ttl value of the packet
    :param mac_dst: the destination MAC address of the MAC header
    :param port_src: the source port of the UDP header
    :param port_dst: the destination port of the UDP header
    :param payload: the payload of the packet
    :return: the corresponding UDP packet
    """

    ether = Ether(src=mac_src, dst=mac_dst)
    ip = IP(src=ip_src, dst=ip_dst, ttl=ttl)
    udp = UDP(sport=port_src, dport=port_dst)
    packet = ether / ip / udp / Raw(load=payload)
    return packet


#################################################
########     IP address generation       ########
################################################# 
开发者ID:tklab-tud,项目名称:ID2T,代码行数:30,代码来源:Generator.py

示例6: discover_local_device

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def discover_local_device(self):
        self.sniff_mac_address = get_if_hwaddr(self.nic)
        p = threading.Thread(target=self.sniff_answer)
        p.setDaemon(True)
        p.start()
        # wait sniff start
        time.sleep(0.2)
        packet = Ether(src=self.sniff_mac_address, dst="ff:ff:ff:ff:ff:ff")/IP(src=get_if_addr(self.nic), dst="255.255.255.255")/UDP(sport=44818, dport=44818)/ENIPHeader(Command=0x0063)
        sendp(packet, iface=self.nic)
        self.sniff_finished.wait(self.timeout + 1) 
开发者ID:dark-lbp,项目名称:isf,代码行数:12,代码来源:enip_scan.py

示例7: add_msdu

# 需要导入模块: from scapy.layers import inet [as 别名]
# 或者: from scapy.layers.inet import Ether [as 别名]
def add_msdu(self, msdu):
        msdu_len = len(msdu)
        total_len = msdu_len + 6 + 6 + 2
        padding = "\x00" * (4 - (total_len % 4))  # Align to 4 octets

        if self.num_subframes > 0:
            self.data /= padding

        self.data = self.data / Ether(src=self.src_mac, dst=self.recv_mac, type=msdu_len) / msdu

        self.num_subframes += 1 
开发者ID:rpp0,项目名称:aggr-inject,代码行数:13,代码来源:packets.py


注:本文中的scapy.layers.inet.Ether方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。