Thank you, patch has been merged! On 11/3/26 14:08, Pratik Farkase wrote:
When using passive mode, ftp_pasv() took the address and port out of the server's 227 response and opened the data connection there without checking that the advertised address matched the peer of the control connection. A malicious or compromised FTP server could therefore redirect Wget's data connection to an arbitrary host of its choosing -- for example an internal service unreachable from the attacker directly -- a server-side request forgery.ftp_pasv() now records the control connection's peer address and rejects the 227 response (FTPINVPASV, "Cannot parse PASV response") when the advertised address does not match it. This test serves the data socket on a spoofed loopback address (127.0.0.2) and advertises that address in the 227 reply, while the control connection's peer is 127.0.0.1. With the address check in place login proceeds but the PASV response is refused, the transfer fails and nothing is downloaded; a vulnerable Wget instead connects to 127.0.0.2 and downloads the file. Asserting the failed exit code and the absence of a downloaded file separates a fixed Wget from a vulnerable one. * tests/FTPServer.pm: Add the pasv_spoof_addr server behavior, binding the passive data socket on a chosen loopback address and advertising it in the 227 PASV reply. * tests/Test-ftp-pasv-addr-mismatch.px: New test for the PASV address check. * tests/Makefile.am (PX_TESTS): Add Test-ftp-pasv-addr-mismatch.px. Fixes CVE-2026-15146 Copyright-paperwork-exempt: Yes Signed-off-by: Pratik Farkase <[email protected]> --- tests/FTPServer.pm | 42 +++++++++++++++ tests/Makefile.am | 1 + tests/Test-ftp-pasv-addr-mismatch.px | 77 ++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 tests/Test-ftp-pasv-addr-mismatch.px diff --git a/tests/FTPServer.pm b/tests/FTPServer.pm index 51ee7fb..bf32e69 100644 --- a/tests/FTPServer.pm +++ b/tests/FTPServer.pm @@ -763,6 +763,48 @@ sub run next; }+ # Answer PASV with a 227 response that advertises an+ # address different from the control connection's peer + # (127.0.0.1). The passive data socket is bound to that + # same spoofed loopback address (127.0.0.2), so a Wget that + # trusts the server-supplied address connects to it and the + # transfer succeeds, while a Wget that validates the address + # refuses the response. Used by + # Test-ftp-pasv-addr-mismatch.px to exercise the + # CVE-2026-15146 address check in ftp_pasv() (SSRF). + # This behavior was AI-generated (Kiro CLI). + if (defined($self->{_server_behavior}{pasv_spoof_addr}) + && $cmd eq 'PASV') + { + my $spoofdot = $self->{_server_behavior}{pasv_spoof_addr}; + (my $spoofip = $spoofdot) =~ s/,/./g; + "0" =~ /(0)/; # IO::Socket::INET bug workaround. + my $sock = IO::Socket::INET->new( + LocalHost => $spoofip, + LocalPort => '0', + Listen => 1, + Reuse => 1, + Proto => 'tcp', + Type => SOCK_STREAM + ); + unless ($sock) + { + print {$conn->{socket}} + "550 Can't open a listening socket.\r\n"; + next; + } + $conn->{passive} = 1; + $conn->{passive_socket} = $sock; + my $sockport = $sock->sockport; + my $p1 = int($sockport / 256); + my $p2 = $sockport % 256; + $conn->{state} = $_connection_states{TWOSOCKS}; + # Advertise the spoofed address, not the real peer. + print {$conn->{socket}} + "227 Entering Passive Mode ($spoofdot,$p1,$p2)\r\n"; + next; + } + # Run the command. &{$command_table->{$cmd}}($conn, $cmd, $rest); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 002cc76..492bb20 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -56,6 +56,7 @@ PX_TESTS = \ Test-ftp-dir.px \ Test-ftp-pasv-fail.px \ Test-ftp-opie-seq.px \ + Test-ftp-pasv-addr-mismatch.px \ Test-ftp-bad-list.px \ Test-ftp-recursive.px \ Test-ftp-iri.px \ diff --git a/tests/Test-ftp-pasv-addr-mismatch.px b/tests/Test-ftp-pasv-addr-mismatch.px new file mode 100644 index 0000000..d47e2a2 --- /dev/null +++ b/tests/Test-ftp-pasv-addr-mismatch.px @@ -0,0 +1,77 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use FTPTest; + +# Regression test for CVE-2026-15146. +# +# When using passive mode, ftp_pasv() took the IP address and port out of +# the server's 227 response and connected the data connection there, +# without checking that the advertised address matched the peer of the +# control connection. A malicious or compromised FTP server could +# therefore point Wget's data connection at an arbitrary host of its +# choosing -- for example an internal service the attacker cannot reach +# directly -- a server-side request forgery. +# +# ftp_pasv() now records the control connection's peer address and +# rejects the 227 response (FTPINVPASV, "Cannot parse PASV response") +# when the advertised address does not match it. The data connection is +# never opened to the spoofed host and the download fails. +# +# The server below opens a genuine passive socket but advertises it as +# 127.0.0.2 in the 227 reply, while the control connection's peer is +# 127.0.0.1. With the address check in place Wget refuses the response, +# so the transfer fails and nothing is downloaded. A vulnerable Wget +# instead trusts the spoofed address and tries to open the data +# connection to 127.0.0.2. Asserting the refusal (failed exit code, no +# file downloaded) is what separates a fixed Wget from a vulnerable one. +# + +############################################################################### + +my $afile = <<EOF; +Some text. +EOF + +$afile =~ s/\n/\r\n/g; + +# code, msg, headers, content +my %urls = ( + '/afile.txt' => { + content => $afile, + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --tries=1 ftp://localhost:{{port}}/afile.txt"; + +# The server opens its passive data socket on 127.0.0.2 and advertises +# that same address in the 227 reply, while the control connection's peer +# is 127.0.0.1. With the fix, ftp_pasv() rejects the mismatched address +# ("Cannot parse PASV response") before opening any data connection, so +# the retrieval fails and Wget exits 4 (WGET_EXIT_NETWORK_FAIL) once the +# single attempt is exhausted; --tries=1 keeps that deterministic. A +# vulnerable Wget instead trusts the spoofed address, connects to +# 127.0.0.2 where the data socket really listens, and downloads the file +# (exit 0) -- demonstrating the SSRF. +my $expected_error_code = 4; + +# With the fix the PASV response is refused before any transfer, so +# nothing is downloaded. A vulnerable Wget would have written afile.txt. +my %expected_downloaded_files = (); + +############################################################################### + +my $the_test = FTPTest->new ( + # pasv_spoof_addr makes the 227 PASV reply + # advertise 127.0.0.2 instead of the real + # control peer 127.0.0.1. + server_behavior => {pasv_spoof_addr => '127,0,0,2'}, + input => \%urls, + cmdline => $cmdline, + errcode => $expected_error_code, + output => \%expected_downloaded_files); +exit $the_test->run(); + +# vim: et ts=4 sw=4
OpenPGP_signature.asc
Description: OpenPGP digital signature
