#!/usr/bin/python
#coding=utf-8
import ftplib
'''
函数检查每个文件返回默认WEB 页面文件名
并将任何发现的默认 WEB 页面文件名添加到名为 retList 的列 表中。
完成迭代这些文件之后,函数将返回这个列表。
'''
def returnDefault(ftp):
try:
#nlst()方法获取目录下的文件
dirList=ftp.nlst()
except:
dirList=[]
print '[-] Could not list directory contents.'
print '[-] Skipping To Next Target.'
return
#返回命中文件列表
retList=[]
for fileName in dirList:
#lower()方法将文件名都转换为小写的形式
fn=fileName.lower()
if '.php' in fn or '.htm' in fn or '.asp' in fn:
print '[+] Found default page: ' + fileName
retList.append(fileName)
if len(retList)==0:
print '[-] Could not list directory contents.'
print '[-] Skipping To Next Target.'
return retList
def main():
while True:
host=raw_input('[*]Host >>> ')
if host=='bye' or host=='':
return
username = raw_input('[*]Username >>> ')
password = raw_input('[*]Password >>> ')
try:
ftp = ftplib.FTP(host)
ftp.login(username,password)
returnDefault(ftp)
except:
print '[-] Logon failed.'
if __name__ == '__main__':
main()
在FTP服务器上搜索指定文件
最新推荐文章于 2024-05-14 16:52:47 发布