secdev / scapy

Scapy: the Python-based interactive packet manipulation program & library.
https://scapy.net
GNU General Public License v2.0
10.65k stars 2.02k forks source link

Error when elaborated an ipv6: socket.gaierror: [Errno 11001] getaddrinfo failed #1670

Closed sal-versij closed 5 years ago

sal-versij commented 5 years ago

Description

I get this error when i execute scapy with npcap, without npcap scapy starts normaly.

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\scapy\utils.py", line 423, in atol
    ip = 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 "C:\Python37\Scripts\\scapy", line 25, in <module>
    interact()
  File "C:\Python37\lib\site-packages\scapy\main.py", line 421, in interact
    init_session(session_name, mydict)
  File "C:\Python37\lib\site-packages\scapy\main.py", line 295, in init_session
    scapy_builtins = {k: v for k, v in six.iteritems(importlib.import_module(".all", "scapy").__dict__) if _validate_local(k)}
  File "C:\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Python37\lib\site-packages\scapy\all.py", line 25, in <module>
    from scapy.route import *
  File "C:\Python37\lib\site-packages\scapy\route.py", line 193, in <module>
    iface = conf.route.route("0.0.0.0", verbose=0)[0]
  File "C:\Python37\lib\site-packages\scapy\route.py", line 155, in route
    aa = atol(a)
  File "C:\Python37\lib\site-packages\scapy\utils.py", line 425, in atol
    ip = inet_aton(socket.gethostbyname(x))
socket.gaierror: [Errno 11001] getaddrinfo failed

Environment


I tried to debug utils.py at line 421 with a simple print:

def atol(x):
    print(x)
    try:
        ip = inet_aton(x)
    except socket.error:
        ip = inet_aton(socket.gethostbyname(x))
    print(ip,struct.unpack("!I", ip))
    return struct.unpack("!I", ip)[0]

the result is a serie of ip and how their returned like

0.0.0.0
b'\x00\x00\x00\x00' (0,)

and before the error there is an ipv6 as x:

xxxx:xxxx:xxxx:xxxx:xxxx:xxxx

the problem occur when is passed an ipv6 to atol so i tried to elaborate the ipv6 as a number when it is prompted:

def ip6_to_integer(ip6):
    ip6 = socket.inet_pton(socket.AF_INET6, ip6)
    a, b = struct.unpack(">QQ", ip6)
    return (a << 64) | b
def atol(x):
    try:
        if len(x.split(':'))>1:
            return ip6_to_integer(x)
        ip = inet_aton(x)
    except socket.error:
        ip = inet_aton(socket.gethostbyname(x))
    return struct.unpack("!I", ip)[0]

I don't know if I did it the right way or if there is not supposed to be an ipv6 but for now it seem to run well.


I excuse myself for any grammatical error but I'm not english

gpotter2 commented 5 years ago

Hi ! Could you retry using the github version ? Thanks for reporting

sal-versij commented 5 years ago

Ok, I cloned the project to my Github Desktop and executed run_scapy.bat but the error is the same:

Traceback (most recent call last):
  File "C:\Users\****\Documents\GitHub\scapy\scapy\utils.py", line 436, in atol
    ip = 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 "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\****\Documents\GitHub\scapy\scapy\__main__.py", line 15, in <module>
    interact()
  File "C:\Users\****\Documents\GitHub\scapy\scapy\main.py", line 461, in interact
    init_session(session_name, mydict)
  File "C:\Users\****\Documents\GitHub\scapy\scapy\main.py", line 329, in init_session
    scapy_builtins = {k: v for k, v in six.iteritems(importlib.import_module(".all", "scapy").__dict__) if _validate_local(k)}  # noqa: E501
  File "C:\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\****\Documents\GitHub\scapy\scapy\all.py", line 27, in <module>
    from scapy.route import *
  File "C:\Users\****\Documents\GitHub\scapy\scapy\route.py", line 196, in <module>
    iface = conf.route.route(None, verbose=0)[0]
  File "C:\Users\****\Documents\GitHub\scapy\scapy\route.py", line 160, in route
    aa = atol(a)
  File "C:\Users\****\Documents\GitHub\scapy\scapy\utils.py", line 438, in atol
    ip = inet_aton(socket.gethostbyname(x))
socket.gaierror: [Errno 11001] getaddrinfo failed
gpotter2 commented 5 years ago

Ok let’s perform a small investigation: Could you start a python shell (not scapy), and return the result of the following (please call them individually)

from scapy.arch.windows import *
IFACES.show()
read_routes()
read_routes6()
conf.cache_iflist
conf.cache_ipaddrs
conf.cache_in6_getifaddr
get_ips()
get_ips(True)

That will give some context (actually pretty much all context I could ask for)

Sorry if that’s a bit annoying, the output will be quite long. You can use pastebin if that’s easier

Thanks !

sal-versij commented 5 years ago

Sorry for the wait

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from scapy.arch.windows import *
>>> IFACES.show()
INDEX  IFACE                                     IP                         MAC
11     Killer E2500 Gigabit Ethernet Controller  192.168.1.100              4C:CC:6A:D8:DF:DC
14     LogMeIn Hamachi Virtual Ethernet Adapter  fe80::6dbe:7982:9e25:3cea  7A:79:19:4A:DB:4B
15     VirtualBox Host-Only Ethernet Adapter     192.168.56.1               0A:00:27:00:00:0F
3      Npcap Loopback Adapter                    127.0.0.1                  00:00:00:00:00:00
>>> read_routes()
[(4294967295, 4294967295, '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 281), (4294967295, 429496
7295, '0.0.0.0', <NetworkInterface LogMeIn Hamachi Virtual Ethernet Adapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, 'fe80::6dbe:7982:9e25:3cea', 9256), (429
4967295, 4294967295, '0.0.0.0', <NetworkInterface VirtualBox Host-Only Ethernet Adapter {B845DEC6-0C9F-418C-A928-675A561BE944}>, '192.168.56.1', 281), (42949
67295, 4294967295, '0.0.0.0', <NetworkInterface Killer E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, '192.168.1.100', 281), (429
4967295, 4294967295, '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 331), (3758096384, 4026531840,
 '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 281), (3758096384, 4026531840, '0.0.0.0', <Network
Interface LogMeIn Hamachi Virtual Ethernet Adapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, 'fe80::6dbe:7982:9e25:3cea', 9256), (3758096384, 4026531840, '0.0
.0.0', <NetworkInterface VirtualBox Host-Only Ethernet Adapter {B845DEC6-0C9F-418C-A928-675A561BE944}>, '192.168.56.1', 281), (3758096384, 4026531840, '0.0.0
.0', <NetworkInterface Killer E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, '192.168.1.100', 281), (3758096384, 4026531840, '0.0
.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 331), (3232250111, 4294967295, '0.0.0.0', <NetworkInter
face VirtualBox Host-Only Ethernet Adapter {B845DEC6-0C9F-418C-A928-675A561BE944}>, '192.168.56.1', 281), (3232249857, 4294967295, '0.0.0.0', <NetworkInterfa
ce VirtualBox Host-Only Ethernet Adapter {B845DEC6-0C9F-418C-A928-675A561BE944}>, '192.168.56.1', 281), (3232249856, 4294967040, '0.0.0.0', <NetworkInterface
 VirtualBox Host-Only Ethernet Adapter {B845DEC6-0C9F-418C-A928-675A561BE944}>, '192.168.56.1', 281), (3232236031, 4294967295, '0.0.0.0', <NetworkInterface K
iller E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, '192.168.1.100', 281), (3232235876, 4294967295, '0.0.0.0', <NetworkInterface
 Killer E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, '192.168.1.100', 281), (3232235776, 4294967040, '0.0.0.0', <NetworkInterfa
ce Killer E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, '192.168.1.100', 281), (2852061183, 4294967295, '0.0.0.0', <NetworkInter
face Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 281), (2852039499, 4294967295, '0.0.0.0', <NetworkInterface Npcap Loopback
Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 281), (2851995648, 4294901760, '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-ED
F7-42BB-8BFF-044022D01246}>, '127.0.0.1', 281), (2147483647, 4294967295, '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D
01246}>, '127.0.0.1', 331), (2130706433, 4294967295, '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1'
, 331), (2130706432, 4278190080, '0.0.0.0', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, '127.0.0.1', 331), (0, 0, '25.0
.0.1', <NetworkInterface LogMeIn Hamachi Virtual Ethernet Adapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, 'fe80::6dbe:7982:9e25:3cea', 9256), (0, 0, '192.16
8.1.1', <NetworkInterface Killer E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, '192.168.1.100', 25)]
>>> read_routes6()
[('ff00::', 8, '::', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, ['::1'], 281), ('ff00::', 8, '::', <NetworkInterface N
pcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, ['::1'], 331), ('fe80::d5b5:697d:f53e:ab4b', 128, '::', <NetworkInterface Npcap Loopback Adapt
er {192C1806-EDF7-42BB-8BFF-044022D01246}>, ['::1'], 281), ('fe80::6dbe:7982:9e25:3cea', 128, '::', <NetworkInterface LogMeIn Hamachi Virtual Ethernet Adapte
r {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, ['fe80::6dbe:7982:9e25:3cea'], 271), ('fe80::51d5:e98a:7810:a8b8', 128, '::', <NetworkInterface VirtualBox Host-On
ly Ethernet Adapter {B845DEC6-0C9F-418C-A928-675A561BE944}>, ['fe80::51d5:e98a:7810:a8b8'], 281), ('fe80::2d29:6355:29a:302e', 128, '::', <NetworkInterface K
iller E2500 Gigabit Ethernet Controller {7F61AB90-5C40-499F-9CC5-013E2924646A}>, ['fe80::2d29:6355:29a:302e'], 281), ('fe80::', 64, '::', <NetworkInterface N
pcap Loopback Adapter {192C1806-EDF7-42BB-8BFF-044022D01246}>, ['::1'], 281), ('fe80::', 64, '::', <NetworkInterface LogMeIn Hamachi Virtual Ethernet Adapter
 {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, ['fe80::6dbe:7982:9e25:3cea'], 271), ('fe80::', 64, '::', <NetworkInterface VirtualBox Host-Only Ethernet Adapter {
B845DEC6-0C9F-418C-A928-675A561BE944}>, ['fe80::51d5:e98a:7810:a8b8'], 281), ('fe80::', 64, '::', <NetworkInterface Killer E2500 Gigabit Ethernet Controller
{7F61AB90-5C40-499F-9CC5-013E2924646A}>, ['fe80::2d29:6355:29a:302e'], 281), ('2620:9b::194a:db4b', 128, '::', <NetworkInterface LogMeIn Hamachi Virtual Ethe
rnet Adapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, ['2620:9b::194a:db4b'], 271), ('2620:9b::', 96, '::', <NetworkInterface LogMeIn Hamachi Virtual Etherne
t Adapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, ['2620:9b::194a:db4b'], 271), ('2620:9b::', 64, '::', <NetworkInterface LogMeIn Hamachi Virtual Ethernet A
dapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, ['2620:9b::194a:db4b'], 271), ('::1', 128, '::', <NetworkInterface Npcap Loopback Adapter {192C1806-EDF7-42BB
-8BFF-044022D01246}>, ['::1'], 331), ('::', 0, '2620:9b::1900:1', <NetworkInterface LogMeIn Hamachi Virtual Ethernet Adapter {AA5431DE-BBAC-4489-A587-7263D2A
ABDE9}>, ['2620:9b::194a:db4b'], 9015)]
>>> conf.cache_iflist
['\\Device\\NPF_{1EE6F46C-4935-45FB-86B7-8834CFB28F2E}', '\\Device\\NPF_{482356DD-ADD5-4FA0-A97C-31EA296FD17C}', '\\Device\\NPF_{7F61AB90-5C40-499F-9CC5-013E
2924646A}', '\\Device\\NPF_{5AC30C84-E210-4C87-960B-4712ABB87E07}', '\\Device\\NPF_{AA5431DE-BBAC-4489-A587-7263D2AABDE9}', '\\Device\\NPF_{B845DEC6-0C9F-418
C-A928-675A561BE944}', '\\Device\\NPF_{192C1806-EDF7-42BB-8BFF-044022D01246}']
>>> conf.cache_ipaddrs
{'\\Device\\NPF_{7F61AB90-5C40-499F-9CC5-013E2924646A}': b'\xc0\xa8\x01d', '\\Device\\NPF_{B845DEC6-0C9F-418C-A928-675A561BE944}': b'\xc0\xa88\x01', '\\Devic
e\\NPF_{192C1806-EDF7-42BB-8BFF-044022D01246}': b'\x7f\x00\x00\x01'}
>>> conf.cache_in6_getifaddr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Conf' object has no attribute 'cache_in6_getifaddr'
>>> get_ips()
{'Killer E2500 Gigabit Ethernet Controller': '192.168.1.100', 'LogMeIn Hamachi Virtual Ethernet Adapter': 'fe80::6dbe:7982:9e25:3cea', 'VirtualBox Host-Only
Ethernet Adapter': '192.168.56.1', 'Npcap Loopback Adapter': '169.254.171.75'}
>>> get_ips(True)
{'Killer E2500 Gigabit Ethernet Controller': 'fe80::2d29:6355:29a:302e', 'LogMeIn Hamachi Virtual Ethernet Adapter': '2620:9b::194a:db4b', 'VirtualBox Host-O
nly Ethernet Adapter': 'fe80::51d5:e98a:7810:a8b8', 'Npcap Loopback Adapter': 'fe80::d5b5:697d:f53e:ab4b'}
>>>
gpotter2 commented 5 years ago

It’s pretty straight forward:

(0, 0, '25.0
.0.1', <NetworkInterface LogMeIn Hamachi Virtual Ethernet Adapter {AA5431DE-BBAC-4489-A587-7263D2AABDE9}>, 'fe80::6dbe:7982:9e25:3cea', 9256)

Is in your IPv4-only routes. That’s a mistake (it should be in the IPv6 routes).

If you have never edited this, it is a configuration bug that probably happens while setting up LogMeIn or using LogMeIn. That’s to say it’s not on scapy’s side.

We could consider scapy to safely ignore such statements :/ that will prevent anymore of those

guedou commented 5 years ago

I think that ignoring these routes and displaying a warning is the safe way to go.

sal-versij commented 5 years ago

ok thanks for the time