发布于2022年10月14日3年前 前言: 今天逛朋友圈的时候。发现了车王说,用python写web路径扫描的小伙伴门用head别用get。 后来我去百度了查了一下发现Head和Get的不同之处。所以有了以下这篇文章。 请求对比: GET:使用GET请求某个路径获取返回的响应。请求参数会暴露在外 HEAD:特别适用在优先的速度和带宽下 1.检查资源的有效性。 2.检查超链接的有效性。 3.检查网页是否被串改。 4.多用于自动搜索机器人获取网页的标志信息,获取rss种子信息,或者传递安全认证信息等。 正文: 思路:让使用者可以调用指定的web字典进行扫描,添加过滤信息。 当返回的URL的状态码为200并且无过滤列表里面关键字则判定为存在该路径。 代码: import requests import os urlw=[] okurl=[] noturl=[] error=['404','Not Found','403','找不到','没有权限','360','云锁','网站防火墙','D盾','百度云加速'] //过滤列表 headers={'user-agent':'Opera/9.80(WindowsNT6.1;U;en)Presto/2.8.131Version/11.11'} ld=os.listdir('dict') print('[+]Discovery directory') for l in ld: print('[+]find',l) print('') user=input('Please choose:') user2=input('Enter your URL:') if os.path.exists('dict/{}'.format(user)): print('[+]File existence {}'.format(user)) else: print('[-]file does not exist {}'.format(user)) exit() ope=open('dict/{}'.format(user),'r') for r in ope.readlines(): url=user2.strip()+"".join(r.split('\n')) urlw.append(url) def ether(urls): try: reqt=requests.head(url=urls,headers=headers,allow_redirects=True) for e in error: if reqt.status_code==200 and e not in reqt.text: //判断 yes='[200]=>Discovery path:{}'.format(reqt.url) if yes in okurl:continue //去重 okurl.append(yes) print(yes) else: no='[{}]=>Can t find:{}'.format(reqt.status_code,reqt.url) if no in noturl:continue //去重 noturl.append(no) print(no) except Exception as g: print('[-]Error in {} url:{}'.format(g,reqt.url)) for w in urlw: ether(w) 测试效果:
创建帐户或登录后发表意见