This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathicacls.cs
67 lines (57 loc) · 2.41 KB
/
icacls.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Derived from: https://stackoverflow.com/questions/3507862/duplicate-getaccessrules-filesystemaccessrule-entries
// To Compile:
// C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:exe /out:icacls.exe icacls.cs
using System;
using System.IO;
using System.Security.AccessControl;
namespace icacls
{
class Program
{
public static void Main(string[] args)
{
try
{
if (args.Length == 0 || (args.Length > 0 && args[0] == "/?"))
{
Console.WriteLine(@"Displays permissions, grouped by user/group, for each file or directory specified
USAGE:
icacls.exe <file_or_directory> [...] [/?]
Example:
icacls.exe passwords.txt users.txt");
}
else
{
int i = 0;
foreach (string path in args)
{
Console.WriteLine("Permissions for: " + path);
FileSecurity fSecurity = new FileSecurity(path, AccessControlSections.Access);
foreach (FileSystemAccessRule fsar in fSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
Console.WriteLine(" {0}", fsar.IdentityReference.Value);
Console.WriteLine(" Type: {0}", fsar.AccessControlType);
Console.WriteLine(" Rights: {0}", fsar.FileSystemRights);
Console.WriteLine(" Source: {0}", fsar.IsInherited ? "Inherited" : "Explicit");
Console.WriteLine(" Propagation: {0}", fsar.PropagationFlags);
Console.WriteLine(" Inheritance: {0}", fsar.InheritanceFlags);
}
// Print extra space as a separator when multiple paths are specified
if (i++ < args.Length - 1)
{
Console.WriteLine("");
}
}
}
}
catch (Exception e)
{
Console.Error.WriteLine("[-] ERROR: {0}", e.Message.Trim());
}
finally
{
Console.WriteLine("\nDONE");
}
}
}
}