用Python和MD5实现网站挂马检测程序
一、程序测试
# python check_change.pyUsage: 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,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()
您可能感兴趣的文章:
- 用Python和MD5实现网站挂马检测程序
- Python实现的检测网站挂马程序
- Python实现的检测网站挂马程序
- 检测网站挂马程序(Python)
- 检测网站挂马程序(Python)
- 检测百度关键字网站排名的python 程序
- 使用Python脚本实现批量网站存活检测遇到问题及解决方法
- phpsir 开发 一个检测百度关键字网站排名的python 程序
- phpsir 开发 一个检测百度关键字网站排名的python 程序
- Python实现批量网站URL存活检测
- Python实现的检测web服务器健康状况的小程序
- Python实现的检测web服务器健康状况的小程序
- Python实现的检测web服务器健康状况的小程序
- 使用Python脚本实现批量网站存活检测遇到问题及解决方法
- 【Python】用Python来实现凑24的程序,续--实现统计功能,列举出所有情况
- Python实现对网站目录扫描
- 用python实现一个按需生成用于vim跳转的tags文件的小程序
- 基于XML和Python实现白盒测试程序与测试用例分离
- 网路游侠:关于几个免费在线挂马检测网站
- ASP网站程序自动升级实现的方法