PHP Webshell Check tool python implementation code _python

Source: Internet
Author: User
1. How to use: find.py directory Name
2. The main use of Python regular expressions to match, you can add your own definition of keywords, format:
[Eval\ (\$\_post "," found PHP a word trojan!) "] #前面为正则, followed by a description of this regular, will be displayed in the log.
3. Modifying a regular expression of a file suffix and keyword can be used as a Webshell inspection tool in other languages, ^_^.
4. The development environment is the Windows Xp+activepython 2.6.2.2, the home computer does not have the Linux environment, is lazy to install the virtual machine, tomorrow to the company Linux virtual machine test.
5. The present is only a framework, which is then gradually refined.
Copy Code code as follows:

#coding: GBK
Import Os,sys
Import re

findtype=['. php ', '. Inc '] #要检查的文件后缀类型

#要检查的关键字正则表达式和日志中的描述, is a two-dimensional array.
keywords=[["Eval\ \$\_post", "found PHP a word trojan!" "],\
["(System|shell_exec|exec|popen)", "Discover PHP command execution function!"] \
]

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.