Python编写合并字典并实现敏感目录的小脚本
作者:不成大佬不改名 发布时间:2023-05-28 18:36:29
标签:Python,合并字典,敏感目录
0x00 起因
接触网安快一年了,爱收集一些字典啊敏感目录文件啊什么的。收集多了难免有重复,并且有的也需要合并使用方便。自己就写了一个小小的脚步用来完成这个目的。
0x01 代码
第一次发表文章,希望大家多提意见。抱拳了!
代码我就贴出来了
import osimport time
import argparse
import optparse
def Time(n,p):
pat_time = p-n
minute = pat_time/60
hour = minute/60
print(int(hour),'小时',int(minute%60),'分钟',int(pat_time%60),'秒')
def __O__(path): #遍历目录,包括目录里的子目录
f = os.listdir(path) #查看路径下所有文件及目录
D = open('D.txt','w')
F = open('F.txt','w')
for i in f:
fil = os.path.join(path,i) #dir是绝对路径
if os.path.isdir(fil): #如果fil是目录加入到D里
D.write(fil)
__O__(fil) #继续执行当前函数
if os.path.isfile(fil): #如果是文件,加入到F里
F.write(fil)
D.close()
F.close()
def type_txt(file,path): #传入路径,文件名(列表)
try:
n = time.time()
print(' 准备执行!')
path_list = [] #存放需要打开的文件
di = {}
date_list = []
dict_li = ['new_php.txt', 'new_asp.txt', 'new_aspx.txt', 'new_jsp.txt', 'new_dir.txt', 'new_mdb.txt',] #合并的字典列表
for i in dict_li:
di = []
for h in file: #合并给的路径及文件名
fn = os.path.join(path, h)
path_list.append(fn)
for j in path_list: #循环需要打开的文件列表
print(' 文件为:',j)
with open(j, 'r') as f:
date = f.readlines()
print(' -t 当前执行文件为: ' + j,'数量:',len(date))
for i in date: #读取每一行
af, aq = os.path.splitext(i) #分裂成路径及后缀名
aq = aq.lower()
if i != '\n': #如果没有换行符会加上
if '\n' not in i:
i = i + '\n'
aq+='\n'
if aq == '.php\n' and i not in di['new_php.txt']: #判读后缀名并通过后缀名放到相应的字典中,同时判读字典对应的文件列表中是否存在,如果是False则加入进去
di['new_php.txt'].append(i)
elif aq == '.asp\n' and i not in di['new_asp.txt']:
di['new_asp.txt'].append(i)
elif aq == '.aspx\n' and i not in di['new_aspx.txt']:
di['new_aspx.txt'].append(i)
elif aq == '.jsp\n' and i not in di['new_jsp.txt'] :
di['new_jsp.txt'].append(i)
elif (aq == ('.ini\n' or '.xml\n' or '.cgi\n' or '.log\n' or '.db\n' or '.mdb\n' or '.sql\n' or '.xml\n' or '.htm\n' or '.html\n' or '.bak\n' or '.dbf\n' or '.zip\n' or '.rb\n' or '.js\n' or '.css\n' or '.html?\n')) and i not in di['new_mdb.txt']:
di['new_mdb.txt'].append(i)
elif i not in di['new_dir.txt'] :
di['new_dir.txt'].append(i)
f.close()
except (UnicodeDecodeError) as e:
print("字典文件中有错误请检查是否是字典",e)
di1,fi = os.path.split(path)
print(' 分类完毕......准备写入')
for key in di: #写入到文件中
o = open(key,'w')
for i in di[key]:
o.write(i)
Time(n, time.time())
def dir_txt(path): #传进去路径,返回来的是路径下的后缀为txt的文件。如果没有则是当前路径。
dir_txt = []
a = os.listdir(path)
for i in a:
dd, ff = os.path.splitext(i)
if ff == '.txt':
dir_txt.append(i)
return dir_txt
def password(file,path):
try:
path_list = []
password_list = []
for i in file:
pathl = os.path.join(path,i)
path_list.append(pathl)
print(" 开始去除重复.....")
for i in path_list: #重复每一个给定的密码文件
F = open(i,'r')
txt = F.readlines()
F.close
for j in txt: #读取每一个密码文件,并且判读是否存在于password_list列表,如不存在则放进列表
if '\n' not in j:
j+='\n'
if j not in password_list:
password_list.append(j)
print(" 完成,并且准备写入。")
file = open('Password.txt','w') #打开即将写入的Password.txt,把passowrd_list列表数据全部写入进去
for i in password_list:
file.write(i)
file.close
print(" 运行完毕。")
except :
print(" 请检查文件是否存在,路径是否正确。")
def Optparse():
try:
parser = argparse.ArgumentParser(
"""把字典分类:new_php.txt,new_asp.txt,new_aspx.txt,new_jsp.txt,new_mdb.txt,new_dir.
-t -path C:\\x\\x\*
-t -path C:\\x\\x -file xxx.txt,xx.txt """)
group = parser.add_mutually_exclusive_group()
group.add_argument('-p',action='store_true',help='密码合并') #-p 和-t参数是互相排斥的,并不能一起使用。
group.add_argument('-t',action='store_true',help='后台目录字典合并',)
parser.add_argument('-file', type=str, help='输入的文件',required=False)
parser.add_argument('-path',type=str,help='你所指定的目录',required=False)
args = parser.parse_args()
if args.t: #判读t是否真
if args.file == None:
path,file = os.path.split(args.path)
dir__txt = dir_txt(path)
type_txt(dir__txt,path)
elif args.file != None:
list_file = args.file.split(',')
type_txt(list_file,args.path)
elif args.p: #判读p是否真
if args.file == None:
path, file = os.path.split(args.path)
dir__txt = dir_txt(path)
password(dir__txt,path)
elif args.file != None:
list_file = args.file.split(',')
password(list_file,args.path)
else:
print(" 错误请检查输入。")
except (KeyboardInterrupt):
print(' 以退出')
来源:https://bbs.ichunqiu.com/thread-49190-1-1.html
0
投稿
猜你喜欢
- Python的集合set原理集合(set)是一个无序的不重复元素序列。可以使用大括号 { } 或者 set() 函数创建集合,注意:创建一个
- 1. 创建Django项目创建应用前必须先进入虚拟环境 workon npy007创建个文件夹 madir testcd testdjang
- 学习Python过程中,发现没有switch-case,过去写C习惯用Switch/Case语句,官方文档说通过if-elif实现。所以不妨
- 本文实例讲述了Python面向对象之类和对象属性的增删改查操作。分享给大家供大家参考,具体如下:一、类属性的操作# -*- coding:u
- pytorch查看模型model参数parameters示例1:pytorch自带的faster r-cnn模型import torchim
- 介绍目前它是Python数值计算中最为重要的基础包,将numpy的数组的对象作为数据交互的通用语,一般我们要充分理解好矩阵计算的原理,这需要
- 本文实例讲述了Python使用django获取用户IP地址的方法。分享给大家供大家参考。具体如下:函数实现:def get_client_i
- 本文实例讲述了thinkphp3.x连接mysql数据库的方法。分享给大家供大家参考,具体如下:惯例配置文件:ThinkPHP/conf/c
- 安装源pip install django2.2pip install mysqlclient1.4.6使用pyharm 创建django
- 本文实例讲述了Python实现采用进度条实时显示处理进度的方法。分享给大家供大家参考,具体如下:前言在大多数时候,我们的程序会一直进行循环处
- 前言:如果大家接触过数据分析,那么大家可能都知道,最让人头疼的就是在数据录入的过程中,不可避免的会产生重复值,缺失值和异常值了,python
- Oracle9i之前,中文是按照二进制编码进行排序的。在oracle9i中新增了按照拼音、部首、笔画排序功能。 1、
- 在Asp中如何得到所有表单的名称跟对应的值。其实,这个问题很简单,但是可能还是有很多人不知道该怎么做,所以特地写下来,仅供参考。在Asp程序
- 本文介绍了Python中Selenium模拟JQuery滑动解锁实例,分享给大家,也给自己留个笔记滑动解锁一直做UI自动化的难点之一,我补一
- 本文参加新星计划人工智能(Pytorch)赛道:https://bbs.csdn.net/topics/613989052一、Mnist 分
- 程序运行效率程序的运行效率分为两种:第一种是时间效率,第二种是空间效率。时间效率被称为时间复杂度,而空间效率被称作空间复杂度。时间复杂度主要
- 还是网站在不同操作系统不同浏览器下兼容性的问题,但难度加了一层.如果是要检查用户登录后的页面的兼容性,该怎么办?现在一般的测试网站,都是提交
- Django中每一个模型model都对应于数据库中的一张表,每个模型中的字段都对应于数据库表的列。方便的是,django可以自动生成这些cr
- 本文实例讲述了Python多进程机制。分享给大家供大家参考。具体如下:在以前只是接触过PYTHON的多线程机制,今天搜了一下多进程,相关文章
- 一、lower():将大写字母全部转为小写字母。如:name='G'b=name.lower()二、title”"