The Java sandbox for applets and stateful firewalls interact in a surprising way. As a result, external hosts can initiate TCP connections to supposedly protected network services.
This is a passive attack. The attacker must lure the victim to a carefully crafted web page. The victim's web browser must download and execute the embedded Java applet. The victim's computer must offer some vulnerable networking service, and a stateful firewall must prevent access to this service from the Internet.
An attacker can gain access to potentially vulnerable network services which are located behind firewall and/or NAT devices, so that direct access is impossible.
This is a passive vulnerability which can only be used as a stepstone for further attacks. As a result, the risk posed by this vulnerability alone is fairly low.
The attack is carried out as follows.
The attacker creates a specifically crafted web site.
She lures the victim to visit this web site.
The victim's browser downloads the applet and begins to run it.
A FTP server on the same machine that hosts the originating web site answers.
The applet continues to pose as an FTP client, logs in and issues an FTP
PORT command, which prepares an active FTP connection. The TCP port specified in the command refers to some existing TCP service, such as 445/TCP (SMB over TCP) or 1433/TCP (Microsoft SQL Server, MSDE). This port is chosen by the attacker.
The firewall between the attacker and the victim recognizes this command and prepares to open a second connection for the FTP data transfer.
The applet issues a FTP command which requests the data transfer, for example a
The attacker uses her server to initiate a TCP connection to the port indicated in the
PORT on the victim host. The firewall passes through the connection, assuming that it is a legitimate FTP data transfer.
This attack exploits the fact that the Java security model for applet assumes that arbitrary TCP connections back to the server pose no risks. However, the presence of stateful firewalls or NAT devices with heuristic FTP protocol modules between the involved hosts invalidates this assumption because TCP connections back to the originating servers do have side effects.
This is not an error in the Java implementation or in the firewall implementation. Both programs implement their respective specifications. Even the specifications themselves are not inherently flawed. Only the combination of these two components creates a vulnerable configuration. This stresses an important point about secure systems: Security does not compose, and classic divide-and-conquer approaches do not necessarily result in complete systems which are secure.
The attack differs from previous attacks using HTTP
POST requests to ports such as 21/FTP (see Mikael Olsson, Extending the FTP "ALG" vulnerability to any FTP client, March 2000). Such attacks could be detected by the firewall and stopped. In contrast, the Java applet could implement a fully-compliant FTP client, and the firewall cannot tell whether an FTP data transfer was initiated by a rogue Java applet or a legitimate FTP client controlled by the user.
However, this issue has been previously described in Phrack's issue 60 (Linenoise: Java Tears down the Firewall, December 2002).
Use clients that do not support active client such as Java applets.
In firewalls, do not use heuristic approaches to stateful filtering. Complex protocols should be handled by application layer gateways that actually understand the protocols they are letting through.
Note that in principle, this vulnerability is not specific to Java or FTP protocol helpers (see below). A more general approach to eradicate this problem is therefore necessary.
A simple TCP server which emulates FTP and a corresponding Java applet is provided.
For convenience, the TCP port to which access from the web/FTP server is provided can be configured on the client. In a real attack scenario, this port would be chosen by the attacker.
Some questions need further examination.
Other implementations of mobile code might be used to carry out the attack. For example, it could be possible that Flash objects can achieve the same effect.
The vulnerability is not inherently FTP-related. FTP is used here because its active mode is widely used because it is the default mode in a widely-used web browser, and stateful filters usually implement heuristics to handle such FTP data transfers. Other candidate protocols are IRC DCC, Sun and DCE RPC, and in particular H.323 and SIP.
We only tested one firewalling implementation (a custom-compiled Linux 2.6 kernel and an OpenWRT Linux kernel, both with NAT enabled). Other firewall implementations might enforce further restriction and restrict the data flow on the FTP data connection, which slightly mitigates the impact of this vulnerability.
Maybe it is possible to introduce a method by which Java virtual machines can mark outgoing connections initiated by untrusted applets. Even though the protocol described in RFC 3514 could be used for this purpose, significant code changes are needed, and it is not clear if this vulnerability is worth the complexity of such a solution.
Bastian Blank wrote the Java applet which demonstrates this exploitation technology. The applet contains source code copied from the GNU Classpath project.
2005-07-30 22:00: published
2005-08-01: Added link to a description to the HTTP GET/POST issue. Acknowledge prior art.
2012-02-27: Update external links.