用Python和MD5实现网站挂马检测程序
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
一、程序测试
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)
import os,sys,subprocess
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()
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()
相关文章
PyTorch、torchvision和Python版本的对应关系
使用PyTorch时,选择合适的Python版本是至关重要的,错误的版本组合可能导致各种兼容性问题,本文就来介绍一下PyTorch、torchvision与Python版本匹配,感兴趣的可以了解一下2024-03-03Python处理文件的方法(mimetypes和chardet)
这篇文章主要介绍了Python处理文件的方法(mimetypes和chardet),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-09-09Python flask框架请求体数据、文件上传、请求头信息获取方式详解
这篇文章主要介绍了Python flask框架请求体数据、文件上传、请求头信息获取方式详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧2024-03-03
最新评论