用Python和MD5實現(xiàn)網(wǎng)站掛馬檢測程序
一、程序測試
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
二、實現(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)文章
解決python執(zhí)行不輸出系統(tǒng)命令彈框的問題
今天小編就為大家分享一篇解決python執(zhí)行不輸出系統(tǒng)命令彈框的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06
Python tkinter實現(xiàn)圖片標(biāo)注功能(完整代碼)
tkinter是Python下面向tk的圖形界面接口庫,可以方便地進行圖形界面設(shè)計和交互操作編程,本文通過實例代碼給大家介紹的Python tkinter實現(xiàn)圖片標(biāo)注功能,感興趣的朋友一起看看吧2019-12-12
Python簡單實現(xiàn)安全開關(guān)文件的兩種方式
這篇文章主要介紹了Python簡單實現(xiàn)安全開關(guān)文件的兩種方式,涉及Python的try語句針對錯誤的判定與捕捉相關(guān)技巧,需要的朋友可以參考下2016-09-09
tkinter動態(tài)顯示時間的兩種實現(xiàn)方法
這篇文章主要介紹了tkinter動態(tài)顯示時間的兩種實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01
利用Python的Flask框架來構(gòu)建一個簡單的數(shù)字商品支付解決方案
這篇文章主要介紹了利用Python的Flask框架來構(gòu)建一個簡單的數(shù)字商品支付解決方案,文中用極簡的代碼展示了一個flask框架下的支付模版,需要的朋友可以參考下2015-03-03
Python 讀取串口數(shù)據(jù),動態(tài)繪圖的示例
今天小編就為大家分享一篇Python 讀取串口數(shù)據(jù),動態(tài)繪圖的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07
PyTorch中 tensor.detach() 和 tensor.data 的區(qū)別詳解
今天小編就為大家分享一篇PyTorch中 tensor.detach() 和 tensor.data 的區(qū)別詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01
使用python框架Scrapy爬取數(shù)據(jù)的操作步驟
Scrapy是一個基于Python的強大的開源網(wǎng)絡(luò)爬蟲框架,用于從網(wǎng)站上抓取信息,它提供了廣泛的功能,使得爬取和分析數(shù)據(jù)變得相對容易,本文小編將給給大家介紹一下如何使用python框架Scrapy爬取數(shù)據(jù),需要的朋友可以參考下2023-10-10

