快讯资讯
手机优化
系统数码
网络通信人工智能
网站游戏
测评专题

  Python实现文件的全备份和       前端Nginx,后端Apache获取    

检测网站挂马程序(Python)

时间:2026-09-10 00:12 来源:未知 人气:

系统管理员通常从svn/git中检索代码,部署站点后通常首先会生成该站点所有文件的MD5值,如果上线后网站页面内容被篡改(如挂马)等,可以比对之前生成MD5值快速查找去那些文件被更改,为了使系统管理员第一时间发现,可结合crontab或nagios等工具。

程序测试如下:

# python check_change.py     Usage: python check_change.py update /home/wwwroot            python check_change.py check /home/wwwroot # 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

代码如下(check_change.py):

#!/usr/bin/envpython importos,sys,subprocess defupdate(path): f=open(file,'w') forroot,dirs,filesinos.walk(path): fornameinfiles: line=os.path.join(root,name) (stdin,stderr)=subprocess.Popen(['md5sum',line],stdout=subprocess.PIPE).communicate() f.write(stdin) f.close() defcheck(path): f=open(file,'r') forlineinf: check_ok="""echo'%s'|md5sum-c/dev/null21"""%line #printcheck_ok ifnotsubprocess.call(check_ok,shell=True)==0: abnormal=line.split() printabnormal[1] f.close() defUsage(): print''' Usage:python%supdate/home/wwwroot python%scheck/home/wwwroot '''%(sys.argv[0],sys.argv[0]) sys.exit() iflen(sys.argv)!=3: Usage() file='file.key' model=sys.argv[1] path=sys.argv[2] ifos.path.exists(path)==False: print"\033[;31mThedirectoryorfiledoesnotexist\033[0m" sys.exit() elifmodel=='update': update(path) elifmodel=='check': check(path) else: Usage() Fri Oct 25 11:02:44 CST 2013

本文标签:

更多文章

相关文章

网站导航 | 快讯 | 资讯 | 手机 | 优化

  • 数码 | 网络通信 | 人工智能 | 网站 | 游戏

    合作伙伴:

  • 友情链接(欢迎业界知名网站交换链接)申请友情

    

    声明:本站资源皆来自网络,如有侵权问题,请联系管理员处理!

    Copyright ©2020-2028快知站 版权所有 All rights reserved.

    闽ICP备20010713号-1 闽公网安备 35020602001684号