简单的目录扫描python脚本1.0

        目录扫描在信息收集的过程中是一项非常重要的步骤,有时候网站其实有其他具有漏洞的网页,导致你错失getshell的绝佳机会。

        对此我很感兴趣,在思考这是什么原理呢,我个人认为是 输入的 url+字典 两个字符串进行拼接,然后发包,接收返回的状态码,然后判断状态码进行处理...

        下面是我的代码:

        

import requests

def httpContext(file_name):
    with open(file_name, 'r', encoding='utf-8') as good_file:
        for line in good_file:
            url = line.strip()  # 去除行末尾的换行符
            response = requests.get(url)  # 发送请求
            contents = response.text.lower()  # 获取响应的源代码并转换为小写

            if 'key' in contents:
                with open('httpContext.txt', 'a', encoding='utf-8') as output_file:
                    output_file.write(url + '\n')

url = 'http://192.168.21.42'  # 目标URL
with open('DIR.txt', 'r', encoding='utf-8') as f, open('Good.txt', 'w', encoding='utf-8') as good_file:
    for line in f:
        dir = line.strip()  # 去除行末尾的换行符
        full_url = url + dir  # 拼接URL
        try:
            response = requests.get(full_url)
            status_code = response.status_code
            print(f"[{status_code}]{full_url}")
            if status_code == 200:
                good_file.write(full_url + '\n')
        except requests.exceptions.RequestException as e:
            print(f"An error occurred: {e}")

httpContext('Good.txt')

代码中的DIR.txt是需要的字典文件,Good.txt是保存成功访问的url,httpContext是保存具有关键字的源码的url。

测试运行:

        DIR.txt文件:       

        运行py文件。

        结果:

                

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值