确定想要实现的功能
确定需求是最重要的事情,没有挨过打产品经理应该深有体会,挨过打的产品经理体会更深。作为一个想要自我实现某些琐碎功能代替手工的小菜,更要珍惜自己的时间。
常用库和自定义函数
可能用到的库包括但不限于requests、re、os、sys、importlib、time、string、random、socket、pybloom、ipy、tldextract、urllib、bs4、hashlib、selenium、argparse、threading、concurrent、multiprocessing、pymongo、pymysql、redis、celery、subprocess。
以及一些需要自己编写的函数等(以下示例函数可直接使用)。
例如:web字典生成
def urlbaklist(url): # 接收带协议的域名,返回域名字典 url1 = urlparse(url) url2 = tldextract.extract(url) if ":" in url1.netloc: domainname = url1.netloc.split(":")[0] else: domainname =url1.netloc domainname2 = url2.subdomain + url2.domain + url2.suffix domain = url2.domain + "." + url2.suffix domain2 = url2.domain + url2.suffix domain3 = url2.domain + "_" + url2.suffix # baidu_com sub = url2.subdomain subdomain2 = url2.subdomain + url2.domain center = url2.domain domainlist=[domainname, domainname2, domain, domain2,domain3,subdomain2, center] if url2.subdomain: domainlist.append(url2.subdomain) domainlist = list(set(domainlist)) return domainlist
网页编码设置
def getcharset(html): charset = "utf-8" m = re.compile('<meta .*(http-equiv="?Content-Type"?.*)?charset="?([a-zA-Z0-9_-]+)"?', re.I).search(html) if m and m.lastindex == 2: charset = m.group(2).lower() if charset=="" or charset==None: charset="utf-8" return charset
适当的webshell选择,当然也可以选择cmdshell,吃完饭回来重新编辑,里面的shell不见了,应该是被过滤掉了,心痛一秒钟,这样空着吧就。
def webshell(disable=None): #https://www.leavesongs.com/PENETRATION/php-callback-backdoor.html #https://bugs.leavesongs.com/%E8%BF%90%E7%BB%B4%E5%AE%89%E5%85%A8/lnmp%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BAphp%E6%B2%99%E7%9B%92%E7%BB%95%E8%BF%87-%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8C/ #https://blog.csdn.net/whatday/article/details/54880851 #http://www.cnblogs.com/LittleHann/p/3522990.html #http://wooyun.jozxing.cc/static/bugs/wooyun-2015-0145879.html "pcntl_exec" unix扩展,不通用,放弃 # disable绕过 #https://www.exehack.net/5158.html #http://www.cnblogs.com/R4v3n/articles/9081202.html #http://www.freebuf.com/articles/web/169156.html if disable==None: return "" elif "preg_replace" not in disable: return "" elif "create_function" not in disable: return "" elif "assert" not in disable: return "" elif "eval" not in disable: return "" elif "mb_ereg_replace" not in disable: return "" elif "preg_filter" not in disable: return "" else: return None
域名提取
def getdomain(line):#域名提取 url=urlparse(line) if ":" in url.netloc: domain = url.netloc.split(":")[0] else: domain =url.netloc return domain
对入口进行统一管理
由于要调用的各种扫描器和各位大佬写的框架或小工具对参数的接收各不相同,所以需要自己动手,丰衣足食,并在需要的时候将url或ip转换为需要的格式。
调用开源扫描器
调用masscan,其他大佬的小工具同理
def mascportscan(iplist,port,scanthread):#ip列表,端口,线程 portips1=time.strftime("%Y%m%d%H%M%S", time.localtime())+"port.txt" portscancommand="masscan --rate "+str(scanthread)+" -p"+str(port)+" -iL "+iplist+" -oL "+portips1 portscan=subprocess.Popen(portscancommand,shell=True,stdout=subprocess.PIPE,universal_newlines=True) while True: nextline=portscan.stdout.readline() if nextline!="": print(nextline.strip()) if nextline=="" and portscan.poll()!=None: break if portscan.poll(): print(str(port)+"端口扫描完成!") portips2=time.strftime("%Y%m%d%H%M%S", time.localtime())+str(port)+"scanok.txt"#输出到文件夹备用 if os.path.getsize(portips1)!=0: with open(portips1) as f: ls=f.readlines() ls.pop() ls.pop(0) ls=list(set(ls)) print("开放"+str(port)+"端口的有"+str(len(ls))+"个!") with open(portips2,"a+")as f2: for i in ls: ips=i.strip().split() f2.write(ips[3]+"n") return ls
EXP调用
def getExp(cms): exps = [] try: for dirpath, _, filenames in os.walk("./exps/"+cms+"/",topdown=False): for filename in filenames: if '__init__' not in filename and ".pyc" not in filename and '.DS_Store' not in filename and ".txt" not in filename: exps.append(filename) return exps except: return None
exp = getExp(name)
shotname, extension = os.path.splitext(i)
exprun = importlib.import_module("exps." + name + "." + shotname)
if "run_scan" in dir(exprun):
vnl = exprun.run_scan(target)
注意:
在拼接文件路径的时候,需要使用os.path.dirname(__file__)+"具体路径或文件名" 的方式获取配置文件或临时文件路径,如果直接使用相对路径去拼接,在当前文件能够争议使用,但是被第三方调用的时候就会出错。
在python3下使用requests和urllib会自动修改开发者手动修改的Accept-Encoding,可以使用pycurl和urllib3。python2下可直接使用。
结果整合及分布式处理和入库
可对大量任务使用celery+redis构建分布式任务队列进行任务处理,尝试过使用Jpython+多进程,但仍有一些库不受支持,就此放弃。mongodb、或者mysql作为最终存储,涉及基本字段有:id,scan,cms,port,waf,title,vul(数组形式,漏洞位置及对应漏洞名称),time,waf,note(处理记录)等。
参考
https://docs.python.org/zh-cn/3.7/
http://cn.python-requests.org/zh_CN/latest/
https://github.com/jaybaird/python-bloomfilter.git
https://www.cnblogs.com/alex3714/p/6351797.html
https://www.jianshu.com/p/9e422d9f1ce2
本文章来自彼此分享,仅供白帽子、安全爱好者研究学习,对于用于非法途径的行为,发布者及作者不承担任何责任。
我们建立了一个以知识共享为主的 免费精品 知识星球,旨在通过相互交流,促进资源分享和信息安全建设,为以此为生的工作者、即将步入此行业的学生等人士提供绵薄之力。目前星球已发布上千篇精品安全技术文章、教程、工具等内容,已加入上百位安全圈大咖及数千位安全从业者,期待在此共同与你交流。
如果你是安全行业精英,可以加入我们的微信群,目前聚集了来自全球的信息安全公司CEO,安全部门主管,技术总监,信安创业者,网络安全专家,安全实验室负责人,公司HR等。在这里将获得更多与安全大咖们面对面交流的机会,最新的安全动态,更真实的高薪信息安全岗位,更高效率的技术交流空间。可以扫码添加我的微信,需提供真实有效的公司名称+姓名,验证通过后可加入···
原文始发于微信公众号(糖果的实验室):快速使用py构建自己的web渗透框架
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论