Python scapy.all.Packet() Examples

The following are 6 code examples of scapy.all.Packet(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scapy.all , or try the search function .
Example #1
Source File: test_pcap.py    From beagle with MIT License 8 votes vote down vote up
def test_multiple_packets():
    packets = [
        # HTTP Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=12345, dport=80)
        / HTTP()
        / HTTPRequest(Method="GET", Path="/foo", Host="https://google.com"),
        # DNS Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / UDP(sport=80, dport=53)
        / DNS(rd=1, qd=DNSQR(qtype="A", qname="google.com"), an=DNSRR(rdata="123.0.0.1")),
        # TCP Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=80, dport=5355),
    ]

    events = list(packets_to_datasource_events(packets).events())
    assert len(events) == 3

    assert [e["event_type"] for e in events] == ["HTTPRequest", "DNS", "TCP"] 
Example #2
Source File: test_networkx.py    From beagle with MIT License 6 votes vote down vote up
def test_from_datasources():
    packets_1 = [
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=12345, dport=80)
        / HTTP()
        / HTTPRequest(Method="GET", Path="/foo", Host="https://google.com")
    ]

    packets_2 = [
        # HTTP Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=12345, dport=80)
        / HTTP()
        / HTTPRequest(Method="GET", Path="/foo", Host="https://google.com"),
        # DNS Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / UDP(sport=80, dport=53)
        / DNS(rd=1, qd=DNSQR(qtype="A", qname="google.com"), an=DNSRR(rdata="123.0.0.1")),
        # TCP Packet
        Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
        / IP(src="127.0.0.1", dst="192.168.1.1")
        / TCP(sport=80, dport=5355),
    ]

    nx = NetworkX.from_datasources(
        [packets_to_datasource_events(packets) for packets in [packets_1, packets_2]]
    )

    # Make the graph
    nx.graph()

    assert not nx.is_empty() 
Example #3
Source File: cip.py    From scapy-cip-enip with MIT License 6 votes vote down vote up
def __repr__(self):
        if self.reserved != 0:
            return scapy_all.Packet.__repr__(self)

        # Known status
        if self.status in self.ERROR_CODES and self.additional_size == 0:
            return "<CIP_ResponseStatus  status={}>".format(self.ERROR_CODES[self.status])

        # Simple status
        if self.additional_size == 0:
            return "<CIP_ResponseStatus  status=%#x>" % self.status

        # Forward Open failure
        if self.status == 1 and self.additional == b"\x00\x01":
            return "<CIP_ResponseStatus  status=Connection failure>"
        return scapy_all.Packet.__repr__(self) 
Example #4
Source File: test_pcap.py    From beagle with MIT License 5 votes vote down vote up
def packets_to_datasource_events(packets: List[Packet]) -> PCAP:
    f = BytesIO()
    PcapWriter(f).write(packets)
    f.seek(0)
    return PCAP(f)  # type: ignore 
Example #5
Source File: test_networkx.py    From beagle with MIT License 5 votes vote down vote up
def packets_to_datasource_events(packets: List[Packet]) -> PCAP:
    f = BytesIO()
    PcapWriter(f).write(packets)
    f.seek(0)
    return PCAP(f)  # type: ignore 
Example #6
Source File: vulnerability_tester.py    From cotopaxi with GNU General Public License v2.0 5 votes vote down vote up
def verify(self, test_params):
        """Verify whether remote host is vulnerable to this vulnerability."""
        test_result = sr1_file(test_params, VULN_DB_PATH + self.payload_file)
        print ("[*] Payload for {} sent".format(self.name))
        if test_result is not None:
            if test_result is Packet:
                show_verbose(test_params, test_result)
        print (
            "[+] Vulnerability {} is memory leak - verify manually result of "
            "this test.".format(self.name)
        )
        self.report_potential_result(test_params)