7
파이썬 패킷 구문 분석/스니핑 도구 Scapy를 사용하여 원시 바이트 문자열에서 패킷을 만들고 싶습니다. 이 맡아 봤다고 것처럼 나는 같은 모양 원시 바이트에서 new_packet
을 생산할 수있는 방법원시 바이트에서 Scapy 패킷을 만드는 방법
# 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)
: 내 특정 사용 케이스의 세부 사항이 더 현실적인 있지만, 다음과 같은 예를 들어 내 문제와 내 현재의 시도를 보여 pcap 파일에서?
'Ether'클래스를 사용하는 경우 Scapy가 다른 레이어를 자동으로 결정할 수 있습니까? 'sniff' 함수가 어떻게 든 다른 레이어를 파악하는 것 같습니다. – BlackVegetable
다른 레이어에서 이더넷 레이어의 레이어를 의미하는 경우 'type' 필드 덕분에 대답은'예 '입니다. – Pierre
물론! 그게 내게 분명 했어야 했어. 해명 해줘서 고마워. (라우터가 타입 정보가 아닌 다른 레이어를 해석하는 방법을 알고 싶다면?) – BlackVegetable