当前位置: 首页 > 图文教程 > 脚本技术 > Python > PHP webshell检查工具 python实现代码

Python
Python完全新手教程
Python学习资料
Python入门
一篇不错的Python入门教程
王纯业的Python学习笔记 下载
python的几种开发工具介绍
python编程-将Python程序转化为可执行程序[整理]
在漏洞利用Python代码真的很爽
推荐下python/ironpython:从入门到精通
python 图片验证码代码
wxpython 学习笔记 第一天
python 正则表达式 概述及常用字符
python 生成目录树及显示文件大小的代码
PHP webshell检查工具 python实现代码
phpsir 开发 一个检测百度关键字网站排名的python 程序
Cython 三分钟入门教程
Python中的Function定义方法
Python 流程控制实例代码
Python 字符串定义
Python 第一步 hello world

Python 中的 PHP webshell检查工具 python实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 237 ::
收藏到网摘: n/a

Web安全应急响应中,不免要检查下服务器上是否被上传了webshell,手工检查比较慢,就写了个脚本来检查了。Windows平台下已经有了lake2写的雷克图的了,一般的检查也够用了,写了个Linux下面的,用python写的。 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()