国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 幫助中心 > 正文

Linux利用Python腳本檢測網站掛馬程序

2024-07-09 22:50:19
字體:
來源:轉載
供稿:網友

部署站點后通常首先會生成該站點所有文件的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 python  

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 "33[;31mThe directory or file does not exist33[0m"  

    sys.exit()  

elif model == 'update':  

    update(path)  

elif model == 'check':  

    check(path)  

else:  

    Usage()  

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长垣县| 益阳市| 天水市| 连平县| 始兴县| 淮滨县| 稷山县| 万载县| 北碚区| 汤原县| 通许县| 广宁县| 大连市| 长沙县| 毕节市| 弥勒县| 龙游县| 漳州市| 太仓市| 广西| 米脂县| 翁源县| 岑巩县| 峨边| 淳安县| 万州区| 自治县| 台中市| 建德市| 明溪县| 通山县| 五莲县| 江津市| 寿宁县| 裕民县| 甘孜县| 伊通| 扶余县| 宜春市| 同江市| 庆安县|