前段时间的一次样本,需要给出专杀,应急中遇到的是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. Spring retry基本使用

    Spring retry基本使用 背景介绍 在实际工作过程中,重试是一个经常使用的手段.比如MQ发送消息失败,会采取重试手段,比如工程中使用RPC请求外部服务,可能因为网络 波动出现超时而采取重试手段 ...

  2. php 错误

    ini_set('display_errors', '1');error_reporting(E_ALL ^ E_NOTICE);   有时有了其它框架 应该用它的配置,要不然,你改了,它又改回去了: ...

  3. jmeter 运行多个sql

    1.关键就是"allowMultiQueries=true" database url:jdbc:mysql://127.0.0.1:3306/api?useUnicode=tru ...

  4. jQuery动态增删改查表格信息,可左键/右键提示

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. grunt自动化构建工具

    一.什么是grunt? 是基于nodejs的项目构建工具,grunt和grunt插件是通过npm安装并管理的,npm是node.js的包管理器 二.为什么要用grunt? 自动化.对于反复重复的任务, ...

  6. ArcEngine地图窗口指定区域导出指定DPI多格式---delphi/C#实现

    delphi/C#实现,其他语言稍微改下就行了.AE的编码各个语言都差不多,这里也没用到某一语言的特性. 函数特点: 1.可以精确导出指定范围的图形要素 2.支持多格式.TIF, .EMF,.GIF, ...

  7. log4net各种Filter使用【转】

    log4net各种Filter使用[转] log4net里面的filter类常用的为:      1.DenyAllFilter         拒绝所用的日志输出         <filte ...

  8. C# 自定义Section

    一.在App.config中自定义Section,这个使用了SectionGroup <?xml version="1.0" encoding="utf-8&quo ...

  9. [NHibernate]ISessionFactory配置

    系列文章 [Nhibernate]体系结构 引言 在上篇文章学习了orm和nhibernate相关概念,这篇文章主要学习ISessionFactory如何配置. 因为NHibernate被设计为可以在 ...

  10. javascript 高级程序设计 -有感

    本来我想写一个高级程序设计总结的,结果发现我进入了一扇门,里面所有的字都要逐字逐句的理解,所有描述已经是非常精炼了,我最初的想法无异于老鼠吃大象. 我现在记录的是我在看这本时的感想. 2015.4月9 ...