Skip to content

Commit ed593ac

Browse files
committed
ftp: use parser data direction in ftpdata
The ftpdata_command keyword assumed a fixed relationship between the FTP command and the data-flow direction: RETR was expected to be to-client and STOR to-server. That matches passive FTP, but active FTP reverses the TCP data flow because the server opens the connection from port 20. In an active download, the RETR payload is therefore seen by Suricata in the flow's to-server direction. For firewall rules this caused an active RETR rule on ftp-data:request_started to miss. The firewall then applied the default app policy to the FTP-data transaction, dropped the flow, and prevented fileinfo from being logged. Use the direction that the FTP parser stored in FtpDataState from the control-channel expectation instead of deriving direction from the command. This preserves the command check while allowing active and passive data connections to match in their actual parser-established data direction.
1 parent 1614df0 commit ed593ac

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/detect-ftpdata.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ static int DetectFtpdataMatch(DetectEngineThreadCtx *det_ctx,
105105
if (ftp_state == NULL)
106106
return 0;
107107

108-
if (ftpcommandd->command == ftp_state->command) {
109-
/* Only match if the flow is in the good direction */
110-
if ((flags & STREAM_TOSERVER) && (ftpcommandd->command == FTP_COMMAND_RETR)) {
111-
return 0;
112-
} else if ((flags & STREAM_TOCLIENT) && (ftpcommandd->command == FTP_COMMAND_STOR)) {
113-
return 0;
114-
}
115-
return 1;
116-
}
108+
if (ftpcommandd->command != ftp_state->command)
109+
return 0;
117110

118-
return 0;
111+
/* Only match in the parser-established data direction. Active FTP
112+
* reverses the data flow, so RETR/STOR don't map to fixed flow
113+
* directions.
114+
*/
115+
if ((flags & ftp_state->direction) == 0)
116+
return 0;
117+
118+
return 1;
119119
}
120120

121121
/**

0 commit comments

Comments
 (0)