icmp6 echo reply
This commit is contained in:
parent
45e2bd4237
commit
c9f8831865
1 changed files with 26 additions and 4 deletions
|
@ -11,6 +11,7 @@ from scapy.all import IP, Raw, IPv6, TCP, TCP_client, Ether
|
|||
from scapy.all import sniff
|
||||
from scapy.all import Packet, BitField, IntEnumField, ShortField, XShortEnumField, ShortEnumField
|
||||
from scapy.all import ICMPv6ND_NS, ICMPv6ND_RS, ICMPv6NDOptSrcLLAddr, ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr
|
||||
from scapy.all import ICMPv6EchoRequest, ICMPv6EchoReply
|
||||
from scapy.data import ETHER_TYPES
|
||||
|
||||
import sys
|
||||
|
@ -230,6 +231,29 @@ class L2Controller(object):
|
|||
# tcp.ack,
|
||||
# raw)
|
||||
|
||||
def handle_icmp6_echo_request(self, pkg):
|
||||
"""
|
||||
Sample from the wire:
|
||||
|
||||
DEBUG:main:reassambled=<Ether dst=00:00:0a:00:00:42 src=00:00:0a:00:00:01 type=0x86dd |<IPv6 version=6 tc=0 fl=474570 plen=64 nh=ICMPv6 hlim=64 src=2001:db8::1 dst=2001:db8::42 |<ICMPv6EchoRequest type=Echo Request code=0 cksum=0xb76d id=0x16cd seq=0x1 data='\x1f\xe2~\\\x00\x00\x00\x00\xf8\x82\x00\x00\x00\x00\x00\x00\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./01234567' |>>>
|
||||
"""
|
||||
|
||||
log.info("Replying to ICMP packet")
|
||||
dst_mac = pkg[Ether].src
|
||||
src_mac = pkg[Ether].dst
|
||||
|
||||
dst_addr = pkg[IPv6].src
|
||||
src_addr = pkg[IPv6].dst
|
||||
|
||||
e = Ether(src=src_mac, dst=dst_mac)
|
||||
i = IPv6(src=src_addr, dst=dst_addr)
|
||||
i2 = ICMPv6EchoReply(id=pkg[ICMPv6EchoRequest].id,
|
||||
seq=pkg[ICMPv6EchoRequest].seq,
|
||||
data=pkg[ICMPv6EchoRequest].data)
|
||||
i2.cksum = None
|
||||
self.send_pkg(answer)
|
||||
|
||||
|
||||
def handle_icmp6_ns(self, pkg):
|
||||
""" Solicitated NA"""
|
||||
|
||||
|
@ -263,9 +287,6 @@ class L2Controller(object):
|
|||
# Let scapy recalc checksum (try3)
|
||||
# answer = answer.__class__(str(answer))
|
||||
|
||||
|
||||
|
||||
|
||||
self.send_pkg(answer)
|
||||
|
||||
def send_pkg(self, pkg):
|
||||
|
@ -295,7 +316,8 @@ class L2Controller(object):
|
|||
log.info("Doing neighbor solicitation")
|
||||
self.handle_icmp6_ns(orig_packet)
|
||||
elif cpu_header.task == self.task['ICMP6_GENERAL']:
|
||||
log.info("Replying to ICMP packet")
|
||||
if ICMPv6EchoRequest in orig_packet:
|
||||
handle_icmp6_echo_request(orig_packet)
|
||||
|
||||
else:
|
||||
print("Broken pkg: {}".format(pkg.__repr__()))
|
||||
|
|
Loading…
Reference in a new issue