issues2 Min Read

How to solve - Apache Ftp Client library is printing password on console

Gorav Singal

June 03, 2018

TL;DR

Apache FTPSClient logs credentials via its ProtocolCommandListener; remove or customize the listener to prevent username and password from being printed to console or logs.

How to solve - Apache Ftp Client library is printing password on console

Problem Statement

Apache provides lot of libraries for common utility functions for Java. One such common library is FTP library which provides better functionality to do FTP and FTPS calls. The reference to apache ftp library is: Apache Ftp

The problem comes while using FTPS. When developer uses login method of this library while authentication, it prints username and password in console, which is a huge security concern. Also, it exposes user credentials to logs. And, anyone can read those credentials if he or she has access to those logs.

Example

FTPClient ftpClient = null;
FTPSClient ftps = new FTPSClient("TLS", false);

//accept all for now
ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());

//verbose
ftps.addProtocolCommandListener(
  new PrintCommandListener( new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"), true)));

ftpClient = ftps;
//set connect timeout

ftpClient.setConnectTimeout(config.getConnectTimeout());
ftpClient.connect(host);
ftps.execPROT("P");
//SSL mode

if(ftpClient.login(username, password)) {
  //successfully login
}
else {
  //error condition
}

Example output:

``` 220-Isilon OneFS v7.2.1.1 220 AUTH TLS 234 Proceed with negotiation. PROT P 200 PROT now Private. USER USERNAME 331 Please specify the password. PASS PASSWORD ```

The Solution

For best security practices, we should not put passwords anywhere in logs. Lets come to the solution for this problem. We need to modify the code a little bit for this mess. See below code:
 FTPClient ftpClient = null;
 FTPSClient ftps = new FTPSClient("TLS", false);

 //accept all for now
 ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());

 //verbose
 ftps.addProtocolCommandListener(new ProtocolCommandListener() {
  @Override public void protocolReplyReceived(ProtocolCommandEvent arg0) { }
  @Override public void protocolCommandSent(ProtocolCommandEvent arg0) { }
 });

 ftpClient = ftps;

 //set connect timeout
 ftpClient.setConnectTimeout(config.getConnectTimeout());

 ftpClient.connect(host);

 ftps.execPROT("P");
 //SSL mode
 if(ftpClient.login(username, password)) {
   //successfully login
 }
 else {
   //error condition
 }

Result

Now, you will not see previous mess in console, or in logs.

Note: Above code is just to show the problem of showing passwords in concole. I will write a complete better implementation of ftp and ftps apis.

Share

Related Posts

Python SMTP Email Code - Sender Address Rejected - Not Owned By User

Python SMTP Email Code - Sender Address Rejected - Not Owned By User

Introduction In a normal email sending code from python, I’m getting following…

Understanding Zero-day Exploit of Log4j Security Vulnerability and Solution (CVE-2021-44228, CVE-2021-45046)

Understanding Zero-day Exploit of Log4j Security Vulnerability and Solution (CVE-2021-44228, CVE-2021-45046)

Introduction On 9th December 2021, an industry-wide vulnerability was discovered…

Dockerfile for building Python 3.9.2 and Openssl for FIPS

Dockerfile for building Python 3.9.2 and Openssl for FIPS

Introduction In previous posts, we saw how to build FIPS enabled Openssl, and…

How to Patch and Build Python 3.9.x for FIPS enabled Openssl

How to Patch and Build Python 3.9.x for FIPS enabled Openssl

Introduction In this post, we will see Python 3.9.x patch for FIPS enabled…

How to Patch and Build Python 3.7.9 for FIPS enabled Openssl

How to Patch and Build Python 3.7.9 for FIPS enabled Openssl

Introduction In this post, we will see Python 3.7.9 patch for FIPS enabled…

How to build FIPS enabled Openssl in docker

How to build FIPS enabled Openssl in docker

Introduction In this post, we will see how we can build FIPS enabled openssl in…

Latest Posts

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…

Security Ticketing and Incident Response

Security Ticketing and Incident Response

The worst time to figure out your incident response process is during an…

Security Mindset for Engineers — Think Like an Attacker

Security Mindset for Engineers — Think Like an Attacker

Most engineers think about security the way they think about flossing — they…

Secrets Management — Vault, SSM, and Secrets Manager

Secrets Management — Vault, SSM, and Secrets Manager

I’ve watched a production database get wiped because someone committed a root…

Penetration Testing Basics for Developers

Penetration Testing Basics for Developers

Most developers think of penetration testing as something a separate security…

OWASP Top 10 for Cloud Applications

OWASP Top 10 for Cloud Applications

The OWASP Top 10 was written for traditional web applications. But in the cloud…