コード例 #1
0
def create_packet_ipcp_config(dst,
                              src,
                              sessionid,
                              code,
                              id=0x01,
                              ip=b'\x00\x00\x00\x00'):
    """
    Create IPCP Configuration Request packet
    :param dst: Destination MAC
    :param src: Source MAC
    :param sessionid: PPPoE session id
    :param code: LCP code
    :param id: Message id
    :param ip: 0.0.0.0 ip address
    :return: packet
    """

    options = []

    options.append(PPP_IPCP_Option(type=0x03, data=ip))

    packet = Ether(dst=dst, src=src, type=0x8864) / \
        PPPoE(version=1, type=1, sessionid=sessionid) / \
        PPP(proto=0x8021) / \
        PPP_IPCP(code=code, id=id, options=options)

    return packet
コード例 #2
0
def create_packet_lcp_config(dst,
                             src,
                             sessionid,
                             code,
                             magic,
                             id=0x01,
                             mru=1492):
    """
    Create lcp packet
    :param dst: Destination MAC
    :param src: Source MAC
    :param sessionid: PPPoE session id
    :param code: LCP code
    :param id: Message id
    :param mru: MRU value
    :param magic: Magic value
    :return: packet
    """

    options = []

    options.append(
        PPP_LCP_Option(type=0x01, data=mru.to_bytes(2, byteorder='big')))
    options.append(
        PPP_LCP_Option(type=0x05, data=magic.to_bytes(4, byteorder='big')))

    packet = Ether(dst=dst, src=src, type=0x8864) / \
        PPPoE(version=1, type=1, sessionid=sessionid) / \
        PPP(proto=0xc021) / \
        PPP_LCP(code=code, id=id, options=options)

    return packet
コード例 #3
0
ファイル: processor.py プロジェクト: pkositsyn/network
 def process_packet(self, pack: PPP):
     if not pack.haslayer(TCP):
         return
     four_tuple = (pack[IP].src, str(pack[TCP].sport), pack[IP].dst,
                   str(pack[TCP].dport))
     if four_tuple in self.connections:
         connection = self.connections[four_tuple]
     else:
         if not pack[TCP].flags.S:
             return
         connection = self.connections[four_tuple] = ConnectionProcessor(
             pack, self.bandwidth)
     connection.process(pack)
コード例 #4
0
ファイル: test_pppoe.py プロジェクト: gavinxiao888/vpp
    def create_stream_pppoe_lcp(self, src_if, dst_if,
                                client_mac, session_id, count=1):
        packets = []
        for i in range(count):
            # create packet info stored in the test case instance
            info = self.create_packet_info(src_if, dst_if)
            # convert the info into packet payload
            payload = self.info_to_payload(info)
            # create the packet itself
            p = (Ether(dst=src_if.local_mac, src=client_mac) /
                 PPPoE(sessionid=session_id) /
                 PPP(proto=0xc021) /
                 Raw(payload))
            # store a copy of the packet in the packet info
            info.data = p.copy()
            # append the packet to the list
            packets.append(p)

        # return the created packet list
        return packets
コード例 #5
0
def create_packet_lcp_config_pkt(dst, src, sessionid, source, code):
    """
    Take source packet
    Get last fields
    Form new packet
    Then copy last fields
    :param dst: Destination MAC
    :param src: Source MAC
    :param sessionid: PPPoE session id
    :param source: source packet
    :param code: LCP code
    :return: packet
    """

    packet = Ether(dst=dst, src=src, type=0x8864) / \
        PPPoE(version=1, type=1, sessionid=sessionid) / \
        PPP(proto=0xc021) / \
        source[PPP_LCP]
    packet[PPP_LCP].code = code
    return packet
コード例 #6
0
def pkt_add_pppoe(pkt, type, code, session_id):
    return Ether(src=pkt[Ether].src, dst=pkt[Ether].dst) / \
           PPPoE(version=1, type=type, code=code, sessionid=session_id) / \
           PPP(proto=0x0021) / pkt[Ether].payload
コード例 #7
0
    packetizer = Packetizer()
    packetizer.from_file(sys.argv[1])
    packetizer.escape_packets()

    with open(sys.argv[2] + ".original_packets", "w+") as orig_fh:
        with open(sys.argv[2] + ".timestamps", "w+") as index_fh:
            with open(sys.argv[2] + ".packets", "w+") as fh:
                for idx, orig_packet in enumerate(packetizer.packets):
                    if idx < len(packetizer.escaped_packets):
                        packet = packetizer.escaped_packets[idx]
                        print(
                            f"\n= WRITE PACKET {idx} ===================================="
                        )
                        trimmed_packet = packet[1:-3]
                        scapy_summary = PPP(trimmed_packet).summary()
                        print(scapy_summary)
                        if packet_search_string and packet_search_string in scapy_summary:
                            with open(sys.argv[2] + ".match",
                                      "w+") as match_fh:
                                match_fh.write(scapy_summary)
                        hexdump(trimmed_packet)
                        if packet[0] != 0x7E or packet[-1] != 0x7E:
                            print(f"[WARN] Improperly formatted PPP packet")
                            # continue
                        fh.write('\n')
                        fh.write(hexdump(trimmed_packet, dump=True))
                        fh.write('\n')
                    index_fh.write(
                        str(packetizer.packet_start_indices[idx]) + '\n')
                    orig_fh.write('\n')