Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-LANG-SEC-063 --project .About This Rule
Understanding the vulnerability and how it is detected
Python's ftplib.FTP() class implements the FTP protocol, which transmits all data including login credentials (username and password), commands, and file contents in plaintext. FTP was designed in an era when network security was not a concern and has never supported encryption natively in its base form.
An attacker who can observe network traffic (on the same network segment, via ARP poisoning, or at any network hop between client and server) can capture FTP credentials and all transferred file contents.
Secure alternatives include: - ftplib.FTP_TLS(): FTP over TLS (FTPS/FTPES), which encrypts the control connection and can encrypt the data connection. Requires server support. - paramiko (SSH/SFTP): SFTP over SSH is generally more secure and widely supported. - HTTPS-based file transfer for web-accessible files.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Plaintext Credential Transmission
FTP LOGIN command transmits the username and password in plaintext. Any network observer can capture these credentials and use them to access the FTP server, modify files, exfiltrate data, or plant malicious files.
File Content Interception
All files transferred via FTP (uploads and downloads) are transmitted without encryption. Sensitive documents, configuration files, database backups, and any other file content is visible to network observers.
Command Injection via Plaintext Control Channel
FTP uses a separate control channel for commands. An attacker who can intercept and modify the control channel can inject arbitrary FTP commands, redirect file transfers to attacker-controlled locations, or delete files.
Passive Mode Data Connection Hijacking
In passive mode FTP, the server provides an IP and port for the data connection. An attacker with network access can intercept the passive mode response and replace the data connection endpoint, hijacking the file transfer.
How to Fix
Recommended remediation steps
- 1Replace ftplib.FTP() with ftplib.FTP_TLS() for encrypted FTP, and call ftp.prot_p() to enable TLS on the data connection as well as the control connection.
- 2Prefer SFTP (SSH File Transfer Protocol) via paramiko over FTPS for new implementations, as SSH key-based authentication is more secure than FTP passwords.
- 3If the FTP server does not support TLS, migrate the server to support FTPS or SFTP rather than accepting plaintext FTP.
- 4Never transmit credentials over plain FTP; use key-based authentication with SFTP or TLS certificates with FTPS.
- 5Consider HTTPS-based file transfer (S3, web API) as a modern alternative that avoids FTP protocol complexity entirely.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to ftplib.FTP() constructor in Python source code. All call sites are flagged since plain FTP always transmits credentials and data in plaintext. ftplib.FTP_TLS() is the secure alternative and is not flagged.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
HTTP Request Without TLS (requests library)
HTTP URLs in requests calls transmit data in plaintext without encryption. Use HTTPS URLs for sensitive data transmission.
telnetlib Usage Detected
telnetlib.Telnet() transmits all data including credentials in plaintext. Replace with SSH (paramiko) for remote command execution.
Insecure HTTP Connection via http.client
http.client.HTTPConnection transmits data in plaintext without encryption. Use HTTPSConnection for sensitive communications.
Frequently Asked Questions
Common questions about FTP Without TLS (ftplib.FTP)
New feature
Get these findings posted directly on your GitHub pull requests
The FTP Without TLS (ftplib.FTP) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.