p God python directory traversal, reptiles

Python directory traversal

Reference link: https: //www.leavesongs.com/PYTHON/pythonfile.html

1. Role

Find a hacker to upload webshell

2. Add the beginning # - * - coding = UTF-8 - * -, you can add Chinese not being given #

3. Multi-line comments

Select the code, hold down ctrl + / multi-line comments

4. Code

# -*- coding=UTF-8 -*-
import os
def replace_str(filepath,sourcestr,objectstr):
    file = open(filepath,"r")
    str = file.read()
    str = str.replace(sourcestr,objectstr)
    file.close()
    file = open(filepath,"w")
    file.write(str)
    file.close()
def getfile(path):
    # leix = os.listdir(path)
    # print(type(leix))
    # print(leix)
    for file in os.listdir(path):
        file = os.path.join(path,file)
#        print(file)
        if os.path.isdir(file):
            getfile(file)
        else:
            replace_str(file,"abcd","")
rootpath = "D: / phpStudy / WWW / pshen / bianli" # use / to list the output directory and file
getfile (rootpath)

5. Another

# -*- coding=UTF-8 -*-
import os
def replace_str(filepath,sourcestr,objectstr):
    file = open(filepath,"r")
    str = file.read()
    str = str.replace(sourcestr,objectstr)
    file.close()
    file = open(filepath,"w")
    file.write(str)
    file.close()

def getfile():
    generator = os.walk('D:/phpStudy/WWW/pshen/bianli')
    for (nowdir,_,file_list) in generator:
        for file in file_list:
            file = os.path.join(nowdir,file)
            print(file)
            replace_str(file,"abcd","")
getfile()
# generator = os.walk('D:/phpStudy/WWW/pshen/bianli')
# print(type(generator))
# print(generator)
# for i in generator:
#     print(i)

Python and reptiles

1.python direct requests to use library

2.python invoke the browser app counterfeit items

3.python calling app python Fun vibrato project

Guess you like

Origin www.cnblogs.com/qzdlp/p/12128397.html