Ahmed Shihab
Ahmed Shihab

Reputation: 31

How to remove a layer from a packet in python using scapy

How can i remove a layer from a packet in scapy lets say we have a packet that consist of the following layers IPv6/IPv6ExtHdrRouting/ICMPv6EchoRequest i would like to remove the IPv6ExtHdrRouting layer so we are left with IPv6/ICMPv6EchoRequest

Upvotes: 1

Views: 8132

Answers (2)

raj trans
raj trans

Reputation: 26

I developed a tool that allows making changes to pcap layers. You can use it to remove any layer by simply providing its offsets.

e.g. To remove the Ethernet layer,

python3 modify_layers.py -i test.pcap -l "(0,14)"

Tool: https://github.com/x00itachi/modify-pcap-pkt-layers

Upvotes: 0

Kashif Ahmad
Kashif Ahmad

Reputation: 486

As far as I know, scapy does not have a particular method for stripping layers but scapy's method remove_payload() can come handy in situations like this. What you can do is.

pkt=IPv6/IPv6ExtHdrRouting/ICMPv6EchoRequest
pkt2=pkt[ICMPv6EchoRequest]
pkt[IPv6].remove_payload()
pkt /=pkt2

Which will leave you with your desired output.

Upvotes: 2

Related Questions