In the Web security emergency response, it is inevitable to check whether the webshell is uploaded on the server. The manual check is slow and you have written a script to check it. On the Windows platform, lake2 has been written to the lake chart, and the general check is enough. I wrote a Linux image written in python.
1. Usage: find. py directory name
2. python regular expressions are used for matching. You can add your own defined Regular Expressions in keywords. The format is as follows:
["Eval ($ \ _ POST", "found a PHP Trojan! "] # The regular expression is followed by the regular expression description, which is displayed in the log.
3. Modify the file suffix and the regular expression of the keyword to become a webshell check tool in other languages, ^_^.
4. the development environment is windows xp + ActivePython 2.6.2.2. If your computer does not have a Linux environment, you are too lazy to install a virtual machine. You will test the environment on your Linux virtual machine tomorrow.
5. Currently, it is only a framework that will be gradually improved.
1. # coding: gbk
2. import OS, sys
3. import re
4.
5. findtype = [. php,. inc] # file suffix type to be checked
6.
7. # The keyword regular expression to be checked and the description in the log are a two-dimensional array.
8. keywords = [["eval ($ \ _ POST", "found a PHP Trojan! "],
9. ["(system | shell_exec | exec | popen)", "PHP Command Execution function found! "]
10.]
11.
12. writelog = open(log.txt, w +)
13.
14. def checkfile (filename ):
15. fp = open (filename)
16. content = fp. read ()
17. for keyword in keywords:
18. if re. search (keyword [0], content, re. I ):
19. log = "% s: % s" % (filename, keyword [1])
20. # print log
21. print> writelog, log
22. fp. close ()
23.
24.
25. def checkdir (dirname ):
26. try:
27. ls = OS. listdir (dirname)
28. Failed t:
29. print access deny
30. else:
31. for l in ls:
32. temp = OS. path. join (dirname, l)
33. if (OS. path. isdir (temp )):
34. checkdir (temp)
35. else:
36. ext = temp [temp. rindex (.):]
37. if ext in findtype:
38. checkfile (temp)
39.
40.
41. if _ name __= = "_ main __":
42. print "PHP webshell check for Python! "
43. print "By: Neeao"
44. print "http://Neeao.com"
45. if len (sys. argv) <2:
46. print "% s C: \" % sys. argv [0]
47. else:
48. print "Check start! "
49. dirs = sys. argv [1:]
50. # print dirs [0]
51. if OS. path. exists (dirs [0]):
52. checkdir (dirs [0])
53. else:
54. print "Dir: % s not exists! "% Dirs [0]
55.
56. print "Check finsh! "
57.
Writelog. close (