From: Philippe Antoine Date: Thu, 2 Feb 2023 10:03:56 +0000 (+0100) Subject: ftp: protocol detection avoiding FP on POP3 X-Git-Tag: suricata-8.0.0-beta1~1302 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2c39fc87bcd62eaf2c419b6e0e5d91872ced704;p=thirdparty%2Fsuricata.git ftp: protocol detection avoiding FP on POP3 --- diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index d1db0d4ef0..d2777198ab 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -951,6 +951,15 @@ static int FTPGetAlstateProgress(void *vtx, uint8_t direction) return FTP_STATE_FINISHED; } +static AppProto FTPUserProbingParser( + Flow *f, uint8_t direction, const uint8_t *input, uint32_t len, uint8_t *rdir) +{ + if (f->alproto_tc == ALPROTO_POP3) { + // POP traffic begins by same "USER" pattern as FTP + return ALPROTO_FAILED; + } + return ALPROTO_FTP; +} static int FTPRegisterPatternsForProtocolDetection(void) { @@ -962,8 +971,8 @@ static int FTPRegisterPatternsForProtocolDetection(void) IPPROTO_TCP, ALPROTO_FTP, "FEAT", 4, 0, STREAM_TOSERVER) < 0) { return -1; } - if (AppLayerProtoDetectPMRegisterPatternCI( - IPPROTO_TCP, ALPROTO_FTP, "USER ", 5, 0, STREAM_TOSERVER) < 0) { + if (AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_FTP, "USER ", 5, 0, + STREAM_TOSERVER, FTPUserProbingParser, 5, 5) < 0) { return -1; } if (AppLayerProtoDetectPMRegisterPatternCI(