Skip to content

Commit

Permalink
Implement extraction of ACL rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
grayed committed Aug 30, 2020
1 parent 1e3e523 commit 1c950cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
51 changes: 44 additions & 7 deletions Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Vanara.PInvoke;
using System.Text;
using System.IO.Pipes;
using System.Security.AccessControl;

namespace PipeExplorer
{
Expand Down Expand Up @@ -145,21 +146,57 @@ public static IEnumerable<PipeModel> GetPipes(string pipeHost = ".")
{
using (handle)
{
//ACL? dacl = new ACL(), sacl = null;
//SECURITY_DESCRIPTOR? attrs = null;
//IntPtr ownerSid = new IntPtr(), groupSid = new IntPtr();
var err = GetSecurityInfo(handle.DangerousGetHandle(), SE_OBJECT_TYPE.SE_FILE_OBJECT,
SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION | SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION | SECURITY_INFORMATION.DACL_SECURITY_INFORMATION,
out var ownerSid, out var groupSid, out var dacl, out _, out _);
if (err.Succeeded)
{
StringBuilder ownerNameBuf = new StringBuilder(1024), groupNameBuf = new StringBuilder(1024), domainBuf = new StringBuilder(1024);
int ownerNameBufLen = ownerNameBuf.Capacity, groupNameBufLen = ownerNameBuf.Capacity, domainBufLen = domainBuf.Capacity;
int ownerNameBufLen = 1024, groupNameBufLen = 1024, domainBufLen = 1024;
StringBuilder ownerNameBuf = new StringBuilder(ownerNameBufLen);
StringBuilder groupNameBuf = new StringBuilder(groupNameBufLen);
StringBuilder domainBuf = new StringBuilder(domainBufLen);
LookupAccountSid(null, ownerSid, ownerNameBuf, ref ownerNameBufLen, domainBuf, ref domainBufLen, out var ownerAccType);
LookupAccountSid(null, groupSid, groupNameBuf, ref groupNameBufLen, null, ref domainBufLen, out var groupAccType);
//

acl = new AclModel(ownerNameBuf.ToString(), groupNameBuf.ToString(), null);
List<AclRuleModel> rules = null;
if (dacl.IsValidAcl())
{
var cnt = dacl.AceCount();
rules = new List<AclRuleModel>((int)cnt);
for (uint i = 0; i < cnt; i++)
{
if (GetAce(dacl, i, out var ace))
{
var sid = ace.GetSid();
int sidNameLen = 1024, sidDomainLen = 1024;
StringBuilder sidNameBuf = new StringBuilder(sidNameLen);
StringBuilder sidDomainBuf = new StringBuilder(sidDomainLen);
LookupAccountSid(null, sid, sidNameBuf, ref sidNameLen, sidDomainBuf, ref sidDomainLen, out var sidAccType);

bool isAllowing;
switch (ace.GetHeader().AceType)
{
case AceType.AccessAllowed:
isAllowing = true;
break;
case AceType.AccessDenied:
isAllowing = false;
break;
default:
continue;
}

var mask = ace.GetMask();
// make Enum formatter happy, since there are no flags for 0x60 bits
mask &= 0xFFFFFF9F;

if (sidNameBuf.Length > 0)
rules.Add(new AclRuleModel(sidNameBuf.ToString(), isAllowing, (PipeAccessRights)mask));
}
}
}

acl = new AclModel(ownerNameBuf.ToString(), groupNameBuf.ToString(), rules);
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions pipeexplorer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ Source: "bin\{#BuildConfig}\MahApps.Metro.dll"; DestDir: "{app}"; Flags: ignorev
Source: "bin\{#BuildConfig}\MahApps.Metro.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Microsoft.Xaml.Behaviors.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Microsoft.Xaml.Behaviors.xml"; DestDir: "{app}"; Flags: ignoreversion
; Source: "bin\{#BuildConfig}\PInvoke.AdvApi32.dll"; DestDir: "{app}"; Flags: ignoreversion
; Source: "bin\{#BuildConfig}\PInvoke.AdvApi32.xml"; DestDir: "{app}"; Flags: ignoreversion
; Source: "bin\{#BuildConfig}\PInvoke.Kernel32.dll"; DestDir: "{app}"; Flags: ignoreversion
; Source: "bin\{#BuildConfig}\PInvoke.Kernel32.xml"; DestDir: "{app}"; Flags: ignoreversion
; Source: "bin\{#BuildConfig}\PInvoke.Windows.Core.dll"; DestDir: "{app}"; Flags: ignoreversion
; Source: "bin\{#BuildConfig}\PInvoke.Windows.Core.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\ReactiveUI.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\ReactiveUI.Fody.Helpers.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\ReactiveUI.Fody.Helpers.xml"; DestDir: "{app}"; Flags: ignoreversion
Expand All @@ -96,6 +90,16 @@ Source: "bin\{#BuildConfig}\System.Threading.Tasks.Extensions.dll"; DestDir: "{a
Source: "bin\{#BuildConfig}\System.Threading.Tasks.Extensions.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\System.ValueTuple.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\System.ValueTuple.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.Core.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.Core.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Cryptography.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Cryptography.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Kernel32.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Kernel32.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Security.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Security.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Shared.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\Vanara.PInvoke.Shared.xml"; DestDir: "{app}"; Flags: ignoreversion

Source: "bin\{#BuildConfig}\ru\*.dll"; DestDir: "{app}\de"; Flags: ignoreversion
Source: "bin\{#BuildConfig}\ru\*.dll"; DestDir: "{app}\en"; Flags: ignoreversion
Expand Down

0 comments on commit 1c950cb

Please sign in to comment.