Skip to content

HSRP version 2 - #3005

Merged
gpotter2 merged 1 commit into
secdev:masterfrom
e-LF:hsrp_v2
Aug 14, 2026
Merged

HSRP version 2#3005
gpotter2 merged 1 commit into
secdev:masterfrom
e-LF:hsrp_v2

Conversation

@e-LF

@e-LF e-LF commented Dec 9, 2020

Copy link
Copy Markdown
Contributor

Checklist:

  • If you are new to Scapy: I have checked CONTRIBUTING.md (esp. section submitting-pull-requests)
  • I squashed commits belonging together
  • I added unit tests or explained why they are not relevant
  • 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
e-LF force-pushed the hsrp_v2 branch 3 times, most recently from fcca29b to 8e24273 Compare December 9, 2020 23:09

@gpotter2 gpotter2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR ! It's generally looking pretty good.
A few comments. Not sure about the issue you've pointed out, I will have a look.

Comment thread scapy/layers/hsrp.py Outdated
Comment thread scapy/layers/hsrp.py Outdated
Comment thread scapy/layers/hsrp.py Outdated
Comment thread scapy/layers/hsrp.py Outdated
Comment thread scapy/layers/hsrp.py Outdated
Comment thread scapy/layers/hsrp.py Outdated
@e-LF
e-LF marked this pull request as draft December 10, 2020 19:10
@e-LF
e-LF marked this pull request as ready for review December 10, 2020 22:12
@e-LF
e-LF marked this pull request as draft December 10, 2020 22:13
@e-LF
e-LF requested a review from gpotter2 December 10, 2020 22:20
@e-LF e-LF changed the title Added support for HSRP version 2 and updated HSRP unit test. HSRP version 2 Dec 12, 2020
@codecov

codecov Bot commented Dec 12, 2020

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.78%. Comparing base (35883c1) to head (9b0c2d1).

Files with missing lines Patch % Lines
scapy/layers/hsrp.py 97.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3005      +/-   ##
==========================================
- Coverage   80.57%   79.78%   -0.79%     
==========================================
  Files         390      372      -18     
  Lines       96808    96543     -265     
==========================================
- Hits        78001    77027     -974     
- Misses      18807    19516     +709     
Files with missing lines Coverage Δ
scapy/layers/hsrp.py 96.25% <97.95%> (+4.58%) ⬆️

... and 300 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gpotter2

Copy link
Copy Markdown
Member

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
gpotter2 merged commit 3f7bed3 into secdev:master Aug 14, 2026
21 of 23 checks passed
@gpotter2

Copy link
Copy Markdown
Member

Thanks for the PR !

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