eve2pcap: fix handling of IPv6 addresses #86
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the following error when using
idstools-eve2pcap
(version 0.6.4) andscapy
(version 2.4.4) under python 3 (version 3.8) with json events containing IPv6 src and dest addresses:"Traceback (most recent call last):", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/fields.py\", line 758, in h2i", " inet_aton(x)", "OSError: illegal IP address string passed to inet_aton", "", "During handling of the above exception, another exception occurred:", "", "Traceback (most recent call last):", " File \"/usr/local/bin/idstools-eve2pcap\", line 12, in <module>", " sys.exit(main())", " File \"/usr/local/lib/python3.8/dist-packages/idstools/scripts/eve2pcap.py\", line 239, in main", " hdr, packet = payload2packet(event)", " File \"/usr/local/lib/python3.8/dist-packages/idstools/scripts/eve2pcap.py\", line 163, in payload2packet", " packet = IP(src=event[\"src_ip\"], dst=event[\"dest_ip\"])", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/base_classes.py\", line 392, in __call__", " i.__init__(*args, **kargs)", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/packet.py\", line 171, in __init__", " self.fields[fname] = self.get_field(fname).any2i(self, value)", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/fields.py\", line 793, in any2i", " return self.h2i(pkt, x)", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/fields.py\", line 760, in h2i", " return Net(x)", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/base_classes.py\", line 165, in __init__", " self.start = self.ip2int(net) >> inv_mask << inv_mask", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/base_classes.py\", line 143, in ip2int", " \"!I\", socket.inet_aton(cls.name2addr(addr))", " File \"/usr/local/lib/python3.8/dist-packages/scapy-2.4.5rc1.dev2-py3.8.egg/scapy/base_classes.py\", line 130, in name2addr", " socket.getaddrinfo(name, None, cls.family)", " File \"/usr/lib/python3.8/socket.py\", line 918, in getaddrinfo", " for res in _socket.getaddrinfo(host, port, family, type, proto, flags):", "socket.gaierror: [Errno -9] Address family for hostname not supported"
Basically, scapy has support for IPv6 but requires the
eve2pcap.py
script to distinguish between IPv4 and IPv6 when constructing a packet to dump as PCAP.