发布于 2014-08-09 14:14:31 | 189 次阅读 | 评论: 3 | 来源: 网友投递

这里有新鲜出炉的Python教程,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


本文是一个python编写的查找webshell脚本的代码,除了查找webshell功能之外还具有白名单功能,以及发现恶意代码发送邮件报警等功能,感兴趣的朋友可以自己测试一下看看效果。

代码如下:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import os
import sys
import re
import smtplib

#设定邮件
fromaddr = "smtp.qq.com"
toaddrs = ["test@qq.com"]
username = "test"
password = "xxxxxx"


#设置白名单
pass_file = ["api_ucenter.php"]

#定义发送邮件函数
def sendmail(toaddrs,sub,content):
  '发送邮件模块'
  # Add the From: and To: headers at the start!
  msg = ("From: %srnTo: %srnSubject: %srnrn"
      % (fromaddr, ", ".join(toaddrs), sub))
  msg += content
  server = smtplib.SMTP('mail.funshion.com', 25,)
  server.login(username, password)
  server.sendmail(fromaddr, toaddrs, msg)
  server.quit()

#设置搜索webshell特征码
rulelist = [
  '($_(GET|POST|REQUEST)[.{0,15}]($_(GET|POST|REQUEST)[.{0,15}]))',
  '(base64_decode(['"][w+/=]{200,}['"]))',
  'eval(base64_decode(',
  '(eval($_(POST|GET|REQUEST)[.{0,15}]))',
  '(assert($_(POST|GET|REQUEST)[.{0,15}]))',
  '($[w_]{0,15}($_(POST|GET|REQUEST)[.{0,15}]))',
  '(wscript.shell)',
  '(gethostbyname()',
  '(cmd.exe)',
  '(shell.application)',
  '(documentss+ands+settings)',
  '(system32)',
  '(serv-u)',
  '(提权)',
  '(phpspy)',
  '(后门)',
  '(webshell)',
  '(Programs+Files)',
  'www.phpdp.com',
  'phpdp',
  'PHP神盾',
  'decryption',
  'Ca3tie1',
  'GIF89a',
  'IKFBILUvM0VCJD/APDolOjtW0tgeKAwA',
  ''e'.'v'.'a'.'l'',
]

def Scan(path):
  for root,dirs,files in os.walk(path):
    for filespath in files:
      isover = False
      if '.' in filespath:
        ext = filespath[(filespath.rindex('.')+1):]
        if ext=='php' and filespath not in pass_file:
          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])
              print 'nn'
              sendmail(toaddrs,"增值发现恶意代码",'文件:'+os.path.join(root,filespath)+"n" + '恶意代码:'+str(result[0]))
              break

try:
  if os.path.lexists("/home/web_root/"):
    print('nn开始扫描:'+ "/home/web_root/")
    print('        可疑文件         ')
    print('########################################')
    Scan("/home/web_root/")
    print('提示:扫描完成--~')
  else:
    print '提示:指定的扫描目录不存在--- '
except IndexError:
  print "请指定扫描文件目录" 


最新网友评论  共有(3)条评论 发布评论 返回顶部
chang 发布于2014-09-28 07:30:25
执行发不了邮件。
  • 2楼  PHPERZ网友 回复于2014-09-28 11:57:37
    这得需要设置smtp服务器呢,
  • 支持(0)  反对(0)  回复
    PHPERZ网友 发布于2014-08-09 14:36:04
    这脚本不错.
    支持(0)  反对(0)  回复

    Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务