Skip to content

Commit f07c6d5

Browse files
committed
Added inheritable handles to native process creation.
1 parent 1fbc53b commit f07c6d5

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

NtApiDotNet/NtProcess.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ private static NtProcessCreateResult Create(NtProcessCreateConfig config, string
188188
dispose.Add(ProcessAttribute.SecureProcess(trustlet_config));
189189
}
190190

191+
if (config.InheritHandleList.Count > 0)
192+
{
193+
dispose.Add(ProcessAttribute.HandleList(config.InheritHandleList.Select(o => o.Handle)));
194+
}
195+
191196
var attr_list = dispose.AddResource(ProcessAttributeList.Create(dispose.OfType<ProcessAttribute>().Concat(config.AdditionalAttributes)));
192197
create_info.Data.InitFlags = config.InitFlags;
193198
if (config.CaptureAdditionalInformation)

NtApiDotNet/NtProcessCreateConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ public sealed class NtProcessCreateConfig
168168
/// Redirection DLL path. Only supported from 1903.
169169
/// </summary>
170170
public string RedirectionDllName { get; set; }
171+
172+
/// <summary>
173+
/// Inheritable handles.
174+
/// </summary>
175+
public List<NtObject> InheritHandleList { get; }
176+
171177
#endregion
172178

173179
#region Public Methods
@@ -209,6 +215,7 @@ public NtProcessCreateConfig()
209215
AdditionalAttributes = new List<ProcessAttribute>();
210216
ProcessDesiredAccess = ProcessAccessRights.MaximumAllowed;
211217
ThreadDesiredAccess = ThreadAccessRights.MaximumAllowed;
218+
InheritHandleList = new List<NtObject>();
212219
}
213220
#endregion
214221
}

NtApiDotNet/ProcessAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public static ProcessAttribute ProtectionLevel(PsProtection protection)
127127

128128
public static ProcessAttribute HandleList(IEnumerable<SafeHandle> handles)
129129
{
130-
return new ProcessAttribute(ProcessAttributeNum.HandleList, false, true, false,
131-
new SafeHandleListHandle(handles.Select(h => NtObject.DuplicateHandle(h.ToSafeKernelHandle()))));
130+
return new ProcessAttribute(ProcessAttributeNum.HandleList, false, true, false,
131+
handles.Select(h => h.DangerousGetHandle()).ToArray().ToBuffer());
132132
}
133133

134134
public static ProcessAttribute SecureProcess(NtProcessTrustletConfig trustlet_config)

NtObjectManager/NtObjectManager.psm1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,8 @@ function New-NtProcessConfig {
12881288
[switch]$TerminateOnDispose,
12891289
[switch]$Win32Path,
12901290
[switch]$CaptureAdditionalInformation,
1291-
[switch]$Secure
1291+
[switch]$Secure,
1292+
[NtApiDotNet.NtObject[]]$InheritHandle
12921293
)
12931294

12941295
if ($Win32Path) {
@@ -1315,6 +1316,9 @@ function New-NtProcessConfig {
13151316
}
13161317
$config.CaptureAdditionalInformation = $CaptureAdditionalInformation
13171318
$config.Secure = $Secure
1319+
if ($null -ne $InheritHandle) {
1320+
$config.InheritHandleList.AddRange($InheritHandle)
1321+
}
13181322

13191323
return $config
13201324
}

0 commit comments

Comments
 (0)