SOCLabs 更新了新的Windows检测挑战题目,《检测可疑的 ipconfig 执行》旨在帮助检测工程师学习和训练威胁检测。
本文介绍如何通过SOCLabs进行威胁检测的学习和训练。
威胁分析
根据题目要求可以看到要求我们去识别ipconfig命令的执行,并要求区分正常行为与异常行为。
挑战地址:https://www.soc-labs.top/zh/detections/98
ipconfig 是Windows系统中用来查看和管理网络配置的命令行工具。它可以显示当前计算机的IP地址、子网掩码、默认网关等网络配置信息,也能执行一些基本的网络管理操作。
我们知道,在企业中IT运维人员通常会执行ipconfig查看和排查网络,同时攻击者也会使用这个命令判断入侵机器的网段环境信息方便进一步横向移动。
IT运维人员通常会通过通过cmd执行ipconfig,这样的话cmd的父进程一般是explorer.exe
如果是攻击者执行ipconfig可能是通过木马直接调用ipconfig或者调用cmd再执行ipconfig。
规则编写
根据SOCLabs的题目描述可以看到,遥测日志使用的是Sysmon,Sysmon日志只会记录当前进程与父进程信息,不会进程祖父进程。
因此我们需要关联其他日志来找到祖父进程,在Sysmon日志中我们可以通过ProcessGuid与ParentProcessGuid进行关联。
由于我们需要使用ProcessGuid与ParentProcessGuid进行关联查询,因此需要使用支持关联查询的SIEM语言,Splunk与Kusto这两个对关联查询支持的比较好。
本文中我们使用Splunk的SPL语法进行检测。
首先需要找到所有ipconfig的执行记录
index=detectiontable Image="C:\\Windows\\System32\\ipconfig.exe"
根据查询结果可以看到父进程都是cmd.exe和 tailscaled.exe。
tailscaled.exe 虽然在攻击中可以作为内网穿透工具,会执行ipconfig修改网络信息。
但日志结果中多个终端都有这个程序,因此我们可以把该进程当做一个正常的业务白名单程序。
由于单纯的通过cmd.exe不用直接判断是否异常,因此我们需要在查询cmd的上级进程信息。
通过利用Splunk的join将 ParentProcessGuid 与 ProcessGuid 进行关联
index=detectiontable Image="C:\\Windows\\System32\\ipconfig.exe" | rename ProcessGuid as ProcGuid, ParentProcessGuid as ParentGuid | join type=left ParentGuid [ search index=windowsipcofnig | rename ProcessGuid as ParentGuid, ParentProcessGuid as GrandParentGuid, ParentImage as GrandParentImage | where EventId=1 | fields ParentGuid, GrandParentGuid, GrandParentImage ] | where EventId=1 | table _time host User Image CommandLine ParentImage GrandParentGuid GrandParentImage
重点是将ParentProcessGuid重命名为ParentGuid
这样就形成了ParentProcessGuid关联查询ProcessGuid。
只关注进程创建事件,所以过滤EventId=1
根据结果我们可以看到GrandParentImage 字段信息,包含了我们需要的祖父进程信息。
接下来就比较简单了,直接排除一些正常业务的tailscaled.exe,和explorer.exe。
首先排除tailscaled.exe
index=detectiontable Image="C:\\Windows\\System32\\ipconfig.exe" | rename ProcessGuid as ProcGuid, ParentProcessGuid as ParentGuid | join type=left ParentGuid [ search index=windowsipcofnig | rename ProcessGuid as ParentGuid, ParentProcessGuid as GrandParentGuid, ParentImage as GrandParentImage | where EventId=1 | fields ParentGuid, GrandParentGuid, GrandParentImage ] | where EventId=1 AND ParentImage!="C:\\Program Files\\Tailscale\\tailscaled.exe" | table _time host User Image CommandLine ParentImage GrandParentGuid GrandParentImage
再次排除explorer.exe
index=detectiontable Image="C:\\Windows\\System32\\ipconfig.exe" | rename ProcessGuid as ProcGuid, ParentProcessGuid as ParentGuid | jointype=left ParentGuid [ searchindex=windowsipcofnig | rename ProcessGuid as ParentGuid, ParentProcessGuid as GrandParentGuid, ParentImage as GrandParentImage | where EventId=1 | fields ParentGuid, GrandParentGuid, GrandParentImage ] | where EventId=1AND ParentImage!="C:\\Program Files\\Tailscale\\tailscaled.exe" | where GrandParentImage!="C:\Windows\explorer.exe" | table _time host User Image CommandLine ParentImage GrandParentGuid GrandParentImage
可以看到结果只剩下shellcode.exe
在实际工作中我们只需要分析shellcode.exe就可以判断是不是木马程序就行了。
点击提交按钮,可以直接验证结果是否正确
至此我们就完成了整个检测挑战。
转自:https://mp.weixin.qq.com/s/AcT-PiVI79jUnmo3I8amRQ?mpshare=1&scene=1&srcid=0620A6xMWwxsEWjVnSUWcIfW&sharer_shareinfo=0c5afb106eef51b5c2b23470e15064f2&sharer_shareinfo_first=0c5afb106eef51b5c2b23470e15064f2&color_scheme=light#rd