Java and Python FTP attacks can punch holes through firewalls

Hackers can trick Java and Python applications to execute rogue FTP commands that would open ports in firewalls

The Java and Python runtimes fail to properly validate FTP URLs, which can potentially allow attackers to punch holes through firewalls to access local networks.

On Saturday, security researcher Alexander Klink disclosed an interesting attack where exploiting an XXE (XML External Entity) vulnerability in a Java application can be used to send emails.

XXE vulnerabilities can be exploited by tricking applications to parse specially crafted XML files that would force the XML parser to disclose sensitive information such as files, directory listings, or even information about processes running on the server.

Klink showed that the same type of vulnerabilities can be used to trick the Java runtime to initiate FTP connections to remote servers by feeding it FTP URLs in the form of ftp://user:password@host:port/file.ext.

However, it turns out that the built-in implementation of the FTP client in Java doesn't filter out special CR (carriage return) and LF (line feed) characters from URLs and actually interprets them.

By inserting such characters in the user or password portions of an FTP URL, the Java FTP client can be tricked to execute rogue commands and can even be tricked to speak SMTP (Simple Mail Transfer Protocol) because the syntax for SMTP and FTP is similar.

Klink showed that by exploiting an XXE vulnerability and this quirk in Java's FTP client implementation, an attacker could force a Java application to send emails to an SMTP server.

"This attack is particularly interesting in a scenario where you can reach an (unrestricted, maybe not even spam- or malware-filtering) internal mail server from the machine doing the XML parsing," Klink said in a blog post.

After seeing Klink's exploit, Timothy Morgan, a researcher with Blindspot Security, decided to disclose a similar attack that works against both Java's and Python's FTP implementations. But his attack is more serious because it can be used to punch holes through firewalls.

Morgan calls the attack "FTP protocol stream injection via malicious URLs" and it also involves injecting rogue FTP commands by exploiting the absence of CRLF filtering.

However, instead of injecting SMTP commands, Morgan abuses the FTP PORT command to trick the client into opening a data channel to a remote FTP server on a specific TCP port.

As the researcher points out, many Linux-based stateful packet inspection (SPI) firewalls, including commercial ones, support the classic mode of FTP translation and will automatically open a TCP port and forward it to an FTP client's LAN IP if they detect a PORT command in FTP traffic originating from that client.

This attack vector has been known for many years, which is why the developers of conntrack, a Linux set of tools that most firewalls use, have added an additional check. A port will only be opened if the PORT command appears at the very beginning of a TCP packet, to ensure that the client actually sent the command.

This poses a would-be attacker with two problems: first, discover the client's internal IP address in order to be able to spoof a PORT command, and then, align the TCP packets between the client and the server so that the spoofed PORT command falls at the beginning of a packet.

Morgan has found a way to do both of these things through his FTP protocol stream injection attack and claims to have developed a proof-of-concept exploit that he doesn't plan to release publicly until Oracle and Python correct their FTP client code.

"The entire attack (including the request used to determine the victim's internal IP) is typically accomplished with just three SSRF (Server Side Request Forgery) attacks to open up one TCP port," he said in a blog post Monday. "Each additional SSRF attack could open up one additional TCP port."

There are multiple ways to exploit this issue, including using it against users with Java installed on their computers. Users don't even need to execute a malicious Java applet, because the exploit can be delivered through a Java Web Start application.

"If a desktop user could be convinced to visit a malicious website while Java is installed, even if Java applets are disabled, they could still trigger Java Web Start to parse a JNLP file," Morgan said. "These files could contain malicious FTP URLs which trigger this bug."

Attackers could also target servers where Java applications run by abusing a man-in-the-middle position on the network or by exploiting SSRF or XXE vulnerabilities in those applications.

Morgan said he tested this attack against a custom Linux firewall running a recent kernel, as well as against firewalls from Palo Alto Networks and Cisco Systems that proved to be vulnerable under default settings.

"While testing of commercial firewalls has been very limited at this point, it seems likely that a significant percentage of production firewalls in the world are susceptible to attack through FTP protocol stream injections," he said.

The Java and Python developers have been notified of this problem, but until they fix their FTP client implementations, the researcher advises firewall vendors to disable classic mode FTP translation by default.

Users should uninstall Java from their systems, or at least disable the browser plug-in and disassociate the .jnlp file extension from the Java Web Start binary. Meanwhile, Java and Python applications should be audited for SSRF and XXE flaws. However, XML parsing in Java is currently vulnerable by default, making XXE vulnerabilities very common on that platform, Morgan said.

Join the newsletter!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Lucian Constantin

IDG News Service
Show Comments

Cool Tech

SanDisk MicroSDXC™ for Nintendo® Switch™

Learn more >

Breitling Superocean Heritage Chronographe 44

Learn more >

Toys for Boys

Family Friendly

Panasonic 4K UHD Blu-Ray Player and Full HD Recorder with Netflix - UBT1GL-K

Learn more >

Stocking Stuffer

Razer DeathAdder Expert Ergonomic Gaming Mouse

Learn more >

Christmas Gift Guide

Click for more ›

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Walid Mikhael

Brother QL-820NWB Professional Label Printer

It’s easy to set up, it’s compact and quiet when printing and to top if off, the print quality is excellent. This is hands down the best printer I’ve used for printing labels.

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

George Khoury

Sharp PN-40TC1 Huddle Board

The biggest perks for me would be that it comes with easy to use and comprehensive programs that make the collaboration process a whole lot more intuitive and organic

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?