Giter VIP home page Giter VIP logo

sandbox-attacksurface-analysis-tools's Introduction

sandbox-attacksurface-analysis-tools

(c) Google LLC. 2015 - 2021
Developed by James Forshaw

This is a small suite of PowerShell tools to test various properties of sandboxes on Windows. Many of the
tools take a -ProcessId flag which is used to specify the PID of a sandboxed process. The tool will impersonate
the token of that process and determine what access is allowed from that location. Also it's recommended
to run these tools as an administrator or local system to ensure the system can be appropriately enumerated.

EditSection: View and manipulate memory sections.
TokenView: View and manipulate various process token values.
NtApiDotNet: A basic managed library to access NT system calls and objects.
NtObjectManager: A powershell module which uses NtApiDotNet to expose the NT object manager.
ViewSecurityDescriptor: View the security descriptor from an SDDL string or an inherited object.

You can load the using the Import-Module Cmdlet. You'll need to disable signing requirements however.

For example copy the module to %USERPROFILE%\Documents\WindowsPowerShell\Modules then load the module with:

Import-Module NtObjectManager

You can now do things like listing the NT object manager namespace using:

Get-ChildItem NtObject:\

Also see help for various commons such as Get-NtProcess, Get-NtType or New-File.

The tools can be built with Visual Studio 2019. It's possible to also build NtApiDotNet and NtObjectManager
with .NET 5.0 building the specific project files.

Thanks to the people who were willing to test it and give feedback:
* Matt Graeber
* Lee Holmes
* Casey Smith
* Jared Atkinson

Release Notes:

1.1.33
--------
* Various bug fixes.
* Added RPC pipe support.

1.1.32
--------
* Too many changes to mention.

1.1.31
--------
* Added signing and encryption to SSPI.
* Added Get-LsaContextSignature and Test-LsaContextSignature.
* Added Protect-LsaContextMessage and Unprotect-LsaContextMessage
* Named auth commands to Lsa.
* Added TCP/IP RPC transport and add signing/encryption.
* Added Disconnect-RpcClient.
* Added server information for local RPC connection.
* Added Enable-NtTokenPrivilege and Disable-NtTokenPrivilege.
* Added native ARM/ARM64 support.
* Added Get-Win32ServiceConfig and Set-Win32ServiceConfig.
* Fixed bug in ACL canonicalization.
* Added support for SDK names of enumerations/structures. 
* Added Get-NtSDKName.
* Added support for Win32 WriteProcessMemory.
* Added Get-Win32ServiceTrigger and support for triggers in Start-Win32Service.
* Added Set-Win32ServiceSecurityDescriptor.
* Fixed INdrStructure unmarshaling #35

1.1.30
--------
* Fixed issue when displaying only a SACL with Format-NtSecurityDescriptor.
* Added basic named pipe support for RPC clients.
* Fixed issue enumerating per-user audit rules.
* Added view accessor for safe buffers.
* Improved debug tracing for RPC clients.
* Improved handling of paths with local files commands.
* Fixed path issue with Set-Win32SecurityDescriptor.
* Added querying trace providers from the WMI security key.

1.1.29
--------
* Added Get-NtProcessUser.
* Added Get-NtProcessEnvironment.
* Added global option for New-NtSymbolicLink.
* Added Split-Win32CommandLine.
* Added send and post methods to NtMessage.
* Added AsObject parameter for Get-NtObjectInformation.
* Added NtMailslotFile and fixed mailslot creation.
* Added Get-NtKeySymbolicLinkTarget.
* Added support for a FollowLink switch which will allow accessible cmdlets to follow symbolic links. Feature request #29.
* Separated forms code from the main assembly.
* Added setting service security and Get/Set-Win32ServiceSecurityDescriptor.
* Added Win32 debug console class and Start/New/Read-Win32DebugConsole.
* Added Test-NtTokenCapability.
* Added New-Win32Service and Remove-Win32Service.
* Reimplemented SidName to allow access to the Domain component.
* Added section characteristics check when parsing RPC servers. Fix for issue #27.
* Added an SDKName attribute to access rights.
* Added Add-NtAccountRight and Remove-NtAccountRight.
* Added basic VBS enclave support.
* Added support to parse ELAM information from a binary.
* Added Get-NtSigningLevel and Get-X509Certificate.
* Added Compare-NtSigningLevel.
* Added silo impersonation commands.
* Added option to impersonation System when creating a token or with Invoke-NtToken.
* Added proper enumeration of AppContainer profiles and support creating with capabilities.
* Added Get-AppModelApplicationPolicy.
* Added Get-NtThreadContext and Set-NtThreadContext.
* Added support for calling CreateProcessWithLogon via Win32Process.
* Added Start-AppModelApplication.
* Added Add-NtThreadApc.
* Fixed path handling in Get-Win32SecurityDescriptor.
* Added Get-NtFileFinalPath command.
* Reworked handling of lease oplocks.
* Added basic USN journal support.
* Added Get-NtFileStream.
* Added Get-NtMountPoint command.
* Added basic async support and the Wait-AsyncTaskResult command.
* Added Send-NtFileControl command.
* Added Get-NtFileVolumeInformation and Set-NtFileVolumeInformation.
* Added Get-NtFileItem command.
* Added support for querying device nodes, setup class and interface classes.
* Added Get-NtFileSharingProcess.
* IPeb: Added GetBeingDebugged() (#26)
* Added support for enumerating filter drivers and connecting to ports.
* Added New-NtKeySymbolicLink and Set-NtKeySymbolicLinkTarget.
* Added a Get-NtKeyHive command.

1.1.28
--------
* Added Import-Win32Module and Get-Win32Module.
* Added support for Registry Keys in the NtObjectManager provider.
* Added Get-NtDirectoryEntry.
* Added Win32 CreateRemoteThread.
* Added addition Registry Key functions.
* Added Network Authentication commands.
* Added Authentication Token formatting commands.
* Added new filtering features to TokenViewer.
* Improved cmdlets for getting and setting object information classes.
* Added Add-NtSection and Remove-NtSection.
* Added Compare-NtObject.
* Added Test-NtTokenPrivilege.
* Added type parsing from PDBs via SymbolResolver.
* Added a summary format to Format-NtSecurityDescriptor.
* Added Out-HexDump.
* Added C# compiler support for .NET Core Support of Get-RpcClient.
* Updated New-NtSecurityDescriptor and Edit-NtSecurityDescriptor.
* Basic C++ NDR formatting from irsl@.
* Added Format-NtJob.
* Added New-NtSecurityAttribute and Get-NtAceConditionData.
* Added Device/User Claims to Token Viewer and Format-NtToken.
* Added many different commands to manipulate Security Descriptors.
* Added Win32 Security Descriptor commands.
* Added filtering for accessible path commands.
* Added Audit support.
* Added basic AuthZ API support.
* Added basic ASN.1 DER parsing and Format-ASN1DER command.
* Added Kerberos Keytab file reading and writing.

1.1.27
--------
* Added support for directory change notifications.
* Added New-NtDesktop, Get-NtDesktop and Get-NtDesktopName.
* Added New-NtWindowStation, Get-NtWindowStation and Get-NtWindowStationName.
* Changed Win32 error codes to an enumeration.
* Added Load/Unload driver.
* Added properties to NtType to show access masks.
* Added basic SendInput method.
* Added token source tab to Token Viewer.
* Updated for the Job object and New-NtJob.
* Added NtWindow class a HWND enumeration.
* Added Get-AccessibleWindowStation command.
* Added some well known WNF names.
* Added option to Get-AccessibleService to check file permissions.
* Added Set-NtProcessJob command.
* Added Get-AccessibleToken command.
* Added support for compound ACEs.
* Added Get/Sid-NtTokenSid and Get/Set-NtTokenGroup.
* Added Get-AccessibleEventTrace command.
* Added Get-AccessibleWnf command.

1.1.26
--------
* Add DeviceGuid to Get/New-NtFile
* Fixed bug in ETA registrations and added GUID enumeration.
* Added SetExceptionPort to NtProcess.
* Added child process mitigation improvements.
* Added extended Fork.
* Updated native process creation support.
* Various new non-throwing methods.
* Updated to C# 7.3.
* Added list of access rights to NtType.
* Added default mandatory policy to NtType.
* Added SetDisposition methods to NtFile.
* Added console and GUI support for Object ACEs.
* Updated access checking to support Object Types.
* Access check returns a structure rather than just an access mask.
* CPP style NDR formatting (#21)
* Added Get-NtTokenPrivilege command.
* Added Get-NtLocallyUniqueId command.

1.1.25
--------
* Added new options to Get-NtSecurityDescriptor.
* Updated accessible resource checking.
* Added Remove-NtTokenPrivilege.
* Added Session option to Get-NtToken.
* Added command line option to Show-NtToken.
* Added information classes for symbolic links.

1.1.24
--------
* Added Add-NtTokenSecurityAttribute and Remove-NtTokenSecurityAttribute cmdlets.
* Added additional properties for running servies.
* Added support for drivers to Get-RunningService and Get-AccesibleService.
* Added fake service NtType objects for services and SCM to allow formatting and the UI.
* Added NtType property to security descriptors.
* Added option to Show-NtToken to elevate to admin.
* Added Suspend, Resume and Stop process commands.
* Added Get-NtEaBuffer and Set-NtEaBuffer commands.
* Added open to Get-NtDebug to get from a process.

1.1.23
--------
* Added basic ETW APIs.
* Added new thread properties.
* Added Close-NtObject function.
* Added Get-AccessibleScheduledTask cmdlet.
* Added typing for New-ExecutionAlias and renamed to Set-ExecutionAlias.
* Added Compare-RpcServer.
* Fixed handling of FQBN token security attributes.
* Added option to Format-RpcClient to output to a directory.
* Added Select-RpcServer cmdlet.
* Added RPC ALPC port brute force.

1.1.22
--------
* Removed old standalone utilities, everything should be accessible from PowerShell.
* Added Test-NetworkAccess cmdlet to replace CheckNetworkAccess utility.
* Added Set-NtFileHardlink cmdlet.
* Various fixes for RPC client code.

1.1.21
--------
* Various updates to the NDR parser, including new types and support for correlation expressions.
* Added complete transaction cmdlets.
* Added extended process creation flags for Win32Process.
* Added Format-NtSecurityDescriptor to display on the console
* Added Copy-NtObject cmdlet.
* Added basic RPC ALPC client support.
* Added option to specify a debug object for a Win32 process.
* Added processor system information.

1.1.20
--------
* Added basic ALPC support including cmdlets.
* Added better debug support including cmdlets.
* Display container access rights in SD GUI and also extract SACL if available.
* Added Set/Get-NtProcessMitigation policy to get specific policies.
* Exposed process mitigation policies using flag enums.
* Added Win32.AppContainerProfile to create and delete AC profiles.
* Many new non-throwing methods added to objects.
* Added ReadScatter and WriteGather methods to NtFile.
* Improved formatting of IO Control Codes.
* Added ability to acknowledge oplock breaks.
* Added Wow64 FS redirection support.
* Use proper WIN32 NT status facility for Win32 errors as status codes.
* Added read/write to file from safe buffers.
* Added methods to zero or fill safe buffers using native methods.
* Fix bug with querying BnoIsolationPrefix which next took into account the enable flag correctly.
* Fix from diversenok "Improve detection of restricted tokens (#20)"
* Code cleanups and source code separation.

1.1.19
--------
* Fix for bug in NtWaitTimeout not creating infinite waits.
* Added some new NTSTATUS codes and break apart the status.
* Added some new FSCTL codes.

1.1.18.1
--------
* Added missing release notes.

1.1.18
------
* Added better support for transaction objects including some cmdlets.
* Added general QueryInformation and SetInformation methods to a number of objects.
* Added side channel isolation mitigation policy.
* Added more FS volume information classes.
* Added extended section/memory functions.
* Added a few missing NDR type formats.
* Added BNO isolation process attribute.
* Added new types to separate out named pipes from normal files.
* Added Start-NtFileOplock.
* Added support for absolute security descriptors.

1.1.17
------
* Added methods to get AppModel policy from a token.
* Added Start-Win32ChildProcess
* Default to a version of DbgHelp if installed to the NtObjectManager directory under x86 or x64.
* Added some setters to token properties.
* Added a fix for a memory corruption issue in getting NT type information on 32 bit platforms (from 1orenz0).
* Added option to parse out RPC clients in Get-RpcServer.
* Fixed performance issue with section viewer and the corrupter.
* Added a valid length property to NtMappedSection.
* Added Get-NtObjectFromHandle cmdlet.
* Added Copy-NtToken function.
* Added enumeration for device characteristics.
* Fixed path resolving for file paths.
* Added Get-RpcAlpcServer cmdlet.

1.1.16
------
* Added Get-NtFilePathType function.
* Added Add-NtSecurityDescriptorDaclAce function.
* Added Path support to Get-NtSecurityDescriptor and Set-NtSecurityDescriptor.
* Added parameter to only return a specific set of IIDs from a COM proxy definition.
* Added support for extracting RPC servers from a DLL.
* Added support for enumerating registered RPC endpoints with Get-RpcEndpoint.
* Added support for enumerating running service information with Get-RunningService.
* Added Get-NtAlpcServer function.
* Reworked OpenWithType to support bruteforce of the object type.
* Added Win32Utils method to parse command line and extract image path.
* Fix DepStatus On Windows Server 2K12 / 2K16 from Rosalie.
* Added option to Get-NtProcess and Get-NtThread to only return system information.
* Added basic transaction support to registry keys.

1.1.15
------
* Convert access exceptions during NDR parsing into an NdrParser exception rather than crashing the process.
* Added function to enumerate running services with PIDs.
* Added methods to load module into a symbol resolver after creation.
* Added basic support for WNF registrations including a Get-NtWnf cmdlet.
* Expose all parameters for section mapping.
* Added a Get-NtMappedSection cmdlet.
* Various fixes to NDR decoding.
* Added method to create an anonymous named pipe pair.
* Rework of cached signing level, including unpacked EA data based on information provided by Alex Ionescu.
* Added protection level to the base New-Win32Process function.
* Added access rights for process creation.

1.1.14
------
* Added basic support for transaction objects.
* Minor fixes for ALPC support.
* Implemented OOP NDR parsing.
* Added NDR parsing and formatting powershell functions such as New-NdrParser and Format-NdrComProxy
* Fix for display of NDR arrays from 1orenz0.
* Print NDR correlation descriptors during formatting.
* Added support to read out COM proxies.

1.1.13
------
* Fixed bug in Get-NtToken for sandboxed tokens.
* Extended support for Job objects.
* Added Set-NtFileReparsePoint cmdlet.
* Added support for viewing a file with Show-NtSection
* Added support for DuplicateTo methods from rosalie.lecart.
* Improved support for Win32 Desktop and WindowStation objects.
* ScriptBlock support for the $_ argument.
* Added SID -> Name cache to improve performance.
* Fixed user marshallers in NDR for Windows 7.
* Added internal security descriptor viewer control.

1.1.12
------
* Added basic NDR parser.
* Added basic symbol resolver.
* Added method to read a security descriptor from another process.
* Improved process memory read and writing methods.
* Added virtual memory cmdlets to allocate, release and modify memory.
* Added Get-EmbeddedAuthenticodeSignature function.
* Added Get and Set NtSecurityDescriptor functions.
* Added ProcessTrustLabel to basic security information set.
* Added Get-NtFileChild cmdlet.
* Added Get-NtKeyChild cmdlet.
* Added Get-NtDirectoryChild cmdlet.
* Added name lookup to NtIoControlCode.
* Added NtNamedPipeFile type with implementations of basic pipe functions.
* Added ADd-DosDevice and Remove-DosDevice cmdlets.
* Added file directory and stream visitors.
* Merged Get-NtLowBoxToken and Get-NtFilteredToken into Get-NtToken.
* Modified Show-NtSection to also display an arbitrary byte array.
* Added an Invoke-NtToken cmdlet to run a script block under impersonation.
* Added Remove-NtFile cmdlet.
* Added case sensitive property for RS4.
* Added flags for NtCreateDirectoryObjectEx.
* Added pseudo option to Get-NtToken.
* Improved conditional ACE support.

1.1.11
------
* Improved New-NtToken including adding missing IL
* Added new NTSTATUS codes from 1709
* Changes to native process creation
* Added OverrideChildProcessCreation for Win32 process
* Added display of process trust labels from tokens.
* Fixed IsChildProcessRestricted on 1709 and above (changed structure)
* Fixed named pipe server in TokenViewer
* Added -All parameter to Show-NtToken to display list of tokens.

1.1.10
------
* Added support for extended handle information to allow for PIDs > 64k.
* Added basic New-NtToken cmdlet and system call.
* Added Resolve-NtObjectAdddress cmdlet to resolve the addresses of a list of objects.
* Added generic object ReOpen method.
* Added vistor method to object directories to enumerate recursively with a callback.
* Added display of process trust labels.

1.1.9
-----
* Fix for bug when querying extended process information on Windows 7/8.
* Add OneDrive file attributes from thierry.franzetti.
* Added support for displaying child AppContainer names.
* Various improvements to section editor including integer data inspectors.

1.1.8
-----
* Better support for relative paths in the cmdlets including supporting ones based on the current directory.
* RenameEx and DispositionEx support from fllombard.
* Added Key value deletion and fixes from rsiestrunck.
* Fixed bug in NtOpenSession prototype.
* Added support for adding additional groups to a token in Get-NtToken if user has SeTcbPrivilege.
* Added Show-NtToken to display a token in the GUI, renamed old whois style token viewer to Show-NtTokenEffective.
* Added PowerShell functions to get and create execution alias reparse points.
* Added section viewer and editor with Show-NtSection function.

1.1.7
-----
* Added projects to build NtObjectManager for PowerShell Core 6.0
* Added additional techniques to open process tokens in access checking cmdlets.
* Fixed issues with Add-NtKey and added Remove-NtKey cmdlets.
* Minor fixes from fllombard
* Added change notify key with asynchronous support
* Added kernel LUID allocation

1.1.6
-----
* Added support for child process policy and desktop app policy to Win32ProcessConfig.
* Added new mitigation options from Win10 1709.
* Fix a couple of crashes.

1.1.5
-----
* Fixed crash on 32 bit Windows when enumerating NT types.
* Merged ManagedHandleUtils assembly into main NtApiDotNet under the Win32 namespace.

1.1.4
-----
* Added Show-NtSecurityDescriptor function.
* Added support for modifying security descriptors in the UI.
* Cleanup of access mask when being displayed in the UI.
* Added opaque reparse buffer.

1.1.3
-----
* Added Show-NtToken function.
* Added basic version checking for certain functions which can't be accessed on Windows 7.
* Fixed referenced System.Management.Automation assembly version to run properly with no PS2.
* Fixed some bugs in token structures which preventing being used with multiple values.
* Added support to Win32Process for LPAC.

1.1.2
-----
* Added Get-AccessibleHandle cmdlet.
* Support for oplock levels.
* Added support to set inherit and protect on close flags to objects.
* Added Get-NtFilePath function.

1.1.1
-----
* Fix to native protected process creation.
* Added functions to create native NT processes.

1.1.0
-----
* Removed check tools, excluding CheckNetworkAccess.
* Added basic Job object cmdlets.
* Added creation of protected processes in Win32Process.
* Added service access checking cmdlet.
* Added get executable manifest cmdlet.

1.0.9
-----
* Made New-Win32Process more generic and added support for Win32k filter enable.
* Added function to capture token from a process using impersonation.
* Added basic support for Desktop and WindowStation objects using Win32u.dll exports.
* Added file locking implementation including async.
* Added hardlink enumeration.
* Added NTFS stream enumeration.
* Deprecated most of the old standalone utilities in favour of PS cmdlets.

1.0.8
-----
* Added cmdlets to create a kernel memory dump, system environment and licensing.
* Additional system calls implemented.
* Added access to secure boot policies and code integrity policies.
* Made Win32 Process creation more generic and added cmdlet.
* Added access check by type including SELF SID.

1.0.7
-----
* Added new cmdlets to do access checking. Many of the old standalone utilities are now deprecated.
* Added cmdlets to create lowbox tokens
* Added list of known capability SIDs and resolve them during name lookup
* Added cmdlet to get a SID
* Added cmdlet to do a standalone access checking
* Reworked the APIs to include non-throwing versions of many of the core Open/Create methods.
* Made NtType more inspectable, includes access enumeration and rationalizes the opening methods.
* Various additional properties such as extended process flags, checking for LPAC
* Rework of access mask handling. Now all low-level APIs use an AccessMask structure which has
  conversion operators to and from other enumerations.
* Various other bug fixes.

1.0.6
-----
* Added cmdlet to filter a Token object.
* Cleanups to various components to make them easier to use from PS

1.0.5
-----
* Added additional Known SIDs
* Unified the variant Get-NtToken* cmdlets into one.
* Added additional token cmdlets such as Logon and Clipboard.
* Added initial support for IO Completion Ports
* Added object creation time property
* Added support to set a process device map
* Added top level CanSynchronize property to NtObject
* Bugs fixes from Rustam Agametov
* Made process list in token viewer a list rather than a tree and made a separate handle tab.

1.0.4
-----
* Support getting and setting file EA buffer
* Added cmdlet to get NTSTATUS code information
* Support to toggle UIAccess and Virtualization flags on tokens
* Added asynchronous support for file operations using Task APIs
* Added support for virtual memory functions
* Added cmdlet to create named pipes and mailslots.
* Added support for specifying SD as SDDL directly to cmdlets.
* Added thread descriptions for Anniversary edition and above.

1.0.3
-----
* Fixed small bug in handling of IO_STATUS_BLOCK which could result in memory corruption.
* Added support to list directory entries for a file directory.
* Added support to do basic read and writes to a file.

1.0.2
-----
* Added support to disable dynamic code policy on a process.
* Added cmdlets for reparse points.
* Fixes for EA buffer.
* Added service SIDs.
* Added support for removing token privileges.
* Fixed token security attribute parsing.

v1.0.1
------
* Replaced all unmanaged code with a managed library.
* Added NtObjectManager Powershell Module

v1.0.0
------
* Initial Release

sandbox-attacksurface-analysis-tools's People

Contributors

1orenz0 avatar agametov avatar anhaehne avatar arthur-suleimanov avatar ccob avatar ceztko avatar diversenok avatar fllombard avatar irsl avatar leechristensen avatar lowleveldesign avatar monoxgas avatar qtc-de avatar rosalie79 avatar rsiestrunck avatar thierryfranzetti avatar tyranid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sandbox-attacksurface-analysis-tools's Issues

Is there a way to check if a certain fields threw an exception when using NtFile.Open?

I am using NtFileOpen on named pipes, sometimes some fields are throwing an exception while others are not:
image

Is there a way to check if a field threw an exception without using try..catch for every field?

For example, in the following code, we can get an object with fields that threw an exception:

namedPipeFileObject = (NtNamedPipeFileBase)NtFile.Open(obj_attributes, i_Access, i_ShareMode, i_Options);  
row.Cells[0].Value = namedPipeObject.NumberOfLinks;
row.Cells[1].Value = namedPipeObject.DirectoryGrantedAccess;
row.Cells[2].Value = namedPipeObject.GrantedAccess;
row.Cells[3].Value = namedPipeObject.GrantedAccessGeneric;    

But using try..catch for every field can be overkill, especially if we will go over all the fields.
Any suggestion how to handle it?

TokenViewer: Create Process -> black window?

This is more of a question (I'd be curious to understand roughly why this happens, even if there's no workaround):

I'm trying the following on Windows 10 (22H2): I start TokenViewer.exe elevated as a user that posseses "act as operating system" privileges. In the logon user tab I create a new processes (with Services4Users, i.e. without password). TokenViewer opens a new Windows in which displays the token of the new processes (which is Impersonation level, as expected). Now in the Operations tab I try to create a cmd.exe process (with Interactive enabled). This works, a process is started and a window appears. However the resulting Window is black/blank, with a blue (but also blank) title bar. (See screenshot below). Things that I type in the cmd.exe shell aren't visible, but are being accepted (i.e. typing exit + ENTER closes the window/process).

I've also tried things like conhost.exe, conhost.exe cmd.exe, conemu.exe, but this produced the same. This is also the case when trying to start other GUI apps like notepad.exe.

If anyone could point me in the direction of an explanation, I'd highly appreciate it. Thanks in advance!

image

Getting Access Denied when calling NtFile.Open on a named pipe

Hi James,

I am creating the following dummy named pipe without Dacl in Powershell:

function CreateDummyPipeForTesting {
  $pipeSecurity = New-Object System.IO.Pipes.PipeSecurity
  $pipeSecurity.SetAccessRuleProtection($true, $true)
  $pipeServer = New-Object System.IO.Pipes.NamedPipeServerStream("myPipe", [System.IO.Pipes.PipeDirection]::InOut, -1, [System.IO.Pipes.PipeTransmissionMode]::Byte, [System.IO.Pipes.PipeOptions]::None, 4096, 4096, $pipeSecurity)
  Write-Output "Waiting for client connection..."
  $pipeServer.WaitForConnection()
  Write-Output "Client connected."
  $reader = New-Object System.IO.StreamReader($pipeServer)
  $writer = New-Object System.IO.StreamWriter($pipeServer)
  while ($true) {
    $message = $reader.ReadLine()
    Write-Output "Received message: $message"
    $writer.WriteLine("Hello from the server!")
    $writer.Flush()
  }
}

CreateDummyPipeForTesting

When I run the PowerShell GetNtFile, everything works fine:

PS C:\Users\eviatar> $b = Get-NtFile("\Device\NamedPipe\myPipe")
PS C:\Users\eviatar> $b.SecurityDescriptor | fl


Dacl                 : {}
Sacl                 :

But when I am trying to use the C# parallel function (NtFile.Open()) like that:

public static NtNamedPipeFileBase GetNamedPipeObjectClient2()
{
	NtNamedPipeFileBase namedPipeFileObject = null;

	string i_NamedPipe = @"\Device\NamedPipe\myPipe";
	//i_NamedPipe = @"\Device\NamedPipe\InitShutdown";
	FileShareMode ShareMode = FileShareMode.Read | FileShareMode.Write;
	FileOpenOptions Options = FileOpenOptions.SynchronousIoNonAlert;
	FileAccessRights Access = FileAccessRights.GenericRead | FileAccessRights.GenericWrite | FileAccessRights.Synchronize;


	using (ObjectAttributes obj_attributes = new ObjectAttributes(i_NamedPipe))
	{
		try
		{
			namedPipeFileObject = (NtNamedPipeFileBase)NtFile.Open(obj_attributes, Access, ShareMode, Options);
			// namedPipeFileObject = NtFile.CreateNamedPipe(obj_attributes, Access, ShareMode, Options, FileDisposition.Open, NamedPipeType.Bytestream,
		   // NamedPipeReadMode.ByteStream, NamedPipeCompletionMode.CompleteOperation, 0, 0, 0, NtWaitTimeout.FromMilliseconds(0));

		}
		catch (Exception e)
		{
			// 
		}

	};


	return namedPipeFileObject;
}

I am getting an exception:

{"(0xC0000022) - {Access Denied}
A process has requested access to an object, but has not been granted those access rights."}

I also tried to run it with admin permissions with no success.
I used Get-NtFile with standard permissions (not admin) and it worked, and I used the same user with the C# function, so I am not sure why it doesn't work.
Maybe my FileAccessRights is wrong?
I tried to follow the source code but didn't see the use of the default permissions:

protected override object CreateObject(ObjectAttributes obj_attributes)
{
using (Transaction?.Enable())
{
FileOpenOptions opts = Options;
if (OpenById)
opts |= FileOpenOptions.OpenByFileId;
if (Directory)
opts |= FileOpenOptions.DirectoryFile;
return NtFile.Create(obj_attributes, Access, FileAttribute,
ShareMode, opts, Disposition, EaBuffer, AllocationSize);
}
}
/// <summary>
/// Constructor
/// </summary>
public NewNtFileCmdlet()
{
Disposition = FileDisposition.Create;
FileAttribute = FileAttributes.Normal;
}
}

RpcServer.ParsePeFile throw and uncatchable error

When I am calling RpcServer.ParsePeFile like that:

string name = @"C:\Windows\winsxs\x86_wcf-system.identitymodel_b03f5f7f11d50a3a_10.0.19041.1_none_e690fdc7d17e3f70\System.IdentityModel.dll";  
string symbolsPath = @"srv*c:\symbols*http://msdl.microsoft.com/download/symbols";
string dbgHelp = @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll";
NtApiDotNet.Win32.RpcServer.ParsePeFile(name, dbgHelp , symbolsPath , NtApiDotNet.Win32.RpcServerParserFlags.None);

I am getting the following error:

C:\Windows\winsxs\x86_wcf-system.identitymodel_b03f5f7f11d50a3a_10.0.19041.1_none_e690fdc7d17e3f70\System.IdentityModel.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administator or the software vendor for support. Error status: 0xc000012f.

image

The problem is that I when I tried to use try...catch it doesn't work on these kind of errors.
Any idea how to solve\workaround it?

I noticed that the DLL PE magic starts with DCS which is related to Delta Compression Application.
More reference from this answer.

I think I can workaround it by checking the magic of the file by reading it first before moving it to the function but it might affect the performance a bit.
The problem can also repeat if you run it like that:

rpcFile = @"C:\Windows\winsxs\x86_wcf-system.identitymodel_b03f5f7f11d50a3a_10.0.19041.1_none_e690fdc7d17e3f70\System.IdentityModel.dll";
using (var result = SafeLoadLibraryHandle.LoadLibrary(rpcFile, LoadLibraryFlags.DontResolveDllReferences, false))
{
}

I noticed that it won't help to check for MZ as magic file because there are files like:

C:\Windows\winsxs\x86_microsoft-windows-n..nd-syswow64-payload_31bf3856ad364e35_1.0.19041.1_none_beac3411b23832d5\compobj.dll

Which starts with MZ but still have bad image.

Thanks

compile error

้”™่ฏฏ CS0165 ไฝฟ็”จไบ†ๆœช่ต‹ๅ€ผ็š„ๅฑ€้ƒจๅ˜้‡โ€œticketโ€ NtApiDotNet D:\sandbox-attacksurface-analysis-tools\NtApiDotNet\Win32\Security\Authentication\Kerberos\Builder\KerberosTicketBuilder.cs 208 ๆดปๅŠจ

Can Get-RpcAlpcServer retrieve information from process inside a container?

Does Get-RpcAlpcServer can get the RpcAlpcServer from a process inside a container?
I had a container running with process CExecSvc.exe (PID 4880) but when I tried to get it with the above function it didn't find it:

PS C:\Windows\system32> Get-RpcAlpcServer| where {$_.ProcessName -eq "cexecsvc.exe"}
PS C:\Windows\system32> Get-RpcAlpcServer -ProcessId 4880
PS C:\Windows\system32>

I noticed that RPCView also can't get this information.
This is not critical for me because I used the workaround with Get-RpcServer on the file itself, just wondering if this is a bug or currently not possible.

image

Reference:

private static IEnumerable<RpcAlpcServer> GetAlpcServersInternal(IEnumerable<NtHandle> handles)
{
NtType alpc_type = NtType.GetTypeByType<NtAlpc>();
foreach (var handle in handles.Where(h => h.NtType == alpc_type
&& h.Name.StartsWith(@"\RPC Control\", StringComparison.OrdinalIgnoreCase)))
{
List<RpcEndpoint> endpoints = new List<RpcEndpoint>();
try
{
endpoints.AddRange(RpcEndpointMapper.QueryEndpointsForAlpcPort(handle.Name));
}
catch (SafeWin32Exception)
{
}
if (endpoints.Count > 0)
{
yield return new RpcAlpcServer(handle, endpoints);
}
}
}

Provide .net standard nuget packages

Hi,

is it possible you provide Nuget packages targeting .net standard?

I saw the NtApiDotNet.Core.csproj but couldn't find a corresponding nuget package.

Get-NtApiSet seems to not resolve ALL ApiSet versions

Forgive me for not knowing all of the proper terminology to use here, I'll do my best to describe what I'm observing. I've been using Get-NtApiSet to resolve ApiSet names to their implementation DLL. Recently, I was analyzing kernel32!OpenProcess to use as a demonstration in a workshop and noticed what I suspect is a looping issue. As I'm sure you're aware, kernel32!OpenProcess is a simple wrapper that calls an imported function. On the version of Windows that I am using (), it is calling api-ms-win-core-processthreads-l1-1-2!OpenProcess. Now I know that the implementation is in kernelbase.dll, but because this is for a workshop I want to show my work. To do this, I've been relying on Get-NtApiSet as it seems to be the best solution for this type of resolution. However, this particular time I noticed an issue with the resolution. Here is the command and output:

Get-NtApiSet -Name api-ms-win-core-processthreads-l1-1-2

Name                                  HostModule   Flags
----                                  ----------   -----
api-ms-win-core-processthreads-l1-1-3 kernel32.dll Sealed

Now I think I only noticed this because I knew that the resulting HostModule should have been kernelbase.dll, but also notice that I requested version l1-1-2 and it returned version l1-1-3. I decided to just list all ApiSets that were known to the tool and found a pattern that when the final number in the version (the minor version maybe) is non zero, the results will only include the largest value. For example, here is the output for the example mentioned above:

api-ms-win-core-processsecurity-l1-1-0                     kernel32.dll                        Sealed
api-ms-win-core-processsnapshot-l1-1-0                     kernelbase.dll                      Sealed
api-ms-win-core-processthreads-l1-1-3                      kernel32.dll                        Sealed

I did however notice that in cases where the 2nd to last number in the version (the major number?) is non zero, it includes both versions:

api-ms-win-core-processtopology-l1-1-0                     kernelbase.dll                      Sealed
api-ms-win-core-processtopology-l1-2-0                     kernelbase.dll                      Sealed

This leads me to suspect that maybe there is some issue with the looping where the results being aren't being added to the list at the lowest level? I looked through the code to see if I could spot anything, but haven't found it yet. I'll keep looking, but thought I'd put this on your radar in case you can think of a quick solution or know something that I don't about ApiSets and their versions.

Errors on Win10 22H2

Hi James, Thanks for the great work.

When I run the work on Win10 22H2 (19045.2728) with the command $allrpc = ls "C:\Windows\system32\*" -Include "*.dll","*.exe" | Get-RpcServer, it has the following errors:

Get-RpcServer : Exception calling "ParsePeFile" with "4" argument(s): "Value cannot be null.
Parameter name: key"
At line:1 char:65
+ ... = ls "C:\Windows\system32\*" -Include "*.dll","*.exe" | Get-RpcServer
+                                                             ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RpcServer

This error just keep happening and it cannot parse any server. I guess this happens because Windows has changed its APIs? or because some kind of new Windows security policies?

btw, when I run the same command on Win10 1909, it has no problem.

[Enhancement/Idea] Get RPC server by the running process PID

Hi James,

Amazing project :)

I am using the NtObjectManager and for now it helps me a lot.
I had an idea I wanted to share.

The Problem
Today, as far as I know, when I want to export RpcServer functions, I can use such command:

Get-RpcServer 'C:\windows\system32\combase.dll' -DbgHelpPath "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll"

But when I used RPCView, you can see that svchost.exe also exports RPC functions but when trying to export it like that:

Get-RpcServer 'C:\windows\system32\svchost.exe'

It won't work. The reason is that it uses DLLs that have the RPC functions.
For example this svchost:

C:\Windows\system32\svchost.exe C:\Windows\system32\svchost.exe -k LocalServiceNetworkRestricted -p -s TimeBrokerSvc

According to RPCView, it uses:

C:\Windows\system32\combase.dll
C:\Windows\system32\BrokerLib.dll
C:\Windows\system32\TimeBrokerServer.dll  

They export the functions of the DLLs.
image

The Idea
A new function, maybe Get-RpcServerByPid.
It will know to export processes like svchost.exe.
I don't know how they did it, but I suppose they listed the modules of the process and checked each of its modules.

Example:
Get-RpcServerByPid <pid_of_svchost>
It will run Get-RpcServer on svchost.exe and list all its loaded modules and run it on them.

I spoke about svchost.exe but of course it should be generic and the logic will run on each process PID that you will decide.

Security Policy violation Binary Artifacts

This issue was automatically created by Allstar.

Security Policy Violation
Project is out of compliance with Binary Artifacts policy: binaries present in source code

Rule Description
Binary Artifacts are an increased security risk in your repository. Binary artifacts cannot be reviewed, allowing the introduction of possibly obsolete or maliciously subverted executables. For more information see the Security Scorecards Documentation for Binary Artifacts.

Remediation Steps
To remediate, remove the generated executable artifacts from the repository.

Artifacts Found

  • third_party/Be.Windows.Forms.HexBox/Be.Windows.Forms.HexBox.dll

Additional Information
This policy is drawn from Security Scorecards, which is a tool that scores a project's adherence to security best practices. You may wish to run a Scorecards scan directly on this repository for more details.


Allstar has been installed on all Google managed GitHub orgs. Policies are gradually being rolled out and enforced by the GOSST and OSPO teams. Learn more at http://go/allstar

This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

some process can not show?

image

the two softwares with different version can show different num of typora process

I think the latest commits shows wrong

NtApiDotNet.Win32.RpcServer.ParsePeFile doesn't return RPC servers

Hi James,

The RPC functions from PowerShell works good:

PS C:\WINDOWS\system32> Get-RpcServer "C:\tmp\CExecSvc.exe" -DbgHelpPath "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll"

Name         UUID                                 Ver Procs EPs Service Running
----         ----                                 --- ----- --- ------- -------
CExecSvc.exe 75ef42c7-22f4-44a0-8200-9351cd316e01 1.0 4     0           False

I wanted to use the Get-RpcServer from C# code. I searched in the PowerShell script and found that you are using [NtApiDotNet.Win32.RpcServer]::ParsePeFile to do it:

PROCESS {
try {
$servers = switch($PSCmdlet.ParameterSetName) {
"FromDll" {
$FullName = Resolve-Path -LiteralPath $FullName -ErrorAction Stop
Write-Progress -Activity "Parsing RPC Servers" -CurrentOperation "$FullName"
[NtApiDotNet.Win32.RpcServer]::ParsePeFile($FullName, $DbgHelpPath, $SymbolPath, $ParserFlags)
}

I wrote it in C#:

// string symbols = @"srv*c:\symbols*http://msdl.microsoft.com/download/symbols";
string dbg = @"C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll";
string rpcFile = @"C:\tmp\CExecSvc.exe";
var rpcServer = NtApiDotNet.Win32.RpcServer.ParsePeFile(rpcFile, dbg, "", NtApiDotNet.Win32.RpcServerParserFlags.None);

But the rpcServer variable is empty (Count=0). Any idea what I am missing here?
Notice that I also tried with symbols without success.
I am using NtApiDoNet.dll version 1.1.33

GitHub Actions?

Does it make sense to have a GitHub Actions Workflow to automatically build the source and respective Release.7z artifact of this repository? If you want that, I can probably do a PR.

RTL_USER_PROCESS_PARAMETERS

Hello,
I was searching for RTL_USER_PROCESS_PARAMETERS in your project but can't find it. You did not implement it ?

Get-NtNamedPipeFile failed with "Object Name invalid"

I have a named pipe with the following name:

PS C:\WINDOWS\system32> $pipes = [System.IO.Directory]::GetFiles("\\.\\pipe\\")
PS C:\WINDOWS\system32> $pipes[5]
\\.\\pipe\\Winsock2\CatalogChangeListener-5f4-0

When I run Get-NtNamedPipeFile it fails:

PS C:\WINDOWS\system32> $b = Get-NtNamedPipeFile("\\Device\\NamedPipe\\Winsock2\\CatalogChangeListener-5f4-0")
Get-NtNamedPipeFile : (0xC0000033) - Object Name invalid.
At line:1 char:6
+ $b = Get-NtNamedPipeFile("\\Device\\NamedPipe\\Winsock2\\CatalogChang ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-NtNamedPipeFile], NtException
    + FullyQualifiedErrorId : NtApiDotNet.NtException,NtObjectManager.Cmdlets.Object.GetNtNamedPipeFileCmdlet  

What can be the reason for that and is it possible to solve it?

Procedure names auto-labeled incorrectly when symbols fail to resolve

Observation:
When symbols fail to resolve for a binary, Get-RpcServer appears to assign RPC procedure names incorrectly:
image

Tested with the latest code on Github as well as the version of NtObjectManager in the PSGallery. Confirmed that the symbol does not exist with symchk as well (can't grab it via winbindex either).

Expected outcome:
If symbol resolution fails, assign an out-generated procedure name (e.g., Proc0, Proc1, Proc2, etc.). Might also throw a warning if symbols are configured but no symbols were found.

Link to example binary (hash C391E5024F1B8FAB6DCD88BBE3B36F71FAE02DD815EA9273D9ACB247781955FB): spoolsv.exe.txt

Get-AccessibleFile feature

Get-AccessibleFile -Recurse currently doesn't follow symlink and junction directories and I suppose this makes sense. However, I can see some cases where it's useful to follow such directories.

Could it be considered implementing an additional flag for this, that can be used in combination with the recurse flag?

[Enhancement/Idea]A token viewer with export option and capability to compare two processes security parameters would be nice to have

Token viewer is a very nice tool which is useful in wide variety of use cases w.r.t analysis of a process's security. It would be great if the below use cases are supported

  1. An export capability which would help in sharing the data with others.
  2. Comparing two instance of processes to see what is different among them w.r.t security parameters/token.

The need of second one arose when I was analyzing a store app where I was not able to access a file from one of the process running in a container. But a command prompt launched in the same security context with the tool called Hover (as per the documentation) was able to access it. I wanted to see how the privilege of command prompt launched from Hover is different from the actual process which failed to access a file. A comparison view which would result in showing the difference between these two processes would help in easier analysis.

Does Params object contains too much parameters: "Cannot find an overload..."

Hi James,
I was checking the function HcsRpc_ShutdownSystem (from vmcompute.exe - HCS service):

PS> $a = Get-RpcServer "C:\windows\system32\vmcompute.exe" -DbgHelpPath "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll"

PS> $a.Procedures[4]

Name             : HcsRpc_ShutdownSystem
Params           : {FC_SUPPLEMENT - NdrSupplementTypeReference - IsIn, , FC_UP - NdrPointerTypeReference - MustSize, MustFree, IsIn, FC_HYPER - NdrSimpleTypeReference - IsIn,
                   IsBasetype...}

l saw it has 4 arguments (there is a fifth without a Name so I don't know if I should include it):

PS> $a.Procedures[4].Params


Attributes      : IsIn
Type            : FC_SUPPLEMENT - NdrSupplementTypeReference
ServerAllocSize : 0
Offset          : 0
Name            : p0
IsIn            : True
IsOut           : False
IsInOut         : False
IsSimpleRef     : False

Explicit        : True
Generic         : False
Attributes      : 0
Type            : FC_BIND_CONTEXT - NdrSimpleTypeReference
ServerAllocSize : 0
Offset          : 0
Name            :
IsIn            : False
IsOut           : False
IsInOut         : False
IsSimpleRef     : False

Attributes      : MustSize, MustFree, IsIn
Type            : FC_UP - NdrPointerTypeReference
ServerAllocSize : 0
Offset          : 8
Name            : p1
IsIn            : True
IsOut           : False
IsInOut         : False
IsSimpleRef     : False

Attributes      : IsIn, IsBasetype
Type            : FC_HYPER - NdrSimpleTypeReference
ServerAllocSize : 0
Offset          : 16
Name            : p2
IsIn            : True
IsOut           : False
IsInOut         : False
IsSimpleRef     : False

Attributes      : MustSize, MustFree, IsOut
Type            : FC_RP - NdrPointerTypeReference
ServerAllocSize : 8
Offset          : 24
Name            : p3
IsIn            : False
IsOut           : True
IsInOut         : False
IsSimpleRef     : False

I connected the client:

PS> $a.Endpoints

UUID                                 Version Protocol Endpoint                Annotation
e7a216af-1ec1-447f-8d3f-a87278db564d 1.0     ncalrpc  LRPC-6981a149a72e0ebb3e

PS> $client = Get-RpcClient $rpc
PS> Connect-RpcClient $c -EndpointPath "LRPC-6981a149a72e0ebb3e"
PS> $c.Connected
True

But when I tried to call it with 4 parameters (p0,p1,p2 and p3) it didn't accept it:

PS> $c.HcsRpc_ShutdownSystem([NullString]::Value, [NullString]::Value, [NullString]::Value, [NullString]::Value)
Cannot find an overload for "HcsRpc_ShutdownSystem" and the argument count: "4".

But with 3 parameters it didn't throw the "Cannot find an overload" error.
It throw other error about using the wrong type but this is a different issue.

I am currently want to understand why the Params shows me 4 (maybe 5) parameters when the client can send only 3.

I reversed the vmcompute.exe and vmcompute.dll, it seems that in both (server and client) it receives 4 parameters and not 3:
image

Why I am getting the overload error when using 4 parameters?

System.AccessViolationException using RpcEndpointMapper against Windows Server 2022 Host

Code to Reproduce:

foreach (var computer in computers)
{
    var potentialString = $"ncacn_ip_tcp:{computer}";
    var results = RpcEndpointMapper.QueryEndpoints(potentialString);

    foreach (var result in results)
    {
        if (result.ProtocolSequence == "ncacn_ip_tcp")
        {
            Console.WriteLine($"Got result: {result}");
        }
    }
}

Result:

Multiple results are returned but fails when pinvoking RpcMgmtEpEltInqNext. authlogics02.authlogics.com is running Windows Server 2022, we don't see this behavior on other machines.

Got result: [50abc2a4-574d-40b3-9d66-ee4fd5fba076, 5.0] ncacn_ip_tcp:authlogics02.authlogics.com[58522]
Got result: [6bffd098-a112-3610-9833-46c3f874532d, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[58502]
Got result: [5b821720-f63b-11d0-aad2-00c04fc324db, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[58502]
Got result: [897e2e5f-93f3-4376-9c9c-fd2277495c27, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[58483]
Got result: [367abb81-9844-35f1-ad32-98f038001003, 2.0] ncacn_ip_tcp:authlogics02.authlogics.com[58464]
Got result: [12345678-1234-abcd-ef00-0123456789ab, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49676]
Got result: [0b6edbfa-4a24-4fc6-8a23-942b1eca65d1, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49676]
Got result: [ae33069b-a2a8-46ee-a235-ddfd339be281, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49676]
Got result: [4a452661-8290-4b36-8fbe-7f4093a94978, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49676]
Got result: [76f03f96-cdfd-44fc-a22c-64950a001209, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49676]
Got result: [29770a8f-829b-4158-90a2-78cd488501f7, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49671]
Got result: [86d35949-83c9-4044-b424-db363231fd0c, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49668]
Got result: [3a9ef155-691d-4449-8d05-09ad57031823, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49668]
Got result: [f6beaff7-1e19-4fbb-9f8f-b89e2018337c, 1.0] ncacn_ip_tcp:authlogics02.authlogics.com[49666]

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at NtApiDotNet.Win32.Win32NativeMethods.RpcMgmtEpEltInqNext(SafeRpcInquiryHandle InquiryContext, RPC_IF_ID IfId, SafeRpcBindingHandle& Binding, UUID ObjectUuid, SafeRpcStringHandle& Annotation)
at NtApiDotNet.Win32.RpcEndpointMapper.d__0.MoveNext() in D:\Github\sandbox-attacksurface-analysis-tools\NtApiDotNet\Win32\RpcEndpointMapper.cs:line 88

Bug in FromByteArray while handling IO_REPARSE_TAG_AF_UNIX

I encountered the following bug in FromByteArray while executing DumpReparsePoints with the handling of the IO_REPARSE_TAG_AF_UNIX tag.

filename: "C:\Users\xxxx\AppData\Local\Packages\TheDebianProject.DebianGNULinux_76v4gfsz19hv4\LocalState\fsserver" ends up with the bytestream: 230000800000000000000000000000000000000000000000

BinaryReader reader = new BinaryReader(new MemoryStream(ba), Encoding.Unicode); // results in IO_REPARSE_TAG_AF_UNIX (0x80000023)
ReparseTag tag = (ReparseTag)reader.ReadUInt32(); // results in IO_REPARSE_TAG_AF_UNIX (0x80000023)
int data_length = reader.ReadUInt16(); // results in 0 
// Reserved
reader.ReadUInt16();  // obsolete
long remaining_length = reader.RemainingLength(); // results in 16 (Remaining null bytes)
long expected_length = data_length; // results in 0 
if (!NtFileUtils.IsReparseTagMicrosoft(tag)) // returns false, doesn't enter the if statement
{
    expected_length += 16; // obsolete
}

if (remaining_length != expected_length) // 16 != 0, enters the if statement
{
    // Corrupted buffer. Return an opaque buffer with all the data until the end.
    return new OpaqueReparseBuffer(tag, reader.ReadToEnd()); // reader.ReadToEnd() ends with a System.OutOfMemoryException
}

Access violation when processing some dlls with Get-RpcServer

0:026> !dumpstack
OS Thread Id: 0x2ae4 (26)
Current frame: VCRUNTIME140_CLR0400!memcpy+0xff
Child-SP         RetAddr          Caller, Callee
000000fbf164ce10 00007ffb89cbab46 clr!SafeBuffer::PtrToStructure+0x16, calling VCRUNTIME140_CLR0400!memcpy
000000fbf164ce20 00007ffb89cbab13 clr!SafeBuffer::SizeOfType+0x43, calling clr!MethodTable::GetClass
000000fbf164ce40 00007ffb2a66cc9c (MethodDesc 00007ffb2aa03620 +0x2c System.Runtime.InteropServices.SafeBuffer.GenericPtrToStructure[[System.Byte, mscorlib]](Byte*, Byte ByRef, UInt32)), calling 00007ffb89cbab30 (stub for System.Runtime.InteropServices.SafeBuffer.PtrToStructureNative(Byte*, TypedReference, UInt32))
000000fbf164ce58 00007ffb89b56c5f clr!SafeHandle::DangerousAddRef+0x6f, calling clr!LazyMachStateCaptureState
000000fbf164ce80 00007ffb2a66ca22 (MethodDesc 00007ffb2aa035c0 +0x112 System.Runtime.InteropServices.SafeBuffer.ReadArray[[System.Byte, mscorlib]](UInt64, Byte[], Int32, Int32)), calling (MethodDesc 00007ffb2aa03620 +0 System.Runtime.InteropServices.SafeBuffer.GenericPtrToStructure[[System.Byte, mscorlib]](Byte*, Byte ByRef, UInt32))
000000fbf164cf00 00007ffb2a66c8e8 (MethodDesc 00007ffb2a9e4738 +0x48 NtApiDotNet.Win32.ImageSection.ToArray()), calling (MethodDesc 00007ffb2aa035c0 +0 System.Runtime.InteropServices.SafeBuffer.ReadArray[[System.Byte, mscorlib]](UInt64, Byte[], Int32, Int32))
000000fbf164cf10 00007ffb70abdb8a (MethodDesc 00007ffb706e6918 +0x1a System.Guid.ToByteArray()), calling clr!JIT_NewArr1VC_MP_InlineGetThread
000000fbf164cf40 00007ffb2a66c646 (MethodDesc 00007ffb2a9ec490 +0x56 NtApiDotNet.Win32.RpcServer+<FindRpcServerInterfaces>d__60.MoveNext()), calling (MethodDesc 00007ffb2a9e4738 +0 NtApiDotNet.Win32.ImageSection.ToArray())
000000fbf164cf60 00007ffb2a66c5c1 (MethodDesc 00007ffb2a9ec500 +0x51 NtApiDotNet.Win32.RpcServer+<FindRpcServerInterfaces>d__60.System.Collections.Generic.IEnumerable<NtApiDotNet.Win32.RpcServer.RpcOffset>.GetEnumerator()), calling clr!JIT_WriteBarrier
000000fbf164cf70 00007ffb2a66c445 (MethodDesc 00007ffb2a9e3988 +0x15 NtApiDotNet.Win32.RpcServer+<>c__DisplayClass51_0.<ParsePeFile>b__0(NtApiDotNet.Win32.ImageSection)), calling (MethodDesc 00007ffb2a9e59c8 +0 NtApiDotNet.NtObjectUtils.HasFlagSet[[NtApiDotNet.Win32.RpcServerParserFlags, NtApiDotNet]](NtApiDotNet.Win32.RpcServerParserFlags, NtApiDotNet.Win32.RpcServerParserFlags))
000000fbf164cfa0 00007ffb2a66c2c5 (MethodDesc 00007ffb2a9ebec0 +0x155 System.Linq.Enumerable+<SelectManyIterator>d__17`2[[System.__Canon, mscorlib],[NtApiDotNet.Win32.RpcServer+RpcOffset, NtApiDotNet]].MoveNext()), calling 00007ffb2a53d760
000000fbf164cfc0 00007ffb2a66c14c (MethodDesc 00007ffb2a9ebf30 +0x5c System.Linq.Enumerable+<SelectManyIterator>d__17`2[[System.__Canon, mscorlib],[NtApiDotNet.Win32.RpcServer+RpcOffset, NtApiDotNet]].System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()), calling clr!JIT_WriteBarrier
000000fbf164cfd0 00007ffb89b5b319 clr!JIT_GetCurrentManagedThreadId+0x9, calling clr!GetThread
000000fbf164d000 00007ffb2a66c015 (MethodDesc 00007ffb2a9e5720 +0x45 System.Linq.Enumerable.Any[[NtApiDotNet.Win32.RpcServer+RpcOffset, NtApiDotNet]](System.Collections.Generic.IEnumerable`1<RpcOffset>)), calling 00007ffb2a53d8a0
000000fbf164d050 00007ffb2a6695ae (MethodDesc 00007ffb2a9e14f8 +0x15e NtApiDotNet.Win32.RpcServer.ParsePeFile(System.String, System.String, System.String, NtApiDotNet.Win32.RpcServerParserFlags)), calling (MethodDesc 00007ffb2a9e5720 +0 System.Linq.Enumerable.Any[[NtApiDotNet.Win32.RpcServer+RpcOffset, NtApiDotNet]](System.Collections.Generic.IEnumerable`1<RpcOffset>))
000000fbf164d080 00007ffb89b769ef clr!GCInterface::SuppressFinalize+0x3f

The issue is reproduced with latest chrome.dll, presumably caused by the presence of .retplne section with zero attributes, which is mapped as PAGE_NOACCESS:

0:026> !vprot rdx
BaseAddress:       00007ffb36665000
AllocationBase:    00007ffb2d5b0000
AllocationProtect: 00000080  PAGE_EXECUTE_WRITECOPY
RegionSize:        0000000000001000
State:             00001000  MEM_COMMIT
Protect:           00000001  PAGE_NOACCESS
Type:              01000000  MEM_IMAGE

image

Suggested fix is to check Characteristics in SafeLoadLibraryHandle.SetupValues:

        for (int i = 0; i < header.FileHeader.NumberOfSections; ++i)
        {
            ImageSectionHeader section = (ImageSectionHeader)Marshal.PtrToStructure(buffer + i * header_size, typeof(ImageSectionHeader));
            ImageSection sect = new ImageSection(section, MappedAsImage, base_ptr);
            _image_sections.Add(sect);
        }

Win32Utils: Incorrect spelling in CreateSecurityCapabilities

James, I was just testing out some of the new features introduced with the most recent 1.1.29 release and I came across some spelling mistakes in the code. Particularly, I've got a lot of interest in Added proper enumeration of AppContainer profiles and support creating with capabilities. So when I was digging into that code, I came across the spelling mistakes which I believe date back further in time.

Quick search: https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/search?q=%22CreateSecuityCapabilities%22

Incorrect: Win32Utils.CreateSecuityCapabilities
Correct: Win32Utils.CreateSecurityCapabilities

  1. https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/blob/master/NtApiDotNet/Win32/Win32ProcessConfig.cs#L449
  2. https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/blob/master/NtApiDotNet/Win32/TokenUtils.cs#L420
  3. https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/blob/master/NtApiDotNet/Win32/Win32Utils.cs#L435

I don't know if this would cause any functional issues or whether it is just a benign spelling typo in the code, but figured I should mention it to you. Cheers!

Get-AccessibleWnf: Access denied errors

Running Get-AccessibleWnf results in an access denied error when running as a lower-privileged user:

Get-AccessibleWnf : (0xC0000022) - {Access Denied}
A process has requested access to an object, but has not been granted those access rights.

The exception's stacktrace shows the following:

PS C:\> error[0].Exception.StackTrace
   at NtApiDotNet.NtObjectUtils.CreateResult[T](NtStatus status, Boolean throw_on_error, Func`2 create_func, Action`1 error_func) in C:\code\sandbox-attacksurface-analysis-tools\NtApiDotNet\NtObjectUtils.cs:line 566
   at NtApiDotNet.NtObjectUtils.CreateResult[T](NtStatus status, Boolean throw_on_error, Func`1 create_func) in C:\code\sandbox-attacksurface-analysis-tools\NtApiDotNet\NtObjectUtils.cs:line 533
   at NtApiDotNet.NtWnf.Query[T](UInt64 state_name, WnfStateNameInformation info_class, Boolean throw_on_error) in C:\code\sandbox-attacksurface-analysis-tools\NtApiDotNet\NtWnf.cs:line 0
   at NtApiDotNet.NtWnf.get_SubscribersPresent() in C:\code\sandbox-attacksurface-analysis-tools\NtApiDotNet\NtWnf.cs:line 310
   at NtObjectManager.Cmdlets.Accessible.WnfAccessCheckResult..ctor(NtWnf wnf, AccessMask granted_access, SecurityDescriptor sd, TokenInformation token_info) in C:\code\sandbox-attacksurface-analysis-tools\NtObjectManager\Cmdlets\Accessible\WnfAccessCheckResult.cs:line 42
   at NtObjectManager.Cmdlets.Accessible.GetAccessibleWnfCmdlet.RunAccessCheck(IEnumerable`1 tokens) in C:\code\sandbox-attacksurface-analysis-tools\NtObjectManager\Cmdlets\Accessible\GetAccessibleWnfCmdlet.cs:line 74
   at NtObjectManager.Cmdlets.Accessible.CommonAccessBaseCmdlet.ProcessRecord() in C:\code\sandbox-attacksurface-analysis-tools\NtObjectManager\Cmdlets\Accessible\CommonAccessBaseCmdlet.cs:line 282
   at System.Management.Automation.CommandProcessor.ProcessRecord()

I worked around it temporarily by setting this code to not throw errors, but don't know how much that changes expected behavior elsewhere:

public bool SubscribersPresent => Query<int>(StateName, WnfStateNameInformation.SubscribersPresent, false).Result != 0;

How to get RPC procedures from the Endpoints

I am not sure if this is possible but I have a svchost.exe process that I want to see its procedures.
I used the following commands to get all the servers:

$a = Get-RpcAlpcServer | where-object {$_.ProcessName -eq "svchost.exe"}

I see the endpoints of each process but is there a way to find what procedures it has?
For example, in RPCView, I can see svchost.exe with PID 2288 and it has two endpoints and two interfaces that shows the procedures:
image

I tried to check of the Endpoints object has a way to get it but didn't see something:
image

NtApiDotNet, symbol package and SourceLink

It would be excellent if you could publish symbols for the nuget package, and adding sourcelink metadata would also be appreciated :)

I was going to submit a PR for it, but the contribution guidelines mention signing a copyright transfer thingie, which seems like too much work for this. Just adding a few lines to the csproj is all that's needed.

<PropertyGroup>
  <IncludeSymbols>true</IncludeSymbols>
  <SymbolPackageFormat>snupkg</SymbolPackageFormat>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>  
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>

That should be all that's needed to add the sourcelink info and publish a symbol package to the nuget symbol server :)

[Question] - Link NewCredentials To Process

Love the module. Thanks for all the work. I like to open my WindowsTerminal.exe and/or ssms.exe ( e.g. _SQL Server Management Studio ) with Network Credentials. When I have a few windows open it would be nice to run a command to check if the current process has negotiated the network credentials and what credentials did it negotiate with.

I'm essentially using Get-NtlogonSession to get the LogonId where the LogonType is NewCredentials. Then I can pass the LogonSession into Get-KerberosTicket to view the potential negotiated credential name. Now in order to map the LogonId to a process, I was using get-NtProcess -access QueryLimitedInformation to grab all the ProcessIds. Then I was using get-NttokenfromProcess to grab the AuthenticationId to map back to the LogonId from Get-NtLogonSession.

Is this the ideal way to do it or is there a more straightforward approach?

How to Get-NtNamedPipeFile programmatically?

Hi,

With PowerShell we can run:

PS C:\WINDOWS\system32> Get-NtNamedPipeFile("\Device\NamedPipe\initShutdown")

Handle Name         NtTypeName Inherit ProtectFromClose
------ ----         ---------- ------- ----------------
2988   InitShutdown File       False   False

I want to do it programmatically with C#. I found how it is being called with C#:

public class GetNtNamedPipeFileCmdlet : GetNtFileCmdlet
{
/// <summary>
/// Method to create an object from a set of object attributes.
/// </summary>
/// <param name="obj_attributes">The object attributes to create/open from.</param>
/// <returns>The newly created object.</returns>
protected override object CreateObject(ObjectAttributes obj_attributes)
{
return NtFile.CreateNamedPipe(obj_attributes, Access, ShareMode, Options, FileDisposition.Open, NamedPipeType.Bytestream,
NamedPipeReadMode.ByteStream, NamedPipeCompletionMode.CompleteOperation, 0, 0, 0, NtWaitTimeout.FromMilliseconds(0));
}
/// <summary>
/// Constructor
/// </summary>
public GetNtNamedPipeFileCmdlet()
{
ShareMode = FileShareMode.Read | FileShareMode.Write;
Options = FileOpenOptions.SynchronousIoNonAlert;
Access = FileAccessRights.GenericRead | FileAccessRights.GenericWrite | FileAccessRights.Synchronize;
}
}

I made the below function but I don't know how to initialize NtObject root :

FileShareMode ShareMode = FileShareMode.Read | FileShareMode.Write;
FileOpenOptions Options = FileOpenOptions.SynchronousIoNonAlert;
FileAccessRights Access = FileAccessRights.GenericRead | FileAccessRights.GenericWrite | FileAccessRights.Synchronize;

using (ObjectAttributes obj_attributes = new ObjectAttributes(i_NamedPipe, AttributeFlags.CaseInsensitive, root))
{
    var a = NtFile.CreateNamedPipe(obj_attributes, Access, ShareMode, Options, FileDisposition.Open, NamedPipeType.Bytestream,
                NamedPipeReadMode.ByteStream, NamedPipeCompletionMode.CompleteOperation, 0, 0, 0, NtWaitTimeout.FromMilliseconds(0));
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.