python焦点编程:web处事器日志阐明简朴剧本
由于N种原因,一个阐明入侵日志的任务落在了我身上,1G的日志,怎么去快速阐明呢??刺总说可以搞个剧本理会入库,再到数据库阐明。。。算了,那就蛋疼了,直接码个剧本把有问题的日志拿出来阐明吧。于是就有了这个小剧本。至于怎么用就要看你本身了,哈哈,好比查到sql注入语句,然后看到IP,就可以改下剧本,用IP为特征取出日志,阐明入侵进程。速度很快哦,我那破呆板,跑1G日志文件也就几秒钟的啦。
在事情中写措施完成任务是很快乐的事,也很有意思。哈哈
利用参数:seay.py E:/1.log
#coding = utf8
#Filename = seay.py
import os
import sys
#特征,可以随意改,两块五一次
_tezheng = {'union','select','file_put_contents'}
def CheckFile(_path):
_f = open(_path,"r")
_All_Line = _f.readlines()
_f.close()
_Count_Line =0
_Len_Line = len(_All_Line)
_Ex_Str = ''
print('Read Over --')
while _Count_Line<_Len_Line:
_Str = _All_Line[_Count_Line]
for _tz_Str in _tezheng:
if _tz_Str in _Str: #可以加and条件,这个贵一点,5毛一次
_Ex_Str+=_tz_Str+_Str+'\r\n'
_Count_Line+=1
_f1 = open(_path+'.seay.txt',"w")
_f1.write(_Ex_Str)
_f1.close()
print 'Find Over--'
if len(sys.argv)==2:
_File = sys.argv[1]
if os.path.lexists(_File):
CheckFile(_File)
else:
print('File does not exist!')
else:
print 'Parameter error'
print sys.argv[0]+' FilePath'
最终生成一个文件为:原文件名.seay.txt在同目次下,名目为匹配的特征+日志