使用python编写简单的目录扫描

    科技2024-09-29  16

    第一个

    地址:

    http://www.miaosj.cn/

    思路:

    """ 通过分析判断网页返回的状态码来表明目录是否存在 1.访问网页 2.查看状态码 3.判断网页是否存在 """

    代码:

    import requests url = "http://www.miaosj.cn/" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" } print("开始( ̄_, ̄ )执行......") #定义个file函数,参数为file1 def file(file1): #打开文件的值(utf-8的格式)用行展示 f = open(file1,encoding='utf-8').readlines() #返回个f return f #定义个run函数 def run(): #赋值给run run = file("2.txt") #循环run的值到i for i in run: #去掉换行 cf = i.strip("\n") #拼接网址和目录名称 URL = url + str(cf) #获得状态码 response = requests.get(URL,headers=headers) #判断状态码是否为200 if response.status_code == 200: print("[+]" + str(cf) + "存在") #将打印的值到传输到f print("[+]" + str(cf) + "存在",file=f) else: print("[+]" + str(cf) + "不存在") return "" #创建写入1.txt with open("1.txt",'w') as f: #调用run()函数并写入到f f.write(run()) #关闭 f.close()

    第二个

    #模块 import requests import sys #第一个参数 url = sys.argv[1] #第二个 dic = sys.argv[2] #打开文件 with open(dic,"r") as f: #单行输出 for line in f.readlines(): line = line.strip() r = requests.get(url + line) #判断返回码 if r.status_code == 200: print("url:" + r.url)

    第三个多线程

    import getopt import sys import math import threading import requests #帮助 def banner(): print("*"*50) print("奥里给 v1.0") print("*" * 50) print("this is the tool's usage") print("python 奥里给 v1.0 -u url -t thread -d dictionary") #开始执行 def start(): if len(sys.argv) == 7: opts, args = getopt.getopt(sys.argv[1:], "u:t:d:") #格式正确传参过去 for k,v in opts: if k == "-u": url = v elif k == "-t": threads = v elif k == "-d": dic = v multi_scan(url,threads,dic) #不正确,提示 else: banner() sys.exit() def multi_scan(url,threads,dic): result_list = [] threads_list = [] #读取文件 with open(dic,"r") as f: dic_list = f.readlines() if len(dic_list) % int(threads) == 0: result = len(dic_list) / int(threads) else: result = math.ceil(len(dic_list) / int(threads)) print(result) i = 0 temp_list = [] for line in dic_list: i = i+1 if i % result == 0: temp_list.append(line.strip()) result_list.append(temp_list) temp_list = [] else: temp_list.append(line.strip()) #多线程 for i in result_list: threads_list.append(threading.Thread(target=scan,args=(url,i))) for t in threads_list: t.start() print(result_list) #判断是否存活 def scan(url,dic): for line in dic: r = requests.get(url + '/' + line) if r.status_code == 200: print(r.url + " "*15 + str(r.status_code)) start()
    Processed: 0.009, SQL: 8