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 PC World newsletter!

Error: Please check your email address.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

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

Most Popular Reviews

Latest News Articles

Resources

PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?