您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 辽阳分类信息网,免费分类信息发布

Python实现的检测网站挂马程序

2024/12/10 3:53:57发布57次查看
系统管理员通常从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/env pythonimport os,sys,subprocessdef 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()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()def usage(): print ''' usage: python %s update /home/wwwroot python %s check /home/wwwroot ''' % (sys.argv[0],sys.argv[0]) sys.exit()if len(sys.argv) != 3: usage()file = 'file.key'model = sys.argv[1]path = sys.argv[2]if os.path.exists(path) == false: print \033[;31mthe directory or file does not exist\033[0m sys.exit()elif model == 'update': update(path)elif model == 'check': check(path)else: usage()
辽阳分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录