天天看點

linux系統 網站木馬後門Webshell清除工具源碼

後門這東西好讓人頭疼,第一檔案太多了,不容易找,第二,難找,需要特征比對啊。搞了一個python版清除php webshell後門工具,大家可以增加後門的特征碼,然後甩到背景給他清除就可以了。适合Linux系統伺服器的站長們

這個代碼比較簡單,大家可以自己繼續完善下。主要是根據特征來比對查找網站木馬後門檔案。

01

#!/usr/bin/python

02

# -*- coding: utf-8 -*-

03

#blog:www.sinesafe.com

04

05

import

os

06

import

sys

07

import

re

08

09

rulelist 

=

[

10

'(\$_(GET|POST|REQUEST)\[.{0,15}\]\(\$_(GET|POST|REQUEST)\[.{0,15}\]\))'

,

11

'(base64_decode\([\'"][\w\+/=]{200,}[\'"]\))'

,

12

'eval\(base64_decode\('

,

13

'(eval\(\$_(POST|GET|REQUEST)\[.{0,15}\]\))'

,

14

'(assert\(\$_(POST|GET|REQUEST)\[.{0,15}\]\))'

,

15

'(\$[\w_]{0,15}\(\$_(POST|GET|REQUEST)\[.{0,15}\]\))'

,

16

'(wscript\.shell)'

,

17

'(gethostbyname\()'

,

18

'(cmd\.exe)'

,

19

'(shell\.application)'

,

20

'(documents\s+and\s+settings)'

,

21

'(system32)'

,

22

'(serv-u)'

,

23

'(提權)'

,

24

'(phpspy)'

,

25

'(後門)'

,

26

'(webshell)'

,

27

'(Program\s+Files)'

28

]

29

30

def

Scan(path):

31

for

root,dirs,files 

in

os.walk(path):

32

for

filespath 

in

files:

33

isover 

=

False

34

if

'.'

in

filespath:

35

ext 

=

filespath[(filespath.rindex(

'.'

)

+

1

):]

36

if

ext

=

=

'php'

:

37

file

=

open

(os.path.join(root,filespath))

38

filestr 

=

file

.read()

39

file

.close()

40

for

rule 

in

rulelist:

41

result 

=

re.

compile

(rule).findall(filestr)

42

if

result:

43

print

'檔案:'

+

os.path.join(root,filespath)

44

print

'惡意代碼:'

+

str

(result[

])

45

print

'\n\n'

46

break

47

48

if

os.path.lexists(sys.argv[

1

]):

49

print

(

'\n\n開始掃描:'

+

sys.argv[

1

])

50

print

(

'               可疑檔案                 '

)

51

print

(

'########################################'

)

52

Scan(sys.argv[

1

])

53

print

(

'提示:掃描完成-- O(∩_∩)O哈哈~'

)

54

else

:

55

print

'提示:指定的掃描目錄不存在---  我靠( \'o′)!!凸'

查到後門檔案後 直接删除掉,光删除是不行的得找到問題的根源到底是從哪裡的漏洞上傳上來的,那就有必須要對程式代碼進行安全審計了建議大家找專業做安全的來做深入的安全部署(建議找專業做安全的國内公司如:Sinesafe,綠盟,啟明星辰等等都是比較不錯的專業做網站安全的公司)