用Python和MD5實(shí)現(xiàn)網(wǎng)站掛馬檢測(cè)程序
一、程序測(cè)試
Usage: python check_change.py update /home/wwwroot
python check_change.py check /home/wwwroot
# python check_change.py update /data/www #生成站點(diǎn)的md5值
# echo ' ' > /data/www/sitemap.html #測(cè)試清空文件
# rm -rf /data/www/sitemap.xml #測(cè)試刪除文件
# python check_change.py check /data/www #查找那些文件被篡改
/data/www/sitemap.xml
/data/www/sitemap.html
二、實(shí)現(xiàn)代碼如下(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()
相關(guān)文章
selenium 安裝與chromedriver安裝的方法步驟
這篇文章主要介紹了selenium 安裝與chromedriver安裝的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-06-06Python選擇網(wǎng)卡發(fā)包及接收數(shù)據(jù)包
今天小編就為大家分享一篇關(guān)于Python選擇網(wǎng)卡發(fā)包及接收數(shù)據(jù)包,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-04-04python將html轉(zhuǎn)成PDF的實(shí)現(xiàn)代碼(包含中文)
python將html轉(zhuǎn)成PDF的實(shí)現(xiàn)代碼,需要用到xhtml2pdf和微軟雅黑字體,需要的朋友可以參考下2013-03-03Python while循環(huán)使用else語句代碼實(shí)例
這篇文章主要介紹了Python while循環(huán)使用else語句代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02Python3 利用requests 庫進(jìn)行post攜帶賬號(hào)密碼請(qǐng)求數(shù)據(jù)的方法
今天小編就為大家分享一篇Python3 利用requests 庫進(jìn)行post攜帶賬號(hào)密碼請(qǐng)求數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10Pycharm中安裝wordcloud等庫失敗問題及終端通過pip安裝的Python庫如何添加到Pycharm解釋器中(
這篇文章主要介紹了Pycharm中安裝wordcloud等庫失敗問題及終端通過pip安裝的Python庫如何添加到Pycharm解釋器中,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2020-05-05Python進(jìn)階之遞歸函數(shù)的用法及其示例
本篇文章主要介紹了Python進(jìn)階之遞歸函數(shù)的用法及其示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01