|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-06 19:19 UTC] vhu at iki dot fi
Description:
------------
ftps:// opendir wrapper seems to be vulnerable to protocol downgrade attack.
When user requests ftps:// connection, php_ftp_fopen_connect() in ext/standard/ftp_fopen_wrapper.c first attempts to use AUTH TLS followed by attempt to use AUTH SSL if that follows. If FTP server, or attacker, responds with status codes other than 234 for AUTH TLS and 334 for AUTH SSL, wrapper will silently downgrade the connection to regular FTP. Relevant code:
if (use_ssl) {
/* send the AUTH TLS request name */
php_stream_write_string(stream, "AUTH TLS\r\n");
/* get the response */
result = GET_FTP_RESULT(stream);
if (result != 234) {
/* AUTH TLS not supported try AUTH SSL */
php_stream_write_string(stream, "AUTH SSL\r\n");
/* get the response */
result = GET_FTP_RESULT(stream);
if (result != 334) {
use_ssl = 0;
} else {
Test script:
---------------
Execute against server that doesn't support ftps.
$dir=opendir('ftps://ftp.funet.fi/');
var_dump($dir);
Expected result:
----------------
bool(false)
TCP session between the client and server:
S: 220---------- Welcome to Pure-FTPd ----------
C: AUTH TLS
S: 500 This security scheme is not implemented
C: AUTH SSL
S: 500 This security scheme is not implemented
(connection terminated)
Actual result:
--------------
resource(%d) of type (stream)
TCP session between the client and server:
S: 220---------- Welcome to Pure-FTPd ----------
C: AUTH TLS
S: 500 This security scheme is not implemented
C: AUTH SSL
S: 500 This security scheme is not implemented
C: USER test
S: 331-Welcome to the FUNET anonymous ftp archive
C: PASS test
S: 230 Any password will work
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 09:00:01 2025 UTC |
Unfortunately can't add patch to private bug, so here it is as a comment: diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index bfb1631..5bffa47 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -188,7 +188,8 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char /* get the response */ result = GET_FTP_RESULT(stream); if (result != 334) { - use_ssl = 0; + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Server doesn't support FTPS."); + goto connect_errexit; } else { /* we must reuse the old SSL session id */ /* if we talk to an old ftpd-ssl */