PHP webshell检查工具 python实现代码
李洪信儿子,小鲸鱼历险记,netstat命令详解
1.使用方法:find.py 目录名称
2. 主要是采用python正则表达式来匹配的,可以在keywords中添加自己定义的正则,格式:
["eval\(\$\_post","发现php一句话木马!"] #前面为正则,后面为对这个正则的描述,会在日志中显示。
3.修改下文件后缀和关键字的正则表达式就可以成为其他语言的webshell检查工具了,^_^。
4.开发环境是windows xp+activepython 2.6.2.2,家里电脑没有linux环境,懒得装虚拟机了,明天到公司linux虚拟机测试下。
5.目前只是一个框架,随后慢慢完善。
#coding:gbk
import os,sys
import re
findtype=['.php','.inc'] #要检查的文件后缀类型
#要检查的关键字正则表达式和日志中的描述,是一个二维数组。
keywords=[ ["eval\(\$\_post","发现php一句话木马!"],\
["(system|shell_exec|exec|popen)","发现php命令执行函数!"]\
]
writelog = open('log.txt', 'w+')
def checkfile(filename):
fp=open(filename)
content = fp.read()
for keyword in keywords:
if re.search(keyword[0],content,re.i):
log="%s:%s" % (filename,keyword[1])
#print log
print >>writelog,log
fp.close()
def checkdir(dirname):
try:
ls=os.listdir(dirname)
except:
print 'access deny'
else:
for l in ls:
temp=os.path.join(dirname,l)
if(os.path.isdir(temp)):
checkdir(temp)
else:
ext = temp[temp.rindex('.'):]
if ext in findtype:
checkfile(temp)
if __name__=="__main__":
print "php webshell check for python!"
print "by:neeao"
print "http://neeao.com"
if len(sys.argv) < 2:
print "%s c:\\" % sys.argv[0]
else:
print "check start!"
dirs=sys.argv[1:]
#print dirs[0]
if os.path.exists(dirs[0]):
checkdir(dirs[0])
else:
print "dir:'%s' not exists!" % dirs[0]
print "check finsh!"
writelog.close()
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
python如何查看网页代码
用python查看网页代码的方法:1、使用“import”导入requests包import requests2、使用requests包的get()函数通过网页...
[阅读全文]
-
-
python如何保存文本文件
python保存文本文件的方法:使用python内置的open()类可以打开文本文件,向文件里面写入数据可以用write()函数,写完之后,使用close()函...
[阅读全文]
-
python如何编写win程序
python可以编写win程序。win程序的格式是exe,下面我们就来看一下使用python编写exe程序的方法。编写好python程序后py2exe模块即可将...
[阅读全文]
-
-
-
-
-
-
网友评论