{"id":"dcaa3f04-70c3-427a-80b4-b870d73c94c4","title":"Dynamic .NET Compilation Via Csc.EXE","description":"Detects execution of \"csc.exe\" to compile .NET code. Attackers often leverage this to compile code on the fly and use it in other stages.","author":"Florian Roth (Nextron Systems), X__Junior (Nextron Systems)","status":"test","level":"medium","date":"2019-08-24","modified":"2026-03-23","tags":["attack.stealth","attack.t1027.004"],"technique_ids":["T1027.004"],"logsource":{"category":"process_creation","product":"windows"},"falsepositives":["Legitimate software from program files - https://twitter.com/gN3mes1s/status/1206874118282448897","Legitimate Microsoft software - https://twitter.com/gabriele_pippi/status/1206907900268072962","Ansible"],"references":["https://securityboulevard.com/2019/08/agent-tesla-evading-edr-by-removing-api-hooks/","https://www.clearskysec.com/wp-content/uploads/2018/11/MuddyWater-Operations-in-Lebanon-and-Oman.pdf","https://app.any.run/tasks/c6993447-d1d8-414e-b856-675325e5aa09/","https://twitter.com/gN3mes1s/status/1206874118282448897","https://github.com/redcanaryco/atomic-red-team/blob/b27a3cb25025161d49ac861cb216db68c46a3537/atomics/T1027.004/T1027.004.md#atomic-test-1---compile-after-delivery-using-cscexe"],"source_path":"rules/windows/process_creation/proc_creation_win_csc_susp_dynamic_compilation.yml","source_sha256":"887d7fea04b88a0e98d9f3fb4dc814f6956b6eb208df36d13242932c2a6930a5","source_url":"https://github.com/anpa1200/sigma/blob/b249e9683190cffdcaf188ccbfb90bf4759844e1/rules/windows/process_creation/proc_creation_win_csc_susp_dynamic_compilation.yml","license":"Detection Rule License 1.1","license_url":"https://github.com/SigmaHQ/Detection-Rule-License/blob/main/LICENSE.Detection.Rules.md","yaml":"title: Dynamic .NET Compilation Via Csc.EXE\nid: dcaa3f04-70c3-427a-80b4-b870d73c94c4\nstatus: test\ndescription: Detects execution of \"csc.exe\" to compile .NET code. Attackers often leverage this to compile code on the fly and use it in other stages.\nreferences:\n    - https://securityboulevard.com/2019/08/agent-tesla-evading-edr-by-removing-api-hooks/\n    - https://www.clearskysec.com/wp-content/uploads/2018/11/MuddyWater-Operations-in-Lebanon-and-Oman.pdf\n    - https://app.any.run/tasks/c6993447-d1d8-414e-b856-675325e5aa09/\n    - https://twitter.com/gN3mes1s/status/1206874118282448897\n    - https://github.com/redcanaryco/atomic-red-team/blob/b27a3cb25025161d49ac861cb216db68c46a3537/atomics/T1027.004/T1027.004.md#atomic-test-1---compile-after-delivery-using-cscexe\nauthor: Florian Roth (Nextron Systems), X__Junior (Nextron Systems)\ndate: 2019-08-24\nmodified: 2026-03-23\ntags:\n    - attack.stealth\n    - attack.t1027.004\nlogsource:\n    category: process_creation\n    product: windows\ndetection:\n    selection_img:\n        Image|endswith: '\\csc.exe'\n    selection_susp_location_1:\n        CommandLine|contains:\n            - ':\\Perflogs\\'\n            - ':\\Users\\Public\\'\n            - '\\AppData\\Local\\Temp\\' # User execution\n            - '\\Temporary Internet'\n            - '\\Windows\\Temp\\' # Admin execution\n    selection_susp_location_2:\n        - CommandLine|contains|all:\n              - ':\\Users\\'\n              - '\\Favorites\\'\n        - CommandLine|contains|all:\n              - ':\\Users\\'\n              - '\\Favourites\\'\n        - CommandLine|contains|all:\n              - ':\\Users\\'\n              - '\\Contacts\\'\n        - CommandLine|contains|all:\n              - ':\\Users\\'\n              - '\\Pictures\\'\n    selection_susp_location_3:\n        CommandLine|re: '(?:[Pp]rogram[Dd]ata|%(?:[Ll]ocal)?[Aa]pp[Dd]ata%|\\\\[Aa]pp[Dd]ata\\\\(?:[Ll]ocal(?:[Ll]ow)?|[Rr]oaming))\\\\[^\\\\]{1,256}$'\n    filter_main_programfiles:\n        # Note: this is a generic filter. You could baseline execution in your env for a more robust rule\n        ParentImage|startswith:\n            - 'C:\\Program Files (x86)\\' # https://twitter.com/gN3mes1s/status/1206874118282448897\n            - 'C:\\Program Files\\' # https://twitter.com/gN3mes1s/status/1206874118282448897\n    filter_main_sdiagnhost:\n        ParentImage: 'C:\\Windows\\System32\\sdiagnhost.exe' # https://twitter.com/gN3mes1s/status/1206874118282448897\n    filter_main_w3p:\n        ParentImage: 'C:\\Windows\\System32\\inetsrv\\w3wp.exe' # https://twitter.com/gabriele_pippi/status/1206907900268072962\n    filter_optional_chocolatey:\n        ParentImage: # Chocolatey https://chocolatey.org/\n            - 'C:\\ProgramData\\chocolatey\\choco.exe'\n            - 'C:\\ProgramData\\chocolatey\\tools\\shimgen.exe'\n    filter_optional_defender:\n        ParentCommandLine|contains: '\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection'\n    filter_optional_ansible:\n        # Note: As ansible is widely used we exclude it with this generic filter.\n        # A better option would be to filter based on script content basis or other marker while hunting\n        ParentCommandLine|contains:\n            # '{\"failed\":true,\"msg\":\"Ansible requires PowerShell v3.0 or newer\"}'\n            - 'JwB7ACIAZgBhAGkAbABlAGQAIgA6AHQAcgB1AGUALAAiAG0AcwBnACIAOgAiAEEAbgBzAGkAYgBsAGUAIAByAGUAcQB1AGkAcgBlAHMAIABQAG8AdwBlAHIAUwBoAGUAbABsACAAdgAzAC4AMAAgAG8AcgAgAG4AZQB3AGUAcgAiAH0AJw'\n            - 'cAewAiAGYAYQBpAGwAZQBkACIAOgB0AHIAdQBlACwAIgBtAHMAZwAiADoAIgBBAG4AcwBpAGIAbABlACAAcgBlAHEAdQBpAHIAZQBzACAAUABvAHcAZQByAFMAaABlAGwAbAAgAHYAMwAuADAAIABvAHIAIABuAGUAdwBlAHIAIgB9ACcA'\n            - 'nAHsAIgBmAGEAaQBsAGUAZAAiADoAdAByAHUAZQAsACIAbQBzAGcAIgA6ACIAQQBuAHMAaQBiAGwAZQAgAHIAZQBxAHUAaQByAGUAcwAgAFAAbwB3AGUAcgBTAGgAZQBsAGwAIAB2ADMALgAwACAAbwByACAAbgBlAHcAZQByACIAfQAnA'\n    condition: selection_img and 1 of selection_susp_location_* and not 1 of filter_main_* and not 1 of filter_optional_*\nfalsepositives:\n    - Legitimate software from program files - https://twitter.com/gN3mes1s/status/1206874118282448897\n    - Legitimate Microsoft software - https://twitter.com/gabriele_pippi/status/1206907900268072962\n    - Ansible\nlevel: medium\n","validation":"yaml_parsed_not_backend_compiled_or_live_validated","techniques":[{"key":"enterprise/T1027.004","id":"T1027.004","name":"Compile After Delivery","page":"techniques/enterprise/T1027.004/"}],"data_path":"data/detection-rules/dcaa3f04-70c3-427a-80b4-b870d73c94c4.json","kind":"sigma"}
