搜索
查看: 544|回复: 2

linux下python版webshell后门查杀工具

[复制链接]

432

主题

573

帖子

2543

积分

核心成员

Rank: 8Rank: 8

积分
2543
发表于 2013-9-29 18:17:52 | 显示全部楼层 |阅读模式
最近几乎每天都有应急响应工作,自己写的一个linux下的webshell查杀小脚本,如果网站文件太多,打包太大,可以用这个脚本查杀一下,然后根据日志和时间再找其他的webshell,如果网站文件比较小,建议打包下来,用 {D盾Web后门查杀V1.2.6版本} 在windows下查杀,查杀脚本下载地址


使用说明:

1.查杀指定路径:python webshell.py 路径


2.按时间查找文件:python webshell.py 路径 “2013-09-28 00:00:00″


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-

import os
import sys
import re
import time

rulelist = [
'(\$_(GET|POST|REQUEST)\[.{0,15}\]\s{0,10}\(\s{0,10}\$_(GET|POST|REQUEST)\[.{0,15}\]\))',
'(base64_decode\([\'"][\w\+/=]{200,}[\'"]\))',
'(eval(\s|\n)*\(base64_decode(\s|\n)*\((.|\n){1,200})',
'((eval|assert)(\s|\n)*\((\s|\n)*\$_(POST|GET|REQUEST)\[.{0,15}\]\))',
'(\$[\w_]{0,15}(\s|\n)*\((\s|\n)*\$_(POST|GET|REQUEST)\[.{0,15}\]\))',
'(call_user_func\(.{0,15}\$_(GET|POST|REQUEST))',
'(preg_replace(\s|\n)*\(.{1,100}[/@].{0,3}e.{1,6},.{0,10}\$_(GET|POST|REQUEST))',
'(wscript\.shell)',
'(cmd\.exe)',
'(shell\.application)',
'(documents\s+and\s+settings)',
'(system32)',
'(serv-u)',
'(phpspy)',
'(jspspy)',
'(webshell)',
'(Program\s+Files)'
]

def Scan(path):
print(' 可疑文件 ')
print('########################################')
for root,dirs,files in os.walk(path):
for filespath in files:
if os.path.getsize(os.path.join(root,filespath))<1024000:
file= open(os.path.join(root,filespath))
filestr = file.read()
file.close()
for rule in rulelist:
result = re.compile(rule).findall(filestr)
if result:
print '文件:'+os.path.join(root,filespath)
print '恶意代码:'+str(result[0])[0:200]
print('最后修改时间:'+time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(os.path.getmtime(os.path.join(root,filespath)))))
print '\n\n'
break

#由文件最后修改时间扫描
def _Get_Time_Files(_path,_time):
_time = time.mktime(time.strptime(_time, '%Y-%m-%d %H:%M:%S'))
print('\n')
print(' 可疑文件 ')
print('########################################')
print('文件路径 最后修改时间 \n')

for _root,_dirs,_files in os.walk(_path):
for _file in _files:
if _file.find('.')!=-1:
_txt = _file[(_file.rindex('.')+1):].lower()

if _txt=='php' or _txt=='jsp':
_File_Time =os.path.getmtime(_root+'/'+_file)
if _File_Time>_time:
print(_root+'/'+_file+' '+ time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(os.path.getmtime(_root+'/'+_file))))


if len(sys.argv)!=3 and len(sys.argv)!=2:
print '【参数错误】:'
print '\t按恶意代码查杀: '+sys.argv[0]+' 目录名'
print '\t按修改时间查杀: '+sys.argv[0]+' 目录名 修改时间(格式:"2013-09-09 12:00:00")'
if os.path.lexists(sys.argv[1])==False:
print '提示:指定的扫描目录不存在--- 囧'

print('\n\n开始查杀:'+sys.argv[1])

if len(sys.argv)==2:
Scan(sys.argv[1])
else:
_Get_Time_Files(sys.argv[1],sys.argv[2])

print('提示:查杀完成-- O(∩_∩)O哈哈~')&#65279;



您可以更新记录, 让好友们知道您在做什么...
专业回帖 该用户已被删除
发表于 2013-9-29 20:34:37 | 显示全部楼层
学习了,谢谢分享、、、
854955425 该用户已被删除
发表于 2013-9-29 20:54:15 | 显示全部楼层
学习了,不错,讲的太有道理了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表