# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .ps1
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: .NET (PowerShell)
#     language: PowerShell
#     name: .net-powershell
# ---

# # T1106 - Native API
# Adversaries may directly interact with the native OS application programming interface (API) to execute behaviors. Native APIs provide a controlled means of calling low-level OS services within the kernel, such as those involving hardware/devices, memory, and processes.(Citation: NT API Windows)(Citation: Linux Kernel API) These native APIs are leveraged by the OS during system boot (when other system components are not yet initialized) as well as carrying out tasks and requests during routine operations.
#
# Functionality provided by native APIs are often also exposed to user-mode applications via interfaces and libraries. For example, functions such as the Windows API <code>CreateProcess()</code> or GNU <code>fork()</code> will allow programs and scripts to start other processes.(Citation: Microsoft CreateProcess)(Citation: GNU Fork) This may allow API callers to execute a binary, run a CLI command, load modules, etc. as thousands of similar API functions exist for various system operations.(Citation: Microsoft Win32)(Citation: LIBC)(Citation: GLIBC)
#
# Higher level software frameworks, such as Microsoft .NET and macOS Cocoa, are also available to interact with native APIs. These frameworks typically provide language wrappers/abstractions to API functionalities and are designed for ease-of-use/portability of code.(Citation: Microsoft NET)(Citation: Apple Core Services)(Citation: MACOS Cocoa)(Citation: macOS Foundation)
#
# Adversaries may abuse these native API functions as a means of executing behaviors. Similar to [Command and Scripting Interpreter](https://attack.mitre.org/techniques/T1059), the native API and its hierarchy of interfaces, provide mechanisms to interact with and utilize various components of a victimized system.

# ## Atomic Tests

#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

# ### Atomic Test #1 - Execution through API - CreateProcess
# Execute program by leveraging Win32 API's. By default, this will launch calc.exe from the command prompt.
# **Supported Platforms:** windows
# #### Attack Commands: Run with `command_prompt`
# ```command_prompt
# C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /out:"%tmp%\T1106.exe" /target:exe PathToAtomicsFolder\T1106\src\CreateProcess.cs
# # %tmp/T1106.exe
# ```

Invoke-AtomicTest T1106 -TestNumbers 1

# ## Detection
# Monitoring API calls may generate a significant amount of data and may not be useful for defense unless collected under specific circumstances, since benign use of API functions are common and difficult to distinguish from malicious behavior. Correlation of other events with behavior surrounding API function calls using API monitoring will provide additional context to an event that may assist in determining if it is due to malicious behavior. Correlation of activity by process lineage by process ID may be sufficient. 
#
# Utilization of the Windows API may involve processes loading/accessing system DLLs associated with providing called functions (ex: kernel32.dll, advapi32.dll, user32.dll, and gdi32.dll). Monitoring for DLL loads, especially to abnormal/unusual or potentially malicious processes, may indicate abuse of the Windows API. Though noisy, this data can be combined with other indicators to identify adversary activity. 

# ## Shield Active Defense
# ### Software Manipulation 
#  Make changes to a system's software properties and functions to achieve a desired effect. 
#
#  Software Manipulation allows a defender to alter or replace elements of the operating system, file system, or any other software installed and executed on a system.
# #### Opportunity
# There is an opportunity for the defender to observe the adversary and control what they can see, what effects they can have, and/or what data they can access.
# #### Use Case
# A defender can modify system calls to break communications, route things to decoy systems, prevent full execution, etc.
# #### Procedures
# Hook the Win32 Sleep() function so that it always performs a Sleep(1) instead of the intended duration. This can increase the speed at which dynamic analysis can be performed when a normal malicious file sleeps for long periods before attempting additional capabilities.
# Hook the Win32 NetUserChangePassword() and modify it such that the new password is different from the one provided. The data passed into the function is encrypted along with the modified new password, then logged so a defender can get alerted about the change as well as decrypt the new password for use.
# Alter the output of an adversary's profiling commands to make newly-built systems look like the operating system was installed months earlier.
# Alter the output of adversary recon commands to not show important assets, such as a file server containing sensitive data.

StarcoderdataJupyterScriptsDedupFiltered