Fix NTP Authenticator parsing for non-MD5 digest types#4918
Fix NTP Authenticator parsing for non-MD5 digest types#4918
Conversation
- Add XStrField import - Add _ntp_auth_tail_size() helper for dynamic MAC size detection - Update _NTPAuthenticatorPaddingField to use dynamic tail size - Change NTPAuthenticator.dgst from XStrFixedLenField to XStrField - Update NTPExtPacketListField.getfield() for dynamic tail detection - Add SHA384 (48-byte) to NTPHeader.guess_payload_class() Co-authored-by: guedou <11683796+guedou@users.noreply.github.com>
- Add SHA1 (24-byte) authenticator parsing test with round-trip verification - Add SHA256 (36-byte) authenticator parsing test with round-trip verification - Update existing MD5 authenticator test to reflect correct SHA1 parsing for 24-byte payloads - Update NTPControl test to expect SHA1 parsing for 24-byte authenticator data Co-authored-by: guedou <11683796+guedou@users.noreply.github.com>
…ents - Define named constants for MAC sizes (_NTP_AUTH_MD5_SIZE, _NTP_AUTH_SHA1_SIZE, etc.) - Update _ntp_auth_tail_size() to use constants instead of hardcoded values - Clarify test comments to explain SHA1 vs MD5 parsing interpretation Co-authored-by: guedou <11683796+guedou@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4918 +/- ##
==========================================
+ Coverage 80.10% 80.63% +0.53%
==========================================
Files 370 370
Lines 91727 91723 -4
==========================================
+ Hits 73477 73965 +488
+ Misses 18250 17758 -492
🚀 New features to boost your workflow:
|
|
@copilot fix the code health error, please. |
- Remove trailing whitespace on blank lines (W293) - Remove trailing whitespace at end of line (W291) - Add extra blank line before class definition (E302) - Move comment to separate line to fix line length (E501) Co-authored-by: guedou <11683796+guedou@users.noreply.github.com>
|
Same response as above - see comparison in previous comment. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot try again? |
Detailed comparison of PR #3821 vs Current PR: ArchitecturePR #3821:
Current PR:
Code ChangesPR #3821 modifies:
Current PR modifies:
Key Differences
Advantages of Current PR
|
scapy/layers/ntp.py
Outdated
| ############################################################################# | ||
|
|
||
|
|
||
| def _ntp_auth_tail_size(length): |
There was a problem hiding this comment.
@copilot This is useless, let the user enter a bad sized if they want to.
There was a problem hiding this comment.
Simplified in commit e757137. The function now just returns the length without validation, allowing any MAC size.
There was a problem hiding this comment.
Removed in commit 7ca3890. The function is completely removed and _NTPAuthenticatorPaddingField is simplified to not extract any padding. XStrField in dgst now handles all remaining bytes automatically.
test/scapy/layers/ntp.uts
Outdated
| = NTPAuthenticator - MD5 with padding (old test, updated for correct parsing) | ||
|
|
||
| # This packet has 24 bytes of authenticator data | ||
| # The old (incorrect) code interpreted this as: 4 padding + 4 key_id + 16 MD5 digest |
test/scapy/layers/ntp.uts
Outdated
| assert p.data == b'ntp.test.2.conf' | ||
| assert p.authenticator.key_id == 1 | ||
| assert bytes_hex(p.authenticator.dgst) == b'c9fb8abe3c605ffa36d218c3b7648923' | ||
| # After data padding to 4-byte alignment, there are 24 bytes for authenticator |
- Simplify _ntp_auth_tail_size() to not validate/restrict MAC sizes - Remove excessive explanatory comments in test file - Allow users to use any authenticator size without restriction Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
- Remove unnecessary _ntp_auth_tail_size() function entirely - Simplify _NTPAuthenticatorPaddingField to not extract any padding - XStrField in dgst now handles all remaining bytes automatically - Revert NTPExtPacketListField to use fixed _NTP_AUTH_MD5_TAIL_SIZE Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
- Remove unused MAC size constants (_NTP_AUTH_MD5_SIZE, etc.) - Remove extra blank line before XLEShortField class - Remove _NTPAuthenticatorPaddingField class entirely - Remove padding field from NTPAuthenticator (not needed with XStrField) Co-authored-by: gpotter2 <10530980+gpotter2@users.noreply.github.com>
Implementation Plan for NTP Authenticator Parsing Fix
Summary
Successfully fixed NTP Authenticator parsing to support multiple digest types (MD5, SHA1, SHA256, SHA384, SHA512) instead of being hardcoded to MD5's 16-byte digest size.
Changes:
NTPAuthenticator.dgstfromXStrFixedLenField(fixed 16-byte) toXStrField(variable-length, consumes all remaining bytes)_NTPAuthenticatorPaddingFieldclass and padding fieldNTPHeader.guess_payload_class()to include SHA384 (48-byte) digest supportThe key insight is that by using
XStrFieldfor the digest field, it automatically consumes all remaining bytes after the key_id field. This eliminates the need for any padding field or complex dynamic tail size detection, providing a much simpler and cleaner solution.Test Results:
Security Summary:
No security vulnerabilities detected by CodeQL analysis.
Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.