今天接到了内网的检测服务器告警,检测到我的主机对外扫描445端口

本次监测使用了2台基于VMware ESXi架构的虚拟服务器,IP及系统架构如下

  • 10.16.11.51 CentOS7【监测机】
  • 10.16.11.15 Windows Server 2008 R2【诱捕机】

脚本编写

脚本使用Python3编写,运行于CentOS7虚拟机(10.16.11.51)上,由于感染后的机器特征为向外部扫描445端口,如下图所示

被感染主机的网络连接

脚本编写思路为监听445端口,如有连接即写入文件并记录连接IP
代码如下

# 服务器
import socket
import threading
import time
# 处理客户端请求
# 监听任意地址
IP_ADDRESS = '0.0.0.0'
# 记录的文件名
FILENAME = 'log.txt'
# 监听端口
PORT = 445

def printalert(string):
print('\033[1;31m ' + string + ' \033[0m')

def printsuccess(string):
print('\033[1;32m ' + string + ' \033[0m')

def printwarning(string):
print('\033[1;33m ' + string + ' \033[0m')

def printinfo(string):
print('\033[0;34m ' + string + ' \033[0m')

class tcp_server():
def __init__(self):
self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.tcp_socket.bind((IP_ADDRESS, PORT))
self.tcp_socket.listen(250)
self.proceses = []
printsuccess('Server Start Success,Waiting For Connect....\n')

def run_server(self):
while True:
sock, addr = self.tcp_socket.accept()
# 创建新线程来处理每个客户端连接
t = threading.Thread(target=self.tcp_server, args=(sock, addr))
t.start()
t.join()

def tcp_server(self, sock, addr):
# 事件产生时间
TIME = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
printinfo('[i] Accept new connection from %s:%s' % addr + ' ...at [' + str(TIME) + ']\n')
printinfo('当前线程:' + threading.current_thread().name + '\n')
self.writelog(addr)
sock.close()
printinfo('[-] Connection from %s:%s closed \n' % addr)

# 写日志
def writelog(self, addr):
# 事件产生时间
TIME = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
with open(FILENAME, 'r') as file:
line = file.read().splitlines()
if addr[0] in line:
printwarning('[!] Detect ' + str(addr[0]) + ' Connect ' + str(PORT) + ' Port At [' + str(TIME) + '] And This IP Has Been Recorded!\n')
else:
with open(FILENAME, 'a+') as file1:
file1.write(str(addr[0]) + '\n')
printalert('[+] Detect ' + str(addr[0]) + ' Connect ' + str(PORT) + ' Port At [' + str(TIME) + '] .\n')

def main():
s = tcp_server()
s.run_server()

if __name__ == '__main__':

main()

运行后如图所示

1559578344395

当有连接发生时输出相关内容(连接IP、端口、事件产生时间),并记录到脚本运行目录下的log.txt

1559578408835

1559578423971

诱捕

10.16.11.15主机关闭防火墙,等待一段时间后被成功植入病毒

分析

被成功攻陷后被植入相关工具(NSA武器库),武器库的路径位于C:\Windows\NetworkDistribution

1

同时系统进程中出现了一个使用cmd启动的非system32目录下的svchost程序

2

系统服务中被随机创建了一个服务,本次诱捕机中的服务为ApplicationProtocolHost

3

并在C:\Windows\System32下释放与服务名称一致的dll文件,用于被系统正常的svchost启动

4

由于病毒的服务名称会从以下字符串中拼凑,所以服务名并不为鉴别病毒的可靠方式

5

主服务的命名规则为“字符串1+字符串2+字符串3”,如上面提及的ApplicationProtocolHost,即Application+Protocol+Host

字符串1列表 字符串2列表 字符串3列表
Windows Update Service
Microsoft Time Host
Network NetBIOS Client
Remote RPC Event
Function Protocol Manager
Secure SSDP Helper
Application UPnP System

但是由于系统为中文操作系统,因此可以通过该服务的描述进行甄别

6

WannaMine 4.0挖矿主体病毒文件为dllhostex.exeC:\Windows\System32\dllhostex.exe),负责挖取门罗币。

7

清理方式

  1. 禁用随机拼凑命名的服务。
  2. 使用XueTrPChunter)卸载异常的svchost非system32目录下的svchost程序)的挂载的模块(即上文提到的随机拼凑命名的.dll并删除
  3. 结束异常进程
  4. 删除随机拼凑命名的服务。
  5. 删除C:\Windows\System32\dllhostex.exeC:\Windows\NetworkDistribution\
  6. 安装MS17-010补丁