logo

Use of Insecure Channel - FTP in Applications - Elixir


Need

Secure transmission of customer information


Context

  1. Usage of Elixir (v1.10+) for building scalable and fault-tolerant applications
  2. Usage of Plug for request handling
  3. Usage of Phoenix framework for building scalable web applications
  4. Usage of ftp module for FTP communication

Description

Insecure Code Example

{:ok, pid} = :ftp.open('ftp.example.com', [user: 'username', password: 'password'])
:ftp.send_cmd(pid, 'RETR somefile.txt')

This code is vulnerable because it uses the FTP protocol to transmit customer information which does not use encryption. This means that the data can be easily intercepted and read in plain text during transit, which could potentially lead to unauthorized access or data leakage.

Steps

  1. Replace FTP (File Transfer Protocol) with SFTP (SSH File Transfer Protocol) for secure file transfer.
  2. Use the :ssh_sftp module in Elixir for SFTP communication.
  3. Make sure to include the necessary SSL certificate configurations for secure SFTP communication.

Secure Code Example

{:ok, conn} = :ssh.connect('sftp.example.com', 22, [user: 'username', password: 'password'])
{:ok, channel} = :ssh_sftp.start_channel(conn)
:ssh_sftp.download(channel, '/remote/path/to/somefile.txt', '/local/path/to/somefile.txt')

This secure code example uses the SFTP protocol for file transfer which uses encryption to secure the data in transit. This ensures that even if the data is intercepted, it cannot be read in plain text.


References

  • 148 - Use of Insecure Channel - FTP in Applications

  • Last updated

    2023/09/18