首页 > 技术文章 > Python写一个目录检索器

haq5201314 2018-06-23 20:57 原文

前言:

昨天看了Demon哥发的干货,有了次篇博文

干货链接:

https://www.soffensive.com/2018/06/exploiting-blind-file-reads-path.html?m=1
 
https://github.com/soffensive/windowsblindread
 
https://github.com/mubix/post-exploitation-wiki/blob/master/windows/files.md
 
正文:
1.将路径保存到一个txt,遍历
2.判断是否存在
3.存在则写入一个文件
代码:
import os
import optparse
payload=open('mulu.txt','r')
def main():
    parser=optparse.OptionParser()
    parser.add_option('-x',dest='jiansuo',action='store_true',help='Retrieval path')
    (options,args)=parser.parse_args()
    if options.jiansuo:
        jiancha()
    else:
        parser.print_help()
        exit()

def jiancha():
    for p in payload.readlines():
        jiance=os.path.exists('{}'.format(p.strip()))
        if jiance==True:
            print('[>>>]The path of existence:{}'.format(p))
            lk=open('word.txt','w')
            lk.write(p)
            lk.close()
        else:
            print('[x]A path that does not exist:{}'.format(p))

if __name__ == '__main__':
    main()

测试如下:

 

推荐阅读