python编写扫描工具_python写的web路径扫描工具

现成的WEB路径扫描工具颇多,但都不尽如人意,主要是它是根据返回的状态码来判断页面是否存在的,比如返回200,就认为找到页面,404则认为页面不存在。但这里有个问题,返回的状态码是服务端可控的,而工具对于状态码的判断规则大都是定死了的,这就使得扫描结果没有多大价值。

所以抽空写了个web扫描工具,它的原理是先探测一个肯定不存在的路径和页面,/mustnotexistspath/和/mustnotexistspath+ext ,将他两的返回码作为页面不存在的标志,如果与之不同,则页面可能存在,原理相当简单,起到了动态判断的效果。

代码为:

#!/usr/bin/python

import httplib2

import sys

if len(sys.argv) 

print(“written by lanz….”)

print( “Usage: ” + sys.argv[0] + ” host ” + ” .ext”)

print (“Eg: ” + sys.argv[0] + ” http://www.baidu.com .php”)

sys.exit(0)

host = sys.argv[1]

ext = sys.argv[2]

print(host)

http = httplib2.Http(“.cache”)

response,content = http.request(host)

response,content=http.request(host+”/mustnotexistspath/”)

nonpathstatus = response.status

response,content=http.request(host+”/mustnotexistspath”+ext)

nonpathextstatus = response.status

print(“NoneExistPathStatus:”,nonpathstatus)

print(“NoneExistFileStatus:”,nonpathextstatus)

f = open ( ‘WebPath.txt’, ‘r’ )

fileList = f.readlines()

def subscan(subpath):

for fileLine in fileList:

newline = fileLine.strip()

path = subpath+”/”+newline

response,content= http.request(path,”GET”)

if response.status!=nonpathstatus:

st = str(response.status)

print(st+” : “+path)

subscan(path)

pathext=path + ext

response,content= http.request(pathext,”GET”)

if response.status!=nonpathextstatus:

st = str(response.status)

print(st+” : “+pathext)

subscan(host)

f.close()

效果对比:

使用webtools扫描目录的结果图:

使用新代码得到的效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值