Mit dem Python-Paket Parsing/Sniffing-Tool Scapy möchte ich ein Paket aus einem rohen Byte-String erstellen. Während die Details meines spezifischen Anwendungsfall mehr realistisch sind, zeigt das folgende Beispiel mein Problem und meinen gegenwärtigen Versuch:Wie man ein Scapy-Paket aus rohen Bytes erstellt
# Get an example packet (we won't really have an offline file in production.)
pkt = sniff(offline="./example_packets/example_packets2.pcap")
# Convert it to raw bytes -- oddly __str__ does this.
raw_packet = str(pkt)
# Current, broken, attempt to construct a new packet from the same bytes as the old.
# In truth, there are easier ways to copy packets from existing Scapy packets, but
# we are really just using that offline packet as a convenient example.
new_packet = Packet(_pkt=raw_packet)
# Sadly, while this packet has the bytes internally, it no longer has the
# interpretations of the layers like the original packet did (such as saying that
# the packet is ARP and has these field values, etc.
print repr(new_packet)
Wie kann ich ein new_packet
aus rohem Bytes erzeugen, die gleich aussehen, als ob sie schnupperte wurde aus einer pcap-Datei?
Wenn die Klasse "Ether" verwendet wird, kann Scapy die anderen Ebenen automatisch bestimmen? Es scheint, dass die "Sniff" -Funktion die anderen Schichten irgendwie herausfindet. – BlackVegetable
Wenn Sie mit anderen Layern die Schichten über der Ethernet-Ebene meinen, lautet die Antwort "Ja", dank des Feldes "Typ". – Pierre
Natürlich! Das hätte mir klar sein müssen. Danke für die Klarstellung. (Wie sonst könnten Router die anderen Schichten interpretieren, wenn nicht für Typinformationen?) – BlackVegetable