secdev / scapy

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

Exception when trying to import scapy.all on IPv6-enabled hosts #1537

Closed adriangranados closed 6 years ago

adriangranados commented 6 years ago

Hi, I'm getting this exception when trying to import scapy.all. As you can see from the trace, the problem is related to IPv6. Disabling IPv6 in the host computer "fixes" it.

  from scapy.all import * 
File "/usr/lib/python2.7/dist-packages/scapy/all.py", line 28, in <module>
   from scapy.route6 import *
 File "/usr/lib/python2.7/dist-packages/scapy/route6.py", line 273, in <module>
   conf.route6 = Route6()
 File "/usr/lib/python2.7/dist-packages/scapy/route6.py", line 31, in __init__
   self.resync()
 File "/usr/lib/python2.7/dist-packages/scapy/route6.py", line 44, in resync
   self.routes = read_routes6()
 File "/usr/lib/python2.7/dist-packages/scapy/arch/linux.py", line 283, in read_routes6
   cset = scapy.utils6.construct_source_candidate_set(d, dp, devaddrs, LOOPBACK_NAME)
 File "/usr/lib/python2.7/dist-packages/scapy/utils6.py", line 50, in construct_source_candidate_set
   if in6_isgladdr(addr) or in6_isuladdr(addr):
 File "/usr/lib/python2.7/dist-packages/scapy/utils6.py", line 708, in in6_isgladdr
   return in6_isincluded(str, '2000::', 3)
 File "/usr/lib/python2.7/dist-packages/scapy/utils6.py", line 651, in in6_isincluded
   temp = inet_pton(socket.AF_INET6, addr)
 File "/usr/lib/python2.7/dist-packages/scapy/pton_ntop.py", line 40, in inet_pton
   raise Exception("Illegal syntax for IP address")

Any ideas?

guedou commented 6 years ago

Thanks for reporting this issue. Could you share the content of /proc/net/ipv6_route ?

adriangranados commented 6 years ago

Here you go:

wlanpi@wlan-pi:~$ cat /proc/net/ipv6_route
26010249000008310000000000000000 40 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000001 00000000 004c0001     eth0
fe800000000000000000000000000000 40 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000002 00000001 00000001     eth0
00000000000000000000000000000000 00 00000000000000000000000000000000 00 fe800000000000000000000000010001 00000400 00000005 00000142 00c50003     eth0
00000000000000000000000000000001 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000006 0000000f 80200001       lo
2601024900000831000166fffe1600e5 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000005 000001ad 80200001     eth0
fe80000000000000000166fffe1600e5 80 00000000000000000000000000000000 00 00000000000000000000000000000000 00000000 00000003 0000017c 80200001     eth0
ff000000000000000000000000000000 08 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000003 000005ac 00000001     eth0
00000000000000000000000000000000 00 00000000000000000000000000000000 00 00000000000000000000000000000000 ffffffff 00000001 00000001 00200200       lo
guedou commented 6 years ago

Thanks. I will need investigate more as I cannot reproduce this issue yet.

Does your Python interpreter supports IPv6?

adriangranados commented 6 years ago

Thanks.

I believe so:

root@wlanpi:~# python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.has_ipv6
True

The following works fine, too:

wlanpi@wlanpi:~$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
>>> s.bind(('', 12345))

Let me know if there's anything I can do to help.

guedou commented 6 years ago

Is still cannot reproduce this issue.

Could you try the following?

$ git clone https://github.com/secdev/scapy --depth 1
$ cd scapy/
$ ./run_scapy
mloiterman commented 6 years ago

Adrian was helping me on this issue. Here is the output you've asked for:

wlanpi@wlan-pi:~/test$ git clone https://github.com/secdev/scapy --depth 1
Cloning into 'scapy'...
remote: Counting objects: 444, done.
remote: Compressing objects: 100% (432/432), done.
remote: Total 444 (delta 21), reused 121 (delta 3), pack-reused 0
Receiving objects: 100% (444/444), 3.17 MiB | 0 bytes/s, done.
Resolving deltas: 100% (21/21), done.
wlanpi@wlan-pi:~/test$ ls
scapy
wlanpi@wlan-pi:~/test$ cd scapy/
wlanpi@wlan-pi:~/test/scapy$ ls
bin              LICENSE      README.md      run_scapy_py2      run_scapy_py3.bat  setup.py
CONTRIBUTING.md  MANIFEST.in  run_scapy      run_scapy_py2.bat  scapy              test
doc              README       run_scapy.bat  run_scapy_py3      setup.cfg          tox.ini
wlanpi@wlan-pi:~/test/scapy$ ./run_scapy
INFO: Can't import matplotlib. Won't be able to plot.
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
WARNING: Failed to execute tcpdump. Check it is installed and in the PATH
INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11)
INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication.
WARNING: IPython not available. Using standard Python shell instead.
AutoCompletion, History are disabled.

                    aSPY//YASa       
            apyyyyCY//////////YCa       |
           sY//////YSpcs  scpCY//Pp     | Welcome to Scapy
ayp ayyyyyyySCP//Pp           syY//C    | Version 1fc08e0
AYAsAYYYYYYYY///Ps              cY//S   |
        pCCCCY//p          cSSps y//Y   | https://github.com/secdev/scapy
        SPPPP///a          pP///AC//Y   |
             A//A            cyP////C   | Have fun!
             p///Ac            sC///a   |
             P////YCpc           A//A   | To craft a packet, you have to be a
      scccccp///pSP///p          p//Y   | packet, and learn how to swim in
     sY/////////y  caa           S//P   | the wires and in the waves.
      cayCyayP//Ya              pY/Ya   |        -- Jean-Claude Van Damme
       sY/PsY////YCc          aC//Yp    |
        sc  sccaCY//PCypaapyCP//YSs  
                 spCPY//////YPSps    
                      ccaacs  
guedou commented 6 years ago

Everything seems to work as expected with this version. Could you try launching your script from this directory ?

adriangranados commented 6 years ago

Not sure if you meant copying the script to the directory where the scapy sources are and running it from there, but here it is the output:

wlanpi@wlan-pi:~$ cd test/
wlanpi@wlan-pi:~/test$ git clone https://github.com/secdev/scapy --depth 1
Cloning into 'scapy'...
remote: Counting objects: 444, done.
remote: Compressing objects: 100% (432/432), done.
remote: Total 444 (delta 21), reused 121 (delta 3), pack-reused 0
Receiving objects: 100% (444/444), 3.17 MiB | 0 bytes/s, done.
Resolving deltas: 100% (21/21), done.
wlanpi@wlan-pi:~/test$ ls
scapy
wlanpi@wlan-pi:~/test$ cd scapy/
wlanpi@wlan-pi:~/test/scapy$ ls
bin              LICENSE      README.md      run_scapy_py2      run_scapy_py3.bat  setup.py
CONTRIBUTING.md  MANIFEST.in  run_scapy      run_scapy_py2.bat  scapy              test
doc              README       run_scapy.bat  run_scapy_py3      setup.cfg          tox.ini
wlanpi@wlan-pi:~/test/scapy$ cp /usr/local/bin/wifiexplorer-sensor.py .
wlanpi@wlan-pi:~/test/scapy$ ./wifiexplorer-sensor.py wlan0
You need to have root privileges to run this script.
wlanpi@wlan-pi:~/test/scapy$ ls
bin              MANIFEST.in  run_scapy.bat      run_scapy_py3.bat  test
CONTRIBUTING.md  README       run_scapy_py2      scapy              tox.ini
doc              README.md    run_scapy_py2.bat  setup.cfg          wifiexplorer-sensor.py
LICENSE          run_scapy    run_scapy_py3      setup.py
wlanpi@wlan-pi:~/test/scapy$ sudo ./wifiexplorer-sensor.py wlan0
[sudo] password for wlanpi:
(info) ready
(info) connected to 192.168.1.64
(info) disconnected from 192.168.1.64
(info) ready
^Cwlanpi@wlan-pi:~/test/scapy$ ipc
ipcmk  ipcrm  ipcs   
wlanpi@wlan-pi:~/test/scapy$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.43  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 0000:000:0:000:0:0000:0000:00  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::1:66ff:fe16:e5  prefixlen 64  scopeid 0x20<link>
        ether 02:01:66:16:00:e5  txqueuelen 10000  (Ethernet)
        RX packets 6921343  bytes 6267045216 (5.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6951917  bytes 6909884249 (6.4 GiB)
        TX errors 0  dropped 28 overruns 0  carrier 0  collisions 0
        device interrupt 23  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 16  bytes 1624 (1.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1624 (1.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0mon: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 11671257  bytes 1130837049 (1.0 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Doing this WORKS with IPv6 ENABLED. However note that this is true with eth0 being configured with an ipv6 and MAC address set to 0. Not sure if that makes a difference. Do you want us to test it with real ipv6 and MAC addresses?

guedou commented 6 years ago

If you can that will be perfect, but it looks like the current Scapy versions fixes your issue. Please reopen if needed.