1.python编写web目录扫描工具

准备

报错大概率是缩进、缩进、缩进

# 注意pip版本号,安装py3的
linux:
pip3  install requests 
cmd:
pip install requests  
pip install fake_useragent

记得将字典改成utf-8格式

# webscan.py v1.0
# 用法:python webscan.py url
import requests
import sys
import fake_useragent

headers = {'User-Agent':fake_useragent.UserAgent().random}
print(headers)
#输入要扫的域名或ip
url = sys.argv[1]
with open('php.txt','r') as f:
    for i in f:
        #去除换行符
        i = i.strip()
        a = url + i
        #捕获超时异常,然后直接无视,直接进入下一个循环
        try:
            res = requests.get(a,headers = headers,timeout = 0.5 )
            if res.status_code == 200:
            #字体颜色设置,百度一下你就知道,不解释
                print("\033[1;32;40m %s \033[0m" % (a+'  200'))
            if res.status_code == 403:
                print("\033[1;31;40m %s \033[0m" % (a+'  403'))
            if res.status_code == 302:
                print("\033[1;31;40m %s \033[0m" % (a+'  302'))
            else:
                continue
         except Exception as e:
            pass
f.close()

在这里插入图片描述
多进程版本

#用法: webscan.py http://xxxx.com
import requests
import sys
import time
from multiprocessing import Pool


def req(url):
        try:
            res = requests.get(url,timeout=0.5)
            if res.status_code == 200:
             #字体颜色设置,百度一下你就知道,不解释
                print(url+'  200')
            elif res.status_code == 403:
                print(url+'  403')
            elif res.status_code == 302:
                print(url+'  302')
            elif res.status_code == 404:
                print(url+'  404')   
        except Exception as e:
                pass


if __name__ == '__main__':
    url = sys.argv[1].rstrip('/')
    p = Pool(10)
    with open('./php.txt','r') as f:
        for i in f.readlines():
            s=''
            s=url+i.strip()
            #req(s) //单进程单线程
            
            p.apply_async(req,(s,))
        print("------------------start---------------")
        p.close()
        p.join()
        print("-------------------end----------------")

在这里插入图片描述
多线程版本

#用法 webscan.py http://x.x.x.x.com
import threading
import sys
import requests
import time

thread_max = threading.BoundedSemaphore(5)

def req(url):
    try:
        res = requests.get(url,timeout=0.5)
        if res.status_code == 200:
             #字体颜色设置,百度一下你就知道,不解释
            print(url+'  200')
        elif res.status_code == 403:
            print(url+'  403')
        elif res.status_code == 302:
            print(url+'  302')
        elif res.status_code == 404:
            print(url+'  404')
    except Exception as e:
        pass


if __name__ == '__main__':
    threads=[]
    #限制线程的最大数量为10
    url=sys.argv[1]
    print("----------------start-------------")
    start=time.time()
    f=open('./php.txt','r') 
    for i in f:
        newUrl=url+i.strip()
        thread_max.acquire()
        t = threading.Thread(target=req, args=(newUrl,))
        threads.append(t)
        t.start()
        thread_max.release()
    for t in threads:
        t.join()    
    f.close()
    end=time.time()
    print("----------------end---------------")
    print(end-start)

在这里插入图片描述
PS
造轮子而已,本质上没啥困难的,就是利用此工具学习了下多进程和多线程,仅此而已

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值