我们来自五湖四海,不为别的,只因有共同的爱好,为中国互联网发展出一分力!
领航时时彩重庆版

重庆时时彩开奖破解器:扫描目录下的php文件,是否含有木马特征

2014年07月26日05:23 阅读: 27470 次

领航时时彩重庆版 www.9nwl5.cn 标签: 扫描目录下的php文件,是否含有木马特征

 shell_checkl

 

?
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
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
#-*- encoding:UTF-8 -*-
###
## @package
## @desc 扫描目录下的php文件,是否含有木马特征,注意,不是“木马扫描”
## @useage python shell_check.py /your/web/path/ 1=是否递归
###
import os
import sys
import re
import time
def listdir(dirs,liston='0'):
    flog = open(os.getcwd()+"/check_php_shell.log","a+")
    if not os.path.isdir(dirs):
        print "directory %s is not exist"% (dirs)
        return
    lists = os.listdir(dirs)
    for list in lists:
        filepath = os.path.join(dirs,list)
        if os.path.isdir(filepath):
            if liston == '1':
                listdir(filepath,'1')
        elif os.path.isfile(filepath):
            filename = os.path.basename(filepath)
            if re.search(r"\.(?:php|inc|html?)$", filename, re.IGNORECASE):
                i = 0
                iname = 0
                f = open(filepath)
                while f:
                    file_contents = f.readline()
                    if not file_contents:
                        break
                    i += 1
                    match = re.search(r'''(?P<function>\b(?:include|require)(?:_once)?\b)\s*\(?\s*["'](?P<filename>.*?(?<!\.(?:php|inc)))["']''', file_contents, re.IGNORECASE| re.MULTILINE)
                    if match:
                        function = match.group("function")
                        filename = match.group("filename")
                        if iname == 0:
                            info = '\n[%s] :\n'% (filepath)
                        else:
                            info = ''
                        info += '\t|-- [%s] - [%s]  line [%d] \n'% (function,filename,i)
                        flog.write(info)
                        print info
                        iname += 1
                      
                    match = re.search(r'\b(?P<function>eval|proc_open|popen|shell_exec|exec|passthru|system)\b\s*\(', file_contents, re.IGNORECASE| re.MULTILINE)
                    if match:
                        function = match.group("function")
                        if iname == 0:
                            info = '\n[%s] :\n'% (filepath)
                        else:
                            info = ''
                        info += '\t|-- [%s]  line [%d] \n'% (function,i)
                        flog.write(info)
                        print info
                        iname += 1
                      
                    match = re.findall(r'(\$[a-z0-9_]*?\s*?\(.*?\))', file_contents, re.IGNORECASE)
                    if match:
                        if iname == 0:
                            info = '\n[%s] :\n'% (filepath)
                        else:
                            info = ''
                        info += '\t|-- [%s]  line [%d] \n'% (match[0],i)
                        flog.write(info)
                        print info
                        iname += 1
  
                f.close()
    flog.close()
if '__main__' == __name__:
    argvnum = len(sys.argv)
    liston = '0'
    if argvnum == 1:
        action = os.path.basename(sys.argv[0])
        print "Command is like:\n   %s D:\wwwroot\ \n   %s D:\wwwroot\ 1    -- recurse subfolders"% (action,action)
        quit()
    elif argvnum == 2:
        path = os.path.realpath(sys.argv[1])
        listdir(path,liston)
    else:
        liston = sys.argv[2]
        path = os.path.realpath(sys.argv[1])
        listdir(path,liston)
    flog = open(os.getcwd()+"/check_php_shell.log","a+")
    ISOTIMEFORMAT='%Y-%m-%d %X'
    now_time = time.strftime(ISOTIMEFORMAT,time.localtime())
    flog.write("\n----------------------%s checked ---------------------\n"% (now_time))
    flog.close()

 

分享到: 更多
©2018 安全焦点 版权所有.

  • 奚国华委员:新兴际华将党建六大优势转化为发展优势 2018-12-06
  • 创业女青年哈丽娟:世界是自己的 与他人没关系 2018-12-06
  • 移植2胚怀5胎 一针减3化风险 十堰市人民医院再创生命奇迹 2018-11-06
  • 首届妈祖信俗“立德”论坛成功举办 2018-10-25
  • 郧西男孩两条腿“长”在一起 十堰市人民医院手术整形帮他迈开双腿 2018-10-25
  • 重磅 江西省委副书记李炳军同志任省委党校校长 2018-10-19
  • 商务部新闻发言人对美白宫6月18日声明发表谈话 2018-10-12
  • 从献血条件,看看你的身体是否达标 2018-09-26
  • 全国“非遗”保护工作先进名单公布 2018-09-26
  • 储大同 中国医学科学院肿瘤医院首席科学家 2018-08-15
  • 【理上网来·喜迎十九大】扶贫也创新!十八大以来年均减贫人数超1300万 获历史突破 2018-08-15
  • 开创美丽中国建设新局面 2018-08-13
  • 毛泽东三游故宫看了些什么 2018-08-13
  • 独家视频:新时代来啦! 2018-08-12
  • 旅游市场再创佳绩端午假期河北接待游客2026.77万 揽金147.79亿 2018-08-12
  • 102| 940| 640| 107| 989| 451| 910| 532| 642| 727|