最近在Freebuf上看到有个人扫描了全球的ip地址,扫描出近80万可匿名登录的FTP服务器,下载下来后用python写了一个扫描文件列表的程序,不过效率比较慢,只当学习一下,没准会找到比较有意思的东西呢。
代码如下:
import ftplib
import threading
import time
import socket
def anonyLogin(ftpUrl,FileDest):
dirList = []
hostnames = open(ftpUrl, 'r')
OutPut = open(FileDest,'w+')
socket.setdefaulttimeout(4)
for line in hostnames:
hostname = line.strip('\n').strip('\r')
try:
ftp = ftplib.FTP(hostname)
ftp.login('anonymous')
print 'Succeed:'+str(hostname)
except Exception,e:continue
try:
dirList = ftp.nlst()
ftp.quit()
except Exception,e:
dirList = []
print str(e)
continue
if dirList != []:
print str(dirList)
OutPut.write(hostname + ':\n' + str(dirList) + '\n')
OutPut.close()
hostnames.close()
return
th = threading.Thread(target=anonyLogin,args=('openftp2.txt','openftp_file2.txt'))
th.start()
刚考试扫描的时候经常会出现卡死的情况,所以加了个socket连接默认时长socket.setdefaulttimeout(4),默认4秒没反应就跳过。