Building an anonymous FTP scanner with python

Building an anonymous FTP scanner with python

FTP Anonymous Login Script

This Python script attempts anonymous login to an FTP server using the ftplib module.

1. Importing the Required Module:

Python
import ftplib

The script imports the ftplib module to perform FTP operations.

2. FTP Anonymous Login Function:

Python
def anonymousLogin(hostname):
    try:
        ftp = ftplib.FTP(hostname)
        response = ftp.login('anonymous', 'anonymous')
        print(response)
        if "230 Anonymous access granted" in response:
            print('\n[*] ' + str(hostname) + ' FTP Anonymous Login Succeeded.')
            print(ftp.getwelcome())
            ftp.dir()
    except Exception as e:
        print(str(e))
        print('\n[-] ' + str(hostname) + ' FTP Anonymous Login Failed.')

The anonymousLogin function attempts to log in to the FTP server with the username “anonymous” and password “anonymous.” If the login is successful, it prints a success message along with the server welcome message and directory listing.

3. Main Function:

Python
hostname = 'ftp.be.debian.org'
anonymousLogin(hostname)

The script then calls the anonymousLogin function with the target FTP server’s hostname, in this case, ‘ftp.be.debian.org’.

Python
#!/usr/bin/env python3

import ftplib

def anonymousLogin(hostname):
    try:
        ftp = ftplib.FTP(hostname)
        response = ftp.login('anonymous', 'anonymous')
        print(response)
        if "230 Anonymous access granted" in response:       
            print('\n[*] ' + str(hostname) +' FTP Anonymous Login Succeeded.')
            print(ftp.getwelcome())
            ftp.dir()
    except Exception as e:
        print(str(e))
        print('\n[-] ' + str(hostname) +' FTP Anonymous Login Failed.')

hostname = 'ftp.be.debian.org'
anonymousLogin(hostname)

Note:

  • This script assumes that the target FTP server allows anonymous logins.
  • Ensure that you have permission to perform anonymous logins on the specified FTP server.
  • Always comply with the applicable laws and ethical guidelines when performing security testing.

FTP Connection and Directory Listing Script

This Python script connects to an FTP server anonymously using the ftplib module and lists the contents of a specified directory.

1. Importing the Required Module:

Python
import ftplib

The script imports the ftplib module for performing FTP operations.

2. FTP Connection and Directory Listing Function:

Python
def check_anonymous_connection(host, path):
    with ftplib.FTP(host, user="anonymous") as connection:
        print("Welcome to ftp server", connection.getwelcome())
        for name, details in connection.mlsd(path):
            print(name, details['type'], details.get('size'))

The check_anonymous_connection function connects to the FTP server specified by host using anonymous credentials. It then lists the contents of the specified path using the mlsd method, which returns a directory listing in machine-readable format.

3. Main Function:

Python
if __name__ == '__main__':
    FTP_SERVER_URL = 'ftp.be.debian.org'
    DOWNLOAD_DIR_PATH = '/pub/linux/kernel/v5.x/'
    check_anonymous_connection(FTP_SERVER_URL, DOWNLOAD_DIR_PATH)

The script calls the check_anonymous_connection function with the FTP server URL (‘ftp.be.debian.org’) and the target directory path (‘/pub/linux/kernel/v5.x/’).

Python
#!/usr/bin/env python3

import ftplib

FTP_SERVER_URL = 'ftp.be.debian.org'
DOWNLOAD_DIR_PATH = '/pub/linux/kernel/v5.x/'

def check_anonymous_connection(host, path):
    with ftplib.FTP(host, user="anonymous") as connection:
        print( "Welcome to ftp server ", connection.getwelcome())
        for name, details in connection.mlsd(path):
            print( name, details['type'], details.get('size') )

if __name__ == '__main__':
    check_anonymous_connection(FTP_SERVER_URL,DOWNLOAD_DIR_PATH)
  • Ensure that the specified FTP server allows anonymous logins.
  • Always comply with applicable laws and ethical guidelines when interacting with external systems.
Total
0
Shares

Leave a Reply

Previous Post
Using ftplib to brute-force FTP user credentials

Using ftplib to brute-force FTP user credentials

Next Post
Connecting with SSH servers with paramiko and pysftp

Connecting with SSH servers with paramiko and pysftp

Related Posts