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

Implement global & extensible interfaces #2707

Merged
merged 7 commits into from
Sep 24, 2020
Merged

Conversation

gpotter2
Copy link
Member

@gpotter2 gpotter2 commented Jul 7, 2020

A pretty major refactor based on a very old PR, but pretty cool. This:

  • unifies how interfaces work on all platforms using a scapy/interfaces.py file and introducing conf.ifaces
  • makes the switch to libpcap work in all cases
  • drops the last places where "dnet" was used to make it clear we stopped supporting it (env var, "pcapdnet" file)
  • merges get_if_list on all platforms
  • improves how interfaces are detected on OSX
  • gives extra detail about the status of the interfaces using interfaces flags and lists all interfaces in a human friendly way
  • allows multiple interfaces providers to cohabitate, in a wireshark extcap style, and for each one to provide it's own sockets. This is very useful for USB sockets for instance, or if the user wants to add its own interfaces/providers to scapy.

It brings the "interfaces" objects to other platforms. Those are cool because they give you the content of the flags and avoid having to re-read the /etc/ files each time you need them.

Screenshots

e.g.: Linux
image

e.g.: Usbpcap AND libpcap
image

This is fully backward compatible: the interfaces objects implement the same functions as strings: conf.iface + "test" == "eth0test" so that it doesn't break anything, and all functions use a network_name function to get the network name from the object or a string (instead of the current if WINDOWS: .... checks)

Tested

  • Windows & Linux (manual + unit tests)
  • OS x (manual + unit tests)
  • *BSD (manual)

How to test this

Mainteners, please test the changes (there are unit tests, but I'd like you all to give some feedback on the features): try playing around with conf.ifaces and conf.iface, then with conf.use_pcap to understand what it does.

@gpotter2 gpotter2 force-pushed the interfaces branch 12 times, most recently from e8965a9 to 163effa Compare July 13, 2020 19:40
@codecov
Copy link

codecov bot commented Jul 13, 2020

Codecov Report

Merging #2707 into master will decrease coverage by 0.08%.
The diff coverage is 90.33%.

@@            Coverage Diff             @@
##           master    #2707      +/-   ##
==========================================
- Coverage   88.26%   88.18%   -0.09%     
==========================================
  Files         252      254       +2     
  Lines       53534    54004     +470     
==========================================
+ Hits        47252    47622     +370     
- Misses       6282     6382     +100     
Impacted Files Coverage Δ
scapy/themes.py 80.91% <25.00%> (ø)
scapy/layers/usb.py 75.60% <57.14%> (-5.45%) ⬇️
scapy/supersocket.py 75.39% <75.00%> (+1.33%) ⬆️
scapy/arch/windows/__init__.py 68.43% <81.91%> (-2.82%) ⬇️
scapy/arch/bpf/core.py 87.59% <84.84%> (+3.43%) ⬆️
scapy/arch/libpcap.py 82.03% <88.67%> (ø)
scapy/utils.py 81.66% <90.47%> (+0.85%) ⬆️
scapy/interfaces.py 96.90% <96.90%> (ø)
scapy/all.py 100.00% <100.00%> (ø)
scapy/arch/__init__.py 92.50% <100.00%> (-0.69%) ⬇️
... and 30 more

@gpotter2 gpotter2 force-pushed the interfaces branch 14 times, most recently from 754931d to a9fa891 Compare July 19, 2020 21:09
@gpotter2 gpotter2 added the major Major changes label Jul 19, 2020
@gpotter2 gpotter2 force-pushed the interfaces branch 3 times, most recently from f422824 to 1451e45 Compare September 13, 2020 12:52
@guedou
Copy link
Member

guedou commented Sep 14, 2020

The display looks way better now. Thanks! I did not notice it during my first test, but on macOS inactive interfaces are also listed. I think that is not necessary as they Scapy won't be able to use them. Another point, the "WARNING: No IPv4 address found" messages are not necessary too.

@guedou
Copy link
Member

guedou commented Sep 14, 2020

On a fresh Ubuntu 18.04 installation, the following creating a dummy network interface with sudo ip link add name scapy0 type dummy gives the following output:

>>> conf.ifaces
Source  Index  Name    MAC                IPv4          IPv6                               
sys     3      scapy0  ce:d1:6c:1f:ac:32  0.0.0.0                                          
sys     2      eth0    00:1c:42:69:bc:31  10.211.55.11  fdb2:2c26:f4e4:0:21c:42ff:fe69:bc31
                                                        fe80::21c:42ff:fe69:bc31           
sys     1      lo      00:00:00:00:00:00  127.0.0.1     ::1 

I see several issues here:

  • scapy0 is not up and should not be displayed
  • the IPv4 should be empty

@guedou
Copy link
Member

guedou commented Sep 14, 2020

04b8d1eaef3b7d1228b3673b3a45059c8746a275 works fine on FreeBSD 12.1 (^^)/

@gpotter2
Copy link
Member Author

gpotter2 commented Sep 14, 2020

I'm pretty sure get_if_list() used to display all interfaces, even the ones not running. On Windows the interfaces that are not running were marked with a flag invalid=True. This flag tagged it as not suitable for default interface but let it appear elsewhere. The flag was replaced by a function specific to the provider, but still has the same effects.

Should we remove interfaces that are not up from get_if_list() (everywhere in scapy: routes, conf.ifaces, ...), or only from the output of conf.ifaces display?

Also sorry but I lost track of what 04b8d1eaef3b7d1228b3673b3a45059c8746a275 was ^^

@guedou
Copy link
Member

guedou commented Sep 15, 2020

Let's keep the current get_if_list() behavior for now. I think that conf.ifaces should only list interfaces that Scapy could use.

By the way, do you think that conf.ifaces could be ordered by the interface index? Index could be the first column. An interesting use case could be conf.iface = conf.ifaces[5].

@gpotter2
Copy link
Member Author

I've settled on a middle ground:

>>> conf.ifaces
Source  Index  Name  MAC                IPv4       IPv6
sys     2      eth0  Microsof:aa:aa:aa  10.0.0.5   XXXXX
sys     1      lo    00:00:00:00:00:00  127.0.0.1  ::1
>>> conf.ifaces.show(hidden=True)
Source  Index  Name    MAC                IPv4       IPv6
sys     4      scapy0  9a:4c:10:71:24:07
sys     2      eth0    Microsof:aa:aa:aa  10.0.0.5   XXXXX
sys     1      lo      00:00:00:00:00:00  127.0.0.1  ::1

I also changed the sorting

@guedou
Copy link
Member

guedou commented Sep 21, 2020

@p-l- what's your call?

@gpotter2 gpotter2 requested a review from guedou September 23, 2020 18:02
@guedou
Copy link
Member

guedou commented Sep 24, 2020

Can I merge this or do you want me to sqash the commits?

@gpotter2 gpotter2 merged commit 4521d8a into secdev:master Sep 24, 2020
@gpotter2 gpotter2 deleted the interfaces branch September 25, 2020 12:59
@guedou
Copy link
Member

guedou commented Sep 26, 2020 via email

bzalkilani pushed a commit to bzalkilani/scapy that referenced this pull request Jun 12, 2022
* Implement global & extensible interfaces

* Simplify detection of valid interfaces

* Linux: handle interfaces with no IPv4

* Reimplement get_working_ifaces

* Remove 'main' IPv6 in interfaces

* Don't show invalid interfaces by default

* Update error message
bzalkilani pushed a commit to bzalkilani/scapy that referenced this pull request Jun 14, 2022
* Implement global & extensible interfaces

* Simplify detection of valid interfaces

* Linux: handle interfaces with no IPv4

* Reimplement get_working_ifaces

* Remove 'main' IPv6 in interfaces

* Don't show invalid interfaces by default

* Update error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants