侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

Python编写合并字典并实现敏感目录的小脚本

Python  /  管理员 发布于 7年前   158

0x00 起因

接触网安快一年了,爱收集一些字典啊敏感目录文件啊什么的。收集多了难免有重复,并且有的也需要合并使用方便。自己就写了一个小小的脚步用来完成这个目的。

0x01 代码

第一次发表文章,希望大家多提意见。抱拳了!

代码我就贴出来了

import osimport timeimport argparseimport optparsedef 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_txtdef 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(' 以退出')

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    初探利用Python进行图文识别(OCR)
    下一条:
    Python实现监控Nginx配置文件的不同并发送邮件报警功能示例
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客