grafana弱口令检测

#-*- encoding:utf-8 -*-
import urllib
import urllib2

def check(ip,port,timeout):
	url="http://%s:%s/login"%(ip,str(port))
	header={
	'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36',
	'ContentType': 'application/x-www-form-urlencoded; chartset=UTF-8',
	'Accept-Encoding': 'gzip, deflate',
	'Accept-Language': 'zh-CN,zh;q=0.8',
	'Connection': 'close'
	}
	data={"user":"admin","email":"","password":"admin"}
	data=urllib.urlencode(data)
	request = urllib2.Request(url=url,data=data,headers=header)
	try:
	    res=urllib2.urlopen(request,timeout=timeout)
	    if "Logged in" in res.read():
		     return u'grafana 存在弱口令'
	except Exception,e:
		pass
if __name__ == '__main__':
    print check("127.0.0.1",3000,5)


里面的坑就是contentype 经过urllib.urlencode 之后虽然抓包的是json 但这里不可用 改成urlencoded

你可能感兴趣的:(python)