-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Use existing TCP opts in p0f_impersonate #1023
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
% Tests for Scapy's p0f module. | ||
|
||
~ p0f | ||
|
||
|
||
############ | ||
############ | ||
+ Basic p0f module tests | ||
|
||
= Module loading | ||
load_module('p0f') | ||
|
||
|
||
############ | ||
############ | ||
+ Tests for p0f_impersonate | ||
|
||
# XXX: a lot of pieces of p0f_impersonate don't have tests yet. | ||
|
||
= Impersonate when window size must be multiple of some integer | ||
sig = ('%467', 64, 1, 60, 'M*,W*', '.', 'Phony Sys', '1.0') | ||
pkt = p0f_impersonate(IP()/TCP(), signature=sig) | ||
assert pkt.payload.window % 467 == 0 | ||
|
||
= Handle unusual flags ("F") quirk | ||
sig = ('1024', 64, 0, 60, 'W*', 'F', 'Phony Sys', '1.0') | ||
pkt = p0f_impersonate(IP()/TCP(), signature=sig) | ||
assert (pkt.payload.flags & 40) in (8, 32, 40) | ||
|
||
= Use valid option values from original packet | ||
sig = ('S4', 64, 1, 60, 'M*,W*,T', '.', 'Phony Sys', '1.0') | ||
opts = [('MSS', 1400), ('WScale', 3), ('Timestamp', (97256, 0))] | ||
pkt = p0f_impersonate(IP()/TCP(options=opts), signature=sig) | ||
assert pkt.payload.options == opts | ||
|
||
= Use valid option values when multiples required | ||
sig = ('S4', 64, 1, 60, 'M%37,W%19', '.', 'Phony Sys', '1.0') | ||
opts = [('MSS', 37*15), ('WScale', 19*12)] | ||
pkt = p0f_impersonate(IP()/TCP(options=opts), signature=sig) | ||
assert pkt.payload.options == opts | ||
|
||
= Discard non-multiple option values when multiples required | ||
sig = ('S4', 64, 1, 60, 'M%37,W%19', '.', 'Phony Sys', '1.0') | ||
opts = [('MSS', 37*15 + 1), ('WScale', 19*12 + 1)] | ||
pkt = p0f_impersonate(IP()/TCP(options=opts), signature=sig) | ||
assert pkt.payload.options[0][1] % 37 == 0 | ||
assert pkt.payload.options[1][1] % 19 == 0 | ||
|
||
= Discard bad timestamp values | ||
sig = ('S4', 64, 1, 60, 'M*,T', '.', 'Phony Sys', '1.0') | ||
opts = [('Timestamp', (0, 1000))] | ||
pkt = p0f_impersonate(IP()/TCP(options=opts), signature=sig) | ||
# since option is "T" and not "T0": | ||
assert pkt.payload.options[1][1][0] > 0 | ||
# since T quirk is not present: | ||
assert pkt.payload.options[1][1][1] == 0 | ||
|
||
= Discard 2nd timestamp of 0 if "T" quirk is present | ||
sig = ('S4', 64, 1, 60, 'M*,T', 'T', 'Phony Sys', '1.0') | ||
opts = [('Timestamp', (54321, 0))] | ||
pkt = p0f_impersonate(IP()/TCP(options=opts), signature=sig) | ||
assert pkt.payload.options[1][1][1] > 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but shouldn't we always set
ts_a = ts_hint[0]
whents_hint[0] and 0 < ts_hint[0] < 2**32
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean instead of setting
ts_a
touptime
when uptime is set?To me it seems more intuitive to use the value explicitly passed as an argument (
uptime
), rather than overriding it with the original packet's timestamp. If the caller wanted to use the value in the original packet, I wouldn't expect them to call the function withuptime=x
.Also this way the behavior is more consistent with the way it was before these changes. The first timestamp will be equal to uptime if uptime was passed, as before. An alternative if we aren't worried about consistency might be remove the
uptime
argument, since people can just set the timestamp in the original packet.But for now I've kept it the way I had it. I could definitely be wrong, though, so please let me know if you do prefer it the other way.