scapy icon indicating copy to clipboard operation
scapy copied to clipboard

HSRP version 2

Open e-LF opened this issue 5 years ago • 2 comments

Checklist:

  • [x] If you are new to Scapy: I have checked CONTRIBUTING.md (esp. section submitting-pull-requests)
  • [x] I squashed commits belonging together
  • [x] I added unit tests or explained why they are not relevant
  • [x] I executed the regression tests for Python2 and Python3 (using tox or, cd test && ./run_tests_py2, cd test && ./run_tests_py3)
  • [ ] If the PR is still not finished, please create a Draft Pull Request

Hello.

While experimenting with Scapy I attempted to perform some HSRP attack on Cisco routers, running the version 2 of the protocol. It failed since it looks like only the version 1 is currentlty supported, so I needed to do some changes. HSRP v2 has not only the version field set to '2' but also has a slightly different header (e.g IPv6 is supported, some fields have not the same size and order...).

This PR add support for HSRP version 2.

There is a limitation though, about automatically filling the UDP ports when using HSRP v2, according to the version of IP used:

bind_layers(UDP, HSRPv2, dport=1985, sport=1985) # HSRP v2 with IPv4 bind_layers(UDP, HSRPv2, dport=2029, sport=2029) # HSRP v2 with IPv6

If dport / sport are not specified explicitly, 2029 will always be used by default. Since scapy has no way to know which port to chose, the port from the last line will be used. Is there a way to make scapy default to 2029 only if IPv6 is used ?

e-LF avatar Dec 09 '20 21:12 e-LF

Codecov Report

Merging #3005 (0edd9bf) into master (4d53d36) will increase coverage by 0.04%. The diff coverage is 97.91%.

@@            Coverage Diff             @@
##           master    #3005      +/-   ##
==========================================
+ Coverage   85.36%   85.41%   +0.04%     
==========================================
  Files         249      249              
  Lines       53338    53405      +67     
==========================================
+ Hits        45533    45616      +83     
+ Misses       7805     7789      -16     
Impacted Files Coverage Δ
scapy/layers/hsrp.py 96.96% <97.91%> (+7.68%) :arrow_up:
scapy/arch/windows/__init__.py 68.25% <0.00%> (-0.58%) :arrow_down:
scapy/config.py 81.29% <0.00%> (-0.20%) :arrow_down:
scapy/layers/inet6.py 88.46% <0.00%> (+0.05%) :arrow_up:
scapy/contrib/isis.py 88.46% <0.00%> (+0.61%) :arrow_up:
scapy/contrib/automotive/bmw/hsfz.py 56.89% <0.00%> (+0.75%) :arrow_up:
scapy/utils.py 79.79% <0.00%> (+0.88%) :arrow_up:
scapy/layers/tls/crypto/groups.py 87.14% <0.00%> (+5.71%) :arrow_up:

codecov[bot] avatar Dec 12 '20 23:12 codecov[bot]

Thanks a lot for the update, this is looking good. You have some tests failing. Remember to unmark this from draft when you think it's ready.

You'll probably have to override build() for the packets, to change the UDP ports on build. I'll provide you an example if i get the time in the following days

gpotter2 avatar Dec 20 '20 03:12 gpotter2