跳转至

T1027-004-win-传输后编译

来自ATT&CK的描述

攻击者可能试图通过将文件作为未编译的代码提供给目标组织,使有效载荷难以被发现和分析。基于文本的源代码文件可能会破坏针对可执行文件的保护措施的分析和审查。这些有效载荷在执行前需要进行编译;通常是通过csc.exe或GCC/MinGW等本地工具。

源代码有效载荷也可能被加密、编码或嵌入到其他文件中,例如那些作为钓鱼网站的文件。有效载荷也可能以本地操作系统无法识别的格式交付(例如:macOS/Linux上的EXEs),然后再通过捆绑的编译器和执行框架(重新)编译成适当的可执行二进制文件。

测试案例

csc.exe是微软.NET Framework 中的C#语言编译器。

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:#{output_file} #{input_file}

检测日志

Windows安全日志/Sysmon日志

测试复现

测试1 COMPILE AFTER DELIVERY USING CSC.EXE

C:\Users\zhuli>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:C:\Users\zhuli\Desktop\TevoraAutomatedRTGui\atomic-red-team-master\atomics\T1027.004\src\calc.exe C:\Users\zhuli\Desktop\TevoraAutomatedRTGui\atomic-red-team-master\atomics\T1027.004\src\calc.cs
Microsoft (R) Visual C# Compiler version 4.8.3761.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

日志留痕

可参考Windows 安全日志4688事件说明、Windows Sysmon安全日志1事件说明。

日志名称:          Microsoft-Windows-Sysmon/Operational
来源:            Microsoft-Windows-Sysmon
日期:            2022/1/9 20:47:06
事件 ID:         1
任务类别:          Process Create (rule: ProcessCreate)
级别:            信息
关键字:           
用户:            SYSTEM
计算机:           zhuli.qax.com
描述:
Process Create:
RuleName: technique_id=T1059,technique_name=Command-Line Interface
UtcTime: 2022-01-09 12:47:06.034
ProcessGuid: {78c84c47-d94a-61da-9908-000000000800}
ProcessId: 5264
Image: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe
FileVersion: 4.8.3761.0 built by: NET48REL1
Description: Visual C# Command Line Compiler
Product: Microsoft® .NET Framework
Company: Microsoft Corporation
OriginalFileName: csc.exe
CommandLine: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe  /out:C:\Users\zhuli\Desktop\TevoraAutomatedRTGui\atomic-red-team-master\atomics\T1027.004\src\calc.exe C:\Users\zhuli\Desktop\TevoraAutomatedRTGui\atomic-red-team-master\atomics\T1027.004\src\calc.cs
CurrentDirectory: C:\Users\zhuli\
User: QAX\zhuli
LogonGuid: {78c84c47-3b57-61d8-525f-090000000000}
LogonId: 0x95F52
TerminalSessionId: 1
IntegrityLevel: Medium
Hashes: SHA1=93CF877F5627E55EC076A656E935042FAC39950E,MD5=23EE3D381CFE3B9F6229483E2CE2F9E1,SHA256=4240A12E0B246C9D69AF1F697488FE7DA1B497DF20F4A6F95135B4D5FE180A57,IMPHASH=EE1E569AD02AA1F7AECA80AC0601D80D
ParentProcessGuid: {78c84c47-d947-61da-9708-000000000800}
ParentProcessId: 4340
ParentImage: C:\Windows\System32\cmd.exe
ParentCommandLine: "C:\Windows\system32\cmd.exe" 
ParentUser: QAX\zhuli

检测规则/思路

sigma规则

title: 使用CSC.EXE对代码进行编译
status: experimental
author: 12306Br0
date: 2022/01/09
references:
    - attack.t1027
logsource:
    product: windows
    service: sysmon
detection:
    selection:
        EventID: 1 #sysmon日志,进程创建
        Image: '*/csc.exe' #进程名称
        CommandLine: '/out:' #进程命令行
    condition: selection
level: low

建议

监测常见编译器的执行文件路径和命令行参数,如csc.exe和GCC/MinGW,并与其他可疑行为相关联,以减少来自正常用户和管理员行为的误报。有效载荷的编译也可能产生文件创建或文件写入事件。寻找非本地二进制格式和跨平台的编译器和执行框架,如Mono,并确定它们在系统上是否有合法用途。通常情况下,这些应该只在特定和有限的情况下使用,如用于软件开发。

参考推荐

MITRE-ATT&CK-T1027-004

https://attack.mitre.org/techniques/T1027/004

跟着ATT&CK学安全之defense-evasion

https://snappyjack.github.io/articles/2020-01/%E8%B7%9F%E7%9D%80ATT&CK%E5%AD%A6%E5%AE%89%E5%85%A8%E4%B9%8Bdefense-evasion