Skip to content

FTP Client

Marcin Bury edited this page Oct 12, 2018 · 1 revision

FTP Client

Example exploit that utilises FTP communication as a client

from routersploit.core.exploit import *
from routersploit.core.ftp.ftp_client import FTPClient

class Exploit(FTPClient):
    __info__ = {
        "name": "Example FTP exploit",
        "description": "FTP exploit description",
        "authors": (
            "John Smith",
        ),
        "references": (
            "https://www.threat9.com",
        ),
        "devices": (
            "D-Link Devices",
        )
    }

target = OptIP("", "Target IPv4 or IPv6 address")
port = OptPort(21, "Target FTP port")

def run(self):
    ftp_client = self.ftp_create()
    if ftp_client.connect():
        if ftp_client.login("admin", "admin"):
             print_info("Default credentials: admin/admin")
        else:
             print_error("Exploit failed - could not authenticate to FTP server")

        ftp_client.close()
        return

    print_error("Exploit failed - could not connect to FTP server")

@mute
def check(self):
    return None

FTPClient Methods

FTPClient.ftp_create

Create FTPCli object

Params

Param Type Description Required
target str target FTP server ip address no, default=exploit.target
port int target FTP port no, default=exploit.port

Returns

Type Description
FTPCli FTPCli object that is used for communication

FTPCli Methods

FTPCli.Connect

Connect to FTP server

Params

param type description required
retries int number of retry attempts no, default=1

Returns

type description
bool True if connection was successful, False otherwise

Example:

ftp_client = self.ftp_create()
if ftp_client.connect():
    print_status("Connection was successful")

FTPCli.login

Login to FTP server

Params

Param Type Description Required
username str FTP account username yes
password str FTP account password yes

Returns

Type Description
bool True if login was successful, False otherwise

Example

ftp_client = self.ftp_create()

if ftp_client.connect():
    if ftp_client.login("admin", "admin"):
        print_success("Successful authentication to FTP server")

FTPCli.test_connect

Test connection to FTP server

Params

  • None

Returns

| Type | Description | | bool | True if connection was successful, False otherwise |

Example

ftp_client = self.ftp_create()
if ftp_client.test_connect():
    print_status("Remote FTP server is listening")

FTPCli.get_content

Get remote file from FTP server

Params

Param Type Description Required
remote_file str remote file name yes

Returns

Type Description
str remote file content

Example

ftp_client = self.ftp_create()

if ftp_client.connect():
    print_status("Connection to FTP server was successful")

    response = ftp_client.get_content("/etc/passwd")
    if response:
         print_status("Downloaded /etc/passwd from remote server")
         print_info(response)

FTPCli.close

Close FTP connection

Params

  • None

Returns

Type Description
bool True if closing connection was successful, False otherwise

Example

ftp_client = self.ftp_create()

if ftp_client.connect():
    print_status("Start to close connection")
    ftp_client.close()