• 注册
  • 技术交流 技术交流 关注:26 内容:30

    PYTHON 判断目录批量替换JS劫持脚本

  • 查看作者
  • 打赏作者
  • #!/usr/bin/env python
    # encoding: utf-8
    
    import os
    import re
    import io
    
    def func_read_file():
        read_file = os.path.dirname(os.path.realpath(__file__)) + '/fuck.js'
        with io.open(read_file, 'r',encoding='UTF-8') as f:
            read_all = f.read()
            f.close()
        return read_all
    
    def func_rewrite_file(file, data):
        with io.open(file, 'w', encoding='UTF-8') as f:
            f.write(data)
            f.close()
    
    def func_replace_js(path,file_name):
        js_data = func_read_file()
        for maindir, subdir, file_name_list in os.walk(path):
            for f in file_name_list:
                apath = os.path.join(maindir, f)
                if re.search(file_name, f) and ('jiechi' in apath):        
                    print(apath)
                    func_rewrite_file(apath,js_data)
    
    
    
    func_replace_js('/www/wwwroot','fuck.js')

    厉害 !!!!

    回复

    请登录之后再进行评论

    登录

    WordPress后台-外观-小工具 进行配置小工具

    帖子间隔 侧栏位置: