Skip to content

Linux 802.1Q support #2091

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

Merged
merged 4 commits into from
Jul 10, 2019
Merged

Linux 802.1Q support #2091

merged 4 commits into from
Jul 10, 2019

Conversation

gpotter2
Copy link
Member

@gpotter2 gpotter2 commented Jun 15, 2019

See #969

This only works with Python 3

IMH we shouldn't bother supporting Python 2.7. I'm against implementing the whole shabang of ctypes calls to support something which EOL is so soon.

@codecov
Copy link

codecov bot commented Jun 15, 2019

Codecov Report

Merging #2091 into master will increase coverage by 0.03%.
The diff coverage is 90.62%.

@@            Coverage Diff             @@
##           master    #2091      +/-   ##
==========================================
+ Coverage   87.28%   87.32%   +0.03%     
==========================================
  Files         199      199              
  Lines       45094    45318     +224     
==========================================
+ Hits        39361    39572     +211     
- Misses       5733     5746      +13
Impacted Files Coverage Δ
scapy/sendrecv.py 84.09% <71.42%> (-0.2%) ⬇️
scapy/arch/linux.py 77.32% <96%> (+1.12%) ⬆️
scapy/pton_ntop.py 89.04% <0%> (-8.22%) ⬇️
scapy/layers/tls/basefields.py 79.86% <0%> (-0.68%) ⬇️
scapy/layers/inet6.py 88.05% <0%> (-0.24%) ⬇️
scapy/arch/windows/__init__.py 71.81% <0%> (-0.16%) ⬇️
scapy/asn1/ber.py 83.09% <0%> (+0.28%) ⬆️
scapy/scapypipes.py 87.26% <0%> (+0.65%) ⬆️
scapy/layers/l2.py 84.97% <0%> (+0.73%) ⬆️
scapy/layers/tls/record.py 92.1% <0%> (+0.87%) ⬆️
... and 2 more

@guedou
Copy link
Member

guedou commented Jun 15, 2019

Cool PR!

Could you add unit tests like done in sendniff.uts?

@gpotter2
Copy link
Member Author

gpotter2 commented Jun 21, 2019

Could you add unit tests like done in sendniff.uts?

I wasn't even able to try it out locally -_- If someone can figure it out I'd really appreciate it

@guedou
Copy link
Member

guedou commented Jun 27, 2019

I am still trying to find a way to test it.

@gpotter2 gpotter2 mentioned this pull request Jun 29, 2019
27 tasks
@guedou
Copy link
Member

guedou commented Jul 8, 2019

I tested it against two VMs in the VLAN, and it works as expected.

This PR:

>>> sniff(iface="eth1", prn=lambda p: p.summary(), count=2)
Ether / Dot1Q / IP / ICMP 1.1.1.2 > 1.1.1.1 echo-request 0 / Raw                                                              
Ether / Dot1Q / IP / ICMP 1.1.1.1 > 1.1.1.2 echo-reply 0 / Raw

master

>>> sniff(iface="eth1", prn=lambda p: p.summary(), count=2)
Ether / IP / ICMP 1.1.1.2 > 1.1.1.1 echo-request 0 / Raw
Ether / IP / ICMP 1.1.1.1 > 1.1.1.2 echo-reply 0 / Raw

@guedou
Copy link
Member

guedou commented Jul 8, 2019

I finally managed to find a way to test this PR locally. Hopefully this will also work on Travis.

git diff test/linux.uts
diff --git a/test/linux.uts b/test/linux.uts
index 6de875f0..9ebcc385 100644
--- a/test/linux.uts
+++ b/test/linux.uts
@@ -378,3 +378,50 @@ exit_status = os.system("ip addr add 192.0.2.1/24 dev scapy0")
 exit_status = os.system("ip link set scapy0 up")
 assert _interface_selection(None, IP(dst="192.0.2.42")/UDP()) == "scapy0"
 exit_status = os.system("ip link del name dev scapy0")
+
+= Test 802.Q sniffing
+~ linux needs_root
+
+from threading import Thread, Condition
+
+veth = VEthPair("left0", "right0")
+veth.setup()
+veth.up()
+exit_status = os.system("ip link add link right0 name vlanright0 type vlan id 42")
+exit_status = os.system("ip link add link left0 name vlanleft0 type vlan id 42")
+exit_status = os.system("ip link set vlanright0 up")
+exit_status = os.system("ip link set vlanleft0 up")
+exit_status = os.system("ip addr add 198.51.100.1/24 dev vlanleft0")
+exit_status = os.system("ip addr add 198.51.100.2/24 dev vlanright0")
+
+cond_started = Condition()
+
+def _sniffer_started():
+
+    global cond_started
+    cond_started.acquire()
+    cond_started.notify()

+    cond_started.release()
+
+cond_started.acquire()
+
+dot1q_count = 0
+
+def _sniffer():
+    sniffed = sniff(iface="right0",
+                    lfilter=lambda p: Dot1Q in p,
+                    count=2,
+                    timeout=5,
+                    started_callback=_sniffer_started)
+    global dot1q_count
+    dot1q_count = len(sniffed)
+
+t_sniffer = Thread(target=_sniffer)
+t_sniffer.start()
+cond_started.wait()
+sendp(Ether()/IP(dst="198.51.100.2")/ICMP(), iface='vlanleft0', count=2)
+
+t_sniffer.join(1)
+assert(dot1q_count == 2)
+
+veth.destroy()

@gpotter2 gpotter2 closed this Jul 9, 2019
@gpotter2 gpotter2 reopened this Jul 9, 2019
@guedou guedou merged commit 1a3b3be into secdev:master Jul 10, 2019
@gpotter2 gpotter2 deleted the vlan branch July 10, 2019 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants