前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor。

首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xor ddos分析http://www.cnblogs.com/goabout2/p/4888651.html),想要杀掉的话,需要先通过kill –stop挂起主进程,再删除其他的文件,但是由于xor的进程名是随机值,同时主机上还有有gates木马(gates最显著的特征就是会替换系统文件ps,lsof,ss,netstat),因此为了避嫌,脚本必须隔离系统命令。

此处通过的是遍历/proc/pid/maps文件获取所有进程对应的程序路径,通过该路径与特征值匹配出的路径对比,从而确定主进程的pid。

import os
import re
import sys
import time # property of the virus
sigin = "m4S4nAC/nA"
filepath = "/boot/dingzhi_random_10_word1;/lib/udev/udev"
delpath = "/etc/cron.hourly/cron.sh;/etc/init.d/fromdingzhi_" #read file
def readfile(path):
file = open(path)
try:
content = file.read()
finally:
file.close()
return content #scan the filesystem in the os with specify eigenvalue
def scanforeigen(path,word):
for filename in os.listdir(path):
fp = os.path.join(path,filename)
if os.path.isfile(fp):
print fp
with open(fp) as f:
for line in f:
if word in line:
print "find in the file:" + fp
return fp
break
elif os.path.isdir(fp):
scanforeigen(fp,word) #check the specify dir thrugh property return the path in a lis
def check():
targetlist = []
bootfile = scanforeigen("/boot",sigin)
if bootfile is not None and bootfile != '':
bootfilename = bootfile.split("/")[-1]
if len(bootfilename) == 10 and re.match('^[a-z]+$',bootfilename):
targetlist.append(bootfile)
libfile = scanforeigen("/lib/udev",sigin)
if libfile is not None and libfile != '':
libfilename = libfile.split("/")[-1]
if libfilename == "udev":
targetlist.append(libfile)
return targetlist def kill():
itemlist = []
targetlist = check()
print targetlist
boot = targetlist[0]
print "boot is " + boot
bootname = boot.split('/')[-1]
for itemnum in os.listdir("/proc"): #throught the filename to find the pid and return
if itemnum.isdigit():
print "the dir is " + itemnum
path = "/proc/" + itemnum + "/maps"
print path
mapscontent = readfile(path)
if bootname in mapscontent:
print "the pid of the " + bootname + " is " + itemnum
itemlist.append(itemnum)
print itemlist #stop the father process
for item in itemlist:
print "item is " + item
cmd = "kill -STOP " + item
os.popen(cmd)
time.sleep(5)
print "going sleeping" #delete the file
for target in targetlist:
print "del the" + target
cmd = "rm " + target
os.popen(cmd) dellist = delpath.split(';')
for delfile in dellist:
print "the delfile" + delfile
if delfile.split('/')[-1] == "fromdingzhi_":
delfile = delfile.replace("fromdingzhi_",bootname) print "del the " + delfile
cmd = "rm " + delfile
os.popen(cmd) #kill the process
cmd = "kill -9 " + item
print cmd
os.popen(cmd) if __name__ == '__main__':
#list = check()
if sys.argv[1] == "-check":
list = check()
elif sys.argv[1] == '-kill':
kill()

对于gates木马需要注意的是,样本运行第一次的时候的文件不会删除,通过二进制分析的时候是获取不到该样本的路径的,索性该处的路径保存在/etc/init.d/DbSecuritySpt的启动文件中。

import os
import sys
import time #linux.tragon.bill.gates sigin = "88FD2FE8EF8D51263B037677FD30F25CBFEB57F759F711FB41956288A85E9655F"
initpaht = "/etc/init.d/selinux;/etc/init.d/DbSecuritySpt"
filedir = "/usr/bin;/usr/sbin;/bin;/usr/bin/bsd-port;/usr/bin/dpkgd"
filepath = "/usr/bin/.sshd;/usr/bin/bsd-port/getty"
delpath = "/usr/bin/ps;/usr/bin/ss;/usr/bin/lsof;/usr/bin/netsata;/usr/sbin/ps;/usr/sbin/ss;/usr/sbin/lsof;/usr/sbin/netsata;/bin/ps;/bin/ss;/bin/lsof;/bin/netsata;/etc/init.d/selinux;/etc/init.d/DbSecuritySpt;/tmp/moni.lod;/tmp/gates.lod;/usr/bin/bsd-port/getty.lock"
configfile = "/tmp/moni.lod;/tmp/gates.lod;/usr/bin/bsd-port/getty.lock" findlist = [] #read file
def readfile(path):
file = open(path)
try:
content = file.read()
finally:
file.close()
return content #scan the filesystem in the os with specify eigenvalue
def scanforeigen(path,word):
for filename in os.listdir(path):
fp = os.path.join(path,filename)
if os.path.isfile(fp):
print fp
with open(fp) as f:
for line in f:
if word in line:
print "find in the file:" + fp
findlist.append(fp)
return fp elif os.path.isdir(fp):
scanforeigen(fp,word) #check the specify dir thrugh property return the path in a lis
def check():
targetlist = []
dirlist = filedir.split(";")
for dirpath in dirlist:
checkfile = scanforeigen(dirpath,sigin)
'''
print "the checkfile is :"
print checkfile
targetlist.append(checkfile)
'''
#start kill
def kill():
piddic = {}
check()
print findlist
#get pid
if findlist is not None:
conflist = configfile.split(";")
for confpath in conflist:
content = readfile(confpath)
print "the path " + confpath + "content is " + content
piddic[confpath] = content
print piddic #get the filepath restart by DbSecuritySpt
specialpath = readfile("/etc/init.d/DbSecuritySpt")
specialpath = specialpath[12:]
print "dd" + specialpath #stop the process in the pidlist
for key in piddic:
cmd = "kill -STOP " + piddic[key]
os.popen(cmd) #start to delete the file
delfile = delpath.split(";")
for delfielpath in delfile:
cmd = "rm " + delfielpath
os.popen(cmd) cmd = "rm " + specialpath
os.popen(cmd) cmd = "cp /usr/bin/dpkgd/ps /bin"
os.popen(cmd)
cmd = "cp /usr/bin/dpkgd/ss /bin"
os.popen(cmd)
cmd = "cp /usr/bin/dpkgd/lsof /bin"
os.popen(cmd)
cmd = "cp /usr/bin/dpkgd/netstat /bin"
os.popen(cmd) for key in piddic:
cmd = "kill -9 " + piddic[key]
os.popen(cmd) if __name__ == '__main__':
#list = check()
if sys.argv[1] == "-check":
list = check()
elif sys.argv[1] == '-kill':
kill()

xor和gates的专杀脚本的更多相关文章

  1. DedeCMS顽固木马后门专杀工具V2.0实现方式研究

    catalog . 安装及使用方式 . 检查DEDECMS是否为最新版本 . 检查默认安装(install)目录是否存在 . 检查默认后台目录(dede)是否存在 . 检查DedeCMS会员中心是否关 ...

  2. 【旧文章搬运】PE感染逆向之修复(Serverx.exe专杀工具出炉手记)

    原文发表于百度空间,2008-10-4看雪论坛发表地址:https://bbs.pediy.com/thread-73948.htm================================== ...

  3. DesktopLayer.exe专杀

    这两天发现电脑卡慢. 同事电脑发现病毒,而后装上杀软后(一直在裸奔~~~),发现自己电脑也存在. DesktopLayer.exe 会有以下几个行为: 第一,会在C:\Program Files (x ...

  4. 病毒木马查杀实战第011篇:QQ盗号木马之专杀工具的编写

    前言 由于我已经在<病毒木马查杀第004篇:熊猫烧香之专杀工具的编写>中编写了一个比较通用的专杀工具的框架,而这个框架对于本病毒来说,经过简单修改也是基本适用的,所以本文就不讨论那些重叠的 ...

  5. 病毒木马查杀实战第017篇:U盘病毒之专杀工具的编写

    前言 经过前几次的讨论,我们对于这次的U盘病毒已经有了一定的了解,那么这次我们就依据病毒的行为特征,来编写针对于这次U盘病毒的专杀工具. 专杀工具功能说明 因为这次是一个U盘病毒,所以我打算把这次的专 ...

  6. r0capture安卓应用层通杀脚本-使用文档

    本文所有教程及源码.软件仅为技术研究.不涉及计算机信息系统功能的删除.修改.增加.干扰,更不会影响计算机信息系统的正常运行.不得将代码用于非法用途,如侵立删! r0capture安卓应用层通杀脚本-使 ...

  7. [转帖] securebootthemes 挖矿病毒的说明 http://blog.netlab.360.com/msraminer-qian-fu-yi-jiu-de-wa-kuang-jiang-shi-wang-luo/ 原文为毛不给一个专杀工具呢.

    MsraMiner: 潜伏已久的挖矿僵尸网络 2017 年 11 月底,我们的 DNSMon 系统监测到几个疑似 DGA 产生的恶意域名活动有异常.经过我们深入分析,确认这背后是一个从 2017 年 ...

  8. 数列[专杀Splay版]

    时间限制: 3 Sec  内存限制: 128 MB提交: 49  解决: 7 题目描述 输入一个数列,你需要进行如下操作:  1. 把编号为I的数值改为K  2. 输出从小到大排序后第k个数 输入 输 ...

  9. 【转】BAT 批处理脚本 教程

    第一章 批处理基础第一节 常用批处理内部命令简介批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT或者CMD.这些命令统称批处理命令.小知识:可以在 ...

随机推荐

  1. noi-openjudge[4.7搜索]怀表问题

    为啥我觉得这是个DP-.f[i][j][k][l]表示四种零件分别用了i,j,k,l个的方案数.然后发现这样不能保证表一定能接在表链首尾,也不知道状态之间如何转移,那么加一维变成f[i][j][k][ ...

  2. ubuntu使用doxygen

    1.安装 sudo apt-get install doxygen按tab键 doxygen        doxygen-dbg    doxygen-doc    doxygen-gui    d ...

  3. strlen()和sizeof()求数组长度

    在字符常量和字符串常量的博文里有提: 求字符串数组的长度 标准库函数strlen(s)可以返回字符串s的长度,在头文件<string.h>里. strlen(s)的判断长度的依据是(s[i ...

  4. QT中使用函数指针

    想仿命令行,所以定义了一个类,让一个String 对应一个 function,将两者输入list容器. 类中定义了 QString commandStr; void (MainWindow::*com ...

  5. Html5 杂记

    (一):html5的声明 <!DOCTYPE html> 注意:声明必须是 HTML 文档的第一行,位于 <html> 标签之前.   声明不是 HTML 标签:它是指示 we ...

  6. 作为一名前端er,从武汉来到深圳三个月有感

    来到深圳已经三个月了,从最开始的担心自己的能力不够怕不能够在深圳这个互联网产品及其发达的城市立足下来,到现在已经慢慢地拾起了一丁点的信心了 (虽然还有很多知识是不够的.但是相当于之前我的,我是觉得我已 ...

  7. Backbone 学习笔记

    Backbone 是一款基于模型-视图-控制器 MVC 模式的轻量级javascript 框架 ,可以用来帮助开发人员创建单页Web应用. 借助Backbone 我们可以使用REST的方式来最小化客户 ...

  8. druid 配置

    连接池配置,以及相关配置 <bean id="logFilter" class="com.alibaba.druid.filter.logging.Slf4jLog ...

  9. Asp.Net Core--自定义基于策略的授权

    翻译如下: 在封面下,角色授权和声明授权使用需求,需求的处理程序和预配置的策略. 这些构建块允许您在代码中表示授权评估,从而允许更丰富,可重用和容易测试的授权结构. 授权策略由一个或多个需求组成,并在 ...

  10. ASP.NET Core--基于授权的视图

    翻译如下: 开发人员通常希望基于当前用户身份显示,隐藏或以其他方式修改UI. 您可以通过依赖注入访问MVC视图中的授权服务. 将授权服务注入Razor视图,请使用@inject指令,例如: @inje ...