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

(discussion) Build AH without SecurityAssociation #4227

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Shu-xueyuan
Copy link

@Shu-xueyuan Shu-xueyuan commented Jan 22, 2024

Fix UDP packet unable to calculate validity when carrying AH extension header

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 (using cd test && ./run_tests or tox)
  • If the PR is still not finished, please create a Draft Pull Request

fixes #xxx

Fix UDP packet unable to calculate validity when carrying AH extension header
Copy link

codecov bot commented Jan 22, 2024

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Project coverage is 49.29%. Comparing base (d71014a) to head (45aee45).
Report is 152 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (d71014a) and HEAD (45aee45). Click for more details.

HEAD has 10 uploads less than BASE | Flag | BASE (d71014a) | HEAD (45aee45) | |------|------|------| ||11|1|
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4227       +/-   ##
===========================================
- Coverage   81.77%   49.29%   -32.48%     
===========================================
  Files         331      343       +12     
  Lines       76721    77435      +714     
===========================================
- Hits        62736    38175    -24561     
- Misses      13985    39260    +25275     
Files Coverage Δ
scapy/layers/inet.py 23.74% <0.00%> (-46.88%) ⬇️

... and 273 files with indirect coverage changes

@guedou
Copy link
Member

guedou commented Jan 30, 2024

@Shu-xueyuan thanks for your PR. Could you share an example that triggers the issue that you are fixing?

@Shu-xueyuan
Copy link
Author

@Shu-xueyuan thanks for your PR. Could you share an example that triggers the issue that you are fixing?

fail pass @guedou I'm very glad that you can reply to me. When I use the official scapy library to construct a UDP message carrying Authentication Header, the Checksum of the message is illegal. Using my modified scapy library to construct the same message will not have this problem. The following is my process of calling scapy: originalPacket = Ether(**ETH2_dicts) / IPv6(**IPV6_dicts) / AH(**Ah_dicts) / UDP(**UDP_dicts).

@Shu-xueyuan
Copy link
Author

@Shu-xueyuan thanks for your PR. Could you share an example that triggers the issue that you are fixing?

@guedou This is the encapsulation format of AH in transport mode:
企业微信截图_17066847603282
Looking forward to your reply.

@gpotter2
Copy link
Member

gpotter2 commented Feb 4, 2024

Hi. This looks good, but you need to add tests in https://github.com/secdev/scapy/blob/master/test/scapy/layers/inet.uts to make sure that this does not regress. Thanks

@Shu-xueyuan Shu-xueyuan reopened this Feb 16, 2024
@Shu-xueyuan
Copy link
Author

@gpotter2 Hello, the test case has been submitted

@gpotter2 gpotter2 added this to the 2.6.0 milestone Mar 22, 2024
@Shu-xueyuan
Copy link
Author

@gpotter2 Hello, when will my changes be reviewed?

@polybassa
Copy link
Contributor

LGTM

polybassa
polybassa previously approved these changes Apr 16, 2024
@polybassa
Copy link
Contributor

Please fix the flake8 issues.

@gpotter2
Copy link
Member

gpotter2 commented Apr 17, 2024

I noted I still need to check when this PR really applies, and compare to what's already implemented in ipsec.py. I will review this more in depth eventually, sorry for the delay. There were some higher priority issues blocking for 2.6.0

@Shu-xueyuan
Copy link
Author

Thanks for your reply, I totally understand. I'll be happy to wait until you have time to review my edits. If there is anything you need further explanation or assistance from me, please feel free to let me know. I fully understand the high-priority issues encountered in version 2.6.0 and hope that the issues can be resolved smoothly. Thanks!

@Shu-xueyuan Shu-xueyuan reopened this Apr 17, 2024
@Shu-xueyuan
Copy link
Author

Please fix the flake8 issues.

@polybassa Thank you for your review, the issue has been resolved.

@gpotter2 gpotter2 removed this from the 2.6.0 milestone Apr 27, 2024
@gpotter2
Copy link
Member

gpotter2 commented Jun 22, 2024

Hi, sorry for the delay.

So I think that generally you should consider that AH is supported through the SecurityAssociation class only. I'm not sure if we want to support stacking AH() packets in the normal Scapy way, as I don't really see how those packets would be valid without the crypto that comes with it. What do you think @guedou @p-l- ?

This currently works fine for your case, and builds valid packets with the proper checksum:

>>> sa = SecurityAssociation(AH, spi=1)
>>> sa.encrypt(IP()/UDP()/b"aaa")

Crafting AH or ESP packets without using SecurityAssociation probably means using only 'null' ciphers, and I'm not sure if that's worth the extra code to support it in inet.py.

@gpotter2 gpotter2 added discussion and removed bug labels Jun 22, 2024
@gpotter2 gpotter2 changed the title Update inet.py (discussion) Build AH without SecurityAssociation Jun 22, 2024
@guedou
Copy link
Member

guedou commented Jun 25, 2024

@Shu-xueyuan could you describe the use case that you have in mind for these changes ?

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.

None yet

4 participants