金沙官网线上用Python和MD5实现网站挂马检测程序
这些代码,大部分是从别处转来的。测试的时候会比较有用。比如数据嗅探,发送请求,正则表达式处理文件,注入测试等。
实际中可以根据自己的项目,进行一定程度的扩展。代码是简洁为主。这部分代码是偏重安全测试的。
学习python已经3月了。感觉非常有用。
前些天,pm还让我写一个程序辅助他办公。
一、程序测试
近来发现很多公司也开始在自己的招聘职位上加上了python。
对于python。功能说的太多没有用,我发一些例子。
我也推荐大家有时间不妨学习一下。一天基本上就可以学会。
外国非常流行。我的pm是德国人,他们国家好像是直接学习python,就像咱们学习c一样普及。
国外搞python开发的人很多,公司也很多。国内的相对较少。
我学习这个,是为了辅助工作和玩hack。日常用也很强大。
google有个google app
enginer,是个类似虚拟主机的服务。使用python开发web应用。
另外,google本身是基于python的。
复制代码 代码如下:
大多数应用,都可以使用一个函数搞定,比如文件下载,发送请求,分析网页,读写xml,文件压缩,爬虫搜索。
这些应用绝大多数是跨平台的。可以在linux下运行。
ironpyhon是一个组合.net平台和python的工具,他们正在研究如何利用python把.net放在linux上运行。
# python check_change.py
诺基亚的手机也开始支持python编程。
java,.net 也开始提供python版本。
Usage: python check_change.py update /home/wwwroot
python check_change.py check /home/wwwroot
下面举些例子,演示一下python的功能。
# python check_change.py update /data/www #生成站点的md5值
# echo ' ' > /data/www/sitemap.html #测试清空文件
# rm -rf /data/www/sitemap.xml #测试删除文件
# python check_change.py check /data/www #查找那些文件被篡改
/data/www/sitemap.xml
/data/www/sitemap.html
1、数据嗅探,这个例子,是嗅探土豆网上的flash真正的播放地址。
import pcap ,struct , re
from pickle import dump,load
pack=pcap.pcap()
pack.setfilter('tcp port 80')
regx=r'/[w+|/]+.flv|/[w+|/]+.swf'
urls=[]
hosts=[]
print 'start capture....'
for recv_time,recv_data in pack:
urls=re.findall(regx,recv_data);
if(len(urls)!=0):print urls;
二、实现代码如下(check_change.py)
2、嗅探qq号码,前些天我还用它嗅探局域网里所有的qq那。可惜没有识别性别的功能。不过可以自己添加
复制代码 代码如下:
# -*- coding: cp936 -*-
import pcap ,struct
pack=pcap.pcap()
pack.setfilter('udp')
key=''
for recv_time,recv_data in pack:
recv_len=len(recv_data)
if recv_len == 102 and recv_data[42]== chr(02) and
recv_data[101]
== chr(03):
print struct.unpack('>I',recv_data[49:53])[0]
elif recv_len == 55:
print struct.unpack('>I',recv_data[49:53])[0]
#!/usr/bin/env python
3、数据嗅探,项目中遇到,需要嗅探一些发送到特定端口的数据,于是花了几分钟写了一个程序。
import os,sys,subprocess
import pcap ,struct
from pickle import dump,load
pack=pcap.pcap()
pack.setfilter('port 2425')
f=open(r'/mm.txt','w+')
print 'start capture....'
for recv_time,recv_data in pack:
print recv_time
print recv_data
f.write(recv_data)
def update(path):
f = open(file,'w')
for root,dirs,files in os.walk(path):
for name in files:
line = os.path.join(root, name)
(stdin,stderr) =
subprocess.Popen(['md5sum',line],stdout=subprocess.PIPE).communicate()
f.write(stdin)
f.close()
3、5 文件内容搜索,我发现windows的自带的搜索无法搜索内容。即使搜索到也不准。就自己写了一个
def check(path):
f = open(file,'r')
for line in f:
check_ok = """echo '%s' | md5sum -c > /dev/null 2>&1""" %
line
#print check_ok
if not subprocess.call(check_ok, shell = True) == 0:
abnormal = line.split()
print abnormal[1]
f.close()
import os,string,re,sys
def Usage():
print '''
Usage: python %s update /home/wwwroot
python %s check /home/wwwroot
''' % (sys.argv[0],sys.argv[0])
sys.exit()
class SevenFile:
files=[]
def FindContent(self,path):
print
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
walks=os.walk(path)
for walk in walks:
for filename in walk[2]:
if('.mht' == filename[-4:]):
res_taskid=[]
file=walk[0]+'\'+filename
f=open(file)
content=f.read()
pattern_taskid=re.compile(r'Stonehenge-UIVerificationChecklist.mht',re.IGNORECASE)
#
res_taskid=pattern_taskid.findall(content)
f.close()
if len(res_taskid)>0:
self.files.append(file)
if len(sys.argv) != 3:
Usage()
def run():
f=SevenFile()
f.FindContent(r"E:workAPManual
TestsPSIGTestProjectPSIGTestProject")
for filepath in f.files:
print filepath
print "OK"
file = 'file.key'
model = sys.argv[1]
path = sys.argv[2]
if __name__=="__main__":
run()
if os.path.exists(path) == False:
print " 33[;31mThe directory or file does not exist 33[0m"
sys.exit()
elif model == 'update':
update(path)
elif model == 'check':
check(path)
else:
Usage()
4、这个不是我写的,是一个网上的×××phpwind论坛的一个代码
http://www.bkjia.com/Pythonjc/741236.htmlwww.bkjia.comtruehttp://www.bkjia.com/Pythonjc/741236.htmlTechArticle一、程序测试 复制代码 代码如下: # python check_change.py Usage: python check_change.py update /home/wwwroot python check_change.py check /home/wwwroot # python check_...
# -*- coding: gb2312 -*-
import urllib2,httplib,sys
httplib.HTTPConnection.debuglevel = 1
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)
def usage():
print "Usage:n"
print " $ ./phpwind.py pwforumurl usertoattackn"
print " pwforumurl 目标论坛地址如http://www.80sec.com/"
print " usertoattack 目标拥有权限的斑竹或管理员"
print " ×××结果将会在目标论坛注册一个和目标用户一样的帐户"
print " 最新版本可以使用uid登陆"
print " 其他版本可以使用cookie+useragent登陆"
print
"########################################################"
print ""
argvs=sys.argv
usage()
本文由金沙官网线上发布于编程,转载请注明出处:金沙官网线上用Python和MD5实现网站挂马检测程序