-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Smtp server detection 1125 v2.0 #11125
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -961,6 +961,35 @@ static AppProto FTPUserProbingParser( | |
| return ALPROTO_FTP; | ||
| } | ||
|
|
||
| static AppProto FTPServerProbingParser( | ||
| Flow *f, uint8_t direction, const uint8_t *input, uint32_t len, uint8_t *rdir) | ||
| { | ||
| // another check for minimum length | ||
| if (len < 5) { | ||
| return ALPROTO_UNKNOWN; | ||
| } | ||
| // begins by 220 | ||
| if (input[0] != '2' || input[1] != '2' || input[2] != '0') { | ||
| return ALPROTO_FAILED; | ||
| } | ||
| // followed by space or hypen | ||
| if (input[3] != ' ' && input[3] != '-') { | ||
| return ALPROTO_FAILED; | ||
| } | ||
| AppProto r = ALPROTO_UNKNOWN; | ||
| if (f->alproto_ts == ALPROTO_FTP || (f->todstbytecnt > 4 && f->alproto_ts == ALPROTO_UNKNOWN)) { | ||
| // only validates FTP if client side was FTP | ||
| // or if client side is unknown despite having received bytes | ||
| r = ALPROTO_FTP; | ||
| } | ||
| for (uint32_t i = 4; i < len; i++) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok doing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably out of scope for this PR, but there is a rust memchr crate that claims some pretty good performance too IIRC |
||
| if (input[i] == '\n') { | ||
| return r; | ||
| } | ||
| } | ||
| return ALPROTO_UNKNOWN; | ||
| } | ||
|
|
||
| static int FTPRegisterPatternsForProtocolDetection(void) | ||
| { | ||
| if (AppLayerProtoDetectPMRegisterPatternCI( | ||
|
|
@@ -983,7 +1012,15 @@ static int FTPRegisterPatternsForProtocolDetection(void) | |
| IPPROTO_TCP, ALPROTO_FTP, "PORT ", 5, 0, STREAM_TOSERVER) < 0) { | ||
| return -1; | ||
| } | ||
|
|
||
| // Only check FTP on known ports as the banner has nothing special beyond | ||
| // the response code shared with SMTP. | ||
| if (!AppLayerProtoDetectPPParseConfPorts( | ||
| "tcp", IPPROTO_TCP, "ftp", ALPROTO_FTP, 0, 5, NULL, FTPServerProbingParser)) { | ||
| // STREAM_TOSERVER here means use 21 as flow destination port | ||
| // and NULL, FTPServerProbingParser means use probing parser to client | ||
| AppLayerProtoDetectPPRegister(IPPROTO_TCP, "21", ALPROTO_FTP, 0, 5, STREAM_TOSERVER, NULL, | ||
| FTPServerProbingParser); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
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 think this supposed to use a different naming style now, right @jasonish?
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.
Correct, changing