Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scapy fails to launch when netifaces is installed #22

Closed
tzudot opened this issue Sep 29, 2015 · 15 comments
Closed

scapy fails to launch when netifaces is installed #22

tzudot opened this issue Sep 29, 2015 · 15 comments

Comments

@tzudot
Copy link

tzudot commented Sep 29, 2015

(scapy3k)~ ❯❯❯ scapy

INFO: Can't import python gnuplot wrapper . Won't be able to plot.
Traceback (most recent call last):
  File "/Users/tzudot/.virtualenvs/scapy3k/bin/scapy", line 25, in <module>
    interact()
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/main.py", line 293, in interact
    scapy_builtins = __import__("scapy.all",globals(),locals(),".").__dict__
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/all.py", line 25, in <module>
    from .route import *
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/route.py", line 163, in <module>
    conf.route=Route()
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/route.py", line 22, in __init__
    self.resync()
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/route.py", line 31, in resync
    self.routes = read_routes()
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/arch/unix.py", line 82, in read_routes
    ifaddr = scapy.arch.get_if_addr(netif)
  File "/Users/tzudot/.virtualenvs/scapy3k/lib/python3.5/site-packages/scapy/arch/__init__.py", line 37, in get_if_addr
    return socket.inet_ntoa(get_if_raw_addr(iff))
TypeError: a bytes-like object is required, not 'NoneType'

Is netifaces package optional? I see, you have stated this on stackoverflow.com. What do you suggest, should netifaces be installed or not?

EDIT: I am running scapy on Mac OS X 10.10.5.

@phaethon
Copy link
Owner

Netifaces is optional. Try removing netifaces and trying again. I will check if they introduced some incompatible changes in netifaces.

@tzudot
Copy link
Author

tzudot commented Sep 30, 2015

Yeah, it works alright without netifaces installed. I was wondering if netifaces would be useful under certain circumstances for scapy or else why at all have this dependency, and is it worthwhile looking into this failure?

@phaethon
Copy link
Owner

netifaces provides OS independent and clean way to determine IP addresses of interfaces. It makes code cleaner, but apparently there have been some changes on the netifaces side as it used to work few months ago.

@tzudot
Copy link
Author

tzudot commented Sep 30, 2015

While debugging the issue, the error came up at line number 66 in pcapdnet.py. The issue is, looking up of IP address of an invalid interface, bridge1 in my case.

BTW, the routes on the machines as fetched by netifaces are in https://gist.github.com/anonymous/fdc6b0c5b4cd96955287 but in reality there is no such device as bridge1.

@tzudot
Copy link
Author

tzudot commented Oct 1, 2015

On further debugging, I have found that the route gist is the output of netstat -rn from file unix.py on line 37, and not from netifaces.

So, it is clear to me now that the error is not from netifaces as I might have suggested earlier.

@phaethon
Copy link
Owner

phaethon commented Oct 1, 2015

When netifaces is available, it overrides get_if_list function and uses netifaces.interfaces(). Please, provide your actual netstat -rn output and netifaces.interfaces() output.

@tzudot
Copy link
Author

tzudot commented Oct 1, 2015

>>> netifaces.interfaces()
['lo0', 'gif0', 'stf0', 'en1', 'en0', 'en2', 'en3', 'p2p0', 'awdl0', 'bridge0', 'bridge100', 'utun0', 'vboxnet0', 'vboxnet1', 'vboxnet2']
❯❯❯ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            10.0.2.1           UGSc          167        0     en1
default            link#11            UCSI            0        0 bridge1
10.0.2/24          link#4             UCS             1        0     en1
10.0.2.1/32        link#4             UCS             2        0     en1
10.0.2.1           24:a2:e1:e6:f8:54  UHLWIir       169        7     en1    913
10.0.2.4           24:a2:e1:e6:f8:54  UHLWI           0        9     en1   1199
10.0.2.8/32        link#4             UCS             0        0     en1
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              1       26     lo0
169.254            link#4             UCS             0        0     en1
192.168.2          link#11            UC              1        0 bridge1

Internet6:
Destination                             Gateway                         Flags         Netif Expire
::1                                     ::1                             UHL             lo0
fde9:2dd0:8e47:d788::/64                fe80::7d36:cd1b:c121:6ace%utun0 Uc            utun0
fde9:2dd0:8e47:d788:7d36:cd1b:c121:6ace link#12                         UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en1/64                           link#4                          UCI             en1
fe80::26a2:e1ff:fee6:f854%en1           24:a2:e1:e6:f8:54               UHLWI           en1
fe80::62f8:1dff:feb8:e72%en1            60:f8:1d:b8:e:72                UHLI            lo0
fe80::%awdl0/64                         link#9                          UCI           awdl0
fe80::a866:eaff:feca:cac9%awdl0         aa:66:ea:ca:ca:c9               UHLI            lo0
fe80::%bridge100/64                     link#11                         UCI        bridge10
fe80::60f8:1dff:fe8b:9264%bridge100     62.f8.1d.8b.92.64               UHLI            lo0
fe80::%utun0/64                         fe80::7d36:cd1b:c121:6ace%utun0 UcI           utun0
fe80::7d36:cd1b:c121:6ace%utun0         link#12                         UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en1/32                           link#4                          UmCI            en1
ff01::%awdl0/32                         link#9                          UmCI          awdl0
ff01::%bridge100/32                     link#11                         UmCI       bridge10
ff01::%utun0/32                         fe80::7d36:cd1b:c121:6ace%utun0 UmCI          utun0
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en1/32                           link#4                          UmCI            en1
ff02::%awdl0/32                         link#9                          UmCI          awdl0
ff02::%bridge100/32                     link#11                         UmCI       bridge10
ff02::%utun0/32                         fe80::7d36:cd1b:c121:6ace%utun0 UmCI          utun0

@phaethon
Copy link
Owner

phaethon commented Oct 1, 2015

Apparently there are differences between interface names as returned by netstat and netifaces. bridge0 vs. bridge 1, bridge100 vs. bridge10. So, this is likely a bug for netifaces for your specific configuration (or generally for bridged interfaces).

@tzudot
Copy link
Author

tzudot commented Oct 1, 2015

Output from ifconfig is similar to output of netifaces. I guess, netstat -nw is messing up.

❯❯❯ ifconfig| grep mtu | cut -d':' -f1
lo0
gif0
stf0
en1
en0
en2
en3
p2p0
awdl0
bridge0
bridge100
utun0
vboxnet0
vboxnet1
vboxnet2

@phaethon
Copy link
Owner

phaethon commented Oct 1, 2015

Current assumption is that interface names are consistent with output from netstat. I believe it is a marginal case that netstat returns different names than ifconfig. So for your case I recommend using scapy without netifaces.

@tzudot
Copy link
Author

tzudot commented Oct 3, 2015

Yeah, this was an issue of a messed up network configuration with virtualbox. I have now done a clean install of Mac OS X 10.11, which has cleared up netstat -rn output.

@tzudot tzudot closed this as completed Oct 3, 2015
@ciobania
Copy link

ciobania commented May 16, 2016

I confirm that there is still an issue present.
It seems to me that a fix can be released, to skip or try/except, in the next file:
get_if_addr from arch/init.py

The error is reproducible if you have a VM, created with virtualbox, and start the VM.
The only way to use this without changing the actual package, vboxnet interfaces need to be shutdown:
ifconfig vboxnet0 down
ifconfig vboxnet1 down
...
ifconfig vboxnetn down

I understand it's not an ideal solution, but nor is reinstalling the system. I currently use my company's laptop, and it's not like I can reinstall anytime I want.
Maybe someone with more knowledge, will provide a better explanation as to why this happens, and maybe who is actually meant to "fix" it.

Thank you.

@phaethon
Copy link
Owner

@ciobania did you try using scapy with netifaces switched off? It is optional package as was written before.

@ciobania
Copy link

Yes, and the behaviour is still present.
In my case, we need netifaces, AND scapy.
They do run fine together, only if I disable the interfaces like in my previous comment.

I am using it home on some personal projects as well, and I have no issue on that machine.

@phaethon
Copy link
Owner

Why do you need netifaces enabled in scapy (especially, as it runs better with it disabled for your case)? conf.use_netifaces disables it for scapy, you can still use netifaces anything else you need in your script.

flokli pushed a commit to flokli/scapy that referenced this issue Nov 21, 2016
Use appropriate config value to call tcpdump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants