Skip to content

Commit 267b66c

Browse files
committed
Updated ACL extraction scripts for tests
1 parent 7628b3e commit 267b66c

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

securitydescriptor/tests/scripts/Dump-ActiveDirectoryAcls.ps1.ps1 renamed to securitydescriptor/tests/scripts/Dump-ActiveDirectoryAcls.ps1

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ $os = Get-CimInstance Win32_OperatingSystem
1414
$osKey = "$($os.Caption) - $($os.Version)"
1515

1616
$result = @{
17-
$osKey = @{
18-
ActiveDirectory = @()
17+
Metadata = @{
18+
Timestamp = $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
19+
OS = @{
20+
OSVersion = $os.Version
21+
OSArchitecture = $os.OSArchitecture
22+
OSBuild = $os.BuildNumber
23+
OSVersionString = $os.VersionString
24+
}
1925
}
26+
ActiveDirectory = @()
2027
}
2128

2229
# -----------------------------
@@ -52,20 +59,28 @@ foreach ($nc in $namingContexts) {
5259
}
5360

5461
$dn = $res.Properties["distinguishedName"][0]
62+
Write-Host $dn
5563
$sdBytes = $res.Properties["nTSecurityDescriptor"][0]
5664

57-
$result[$osKey]["ActiveDirectory"] += [PSCustomObject]@{
65+
$result["ActiveDirectory"] += [PSCustomObject]@{
5866
name = $dn
5967
hexdata = (Convert-BytesToHex $sdBytes)
6068
}
6169
}
6270
}
6371

6472
# Deterministic ordering
65-
$result[$osKey]["ActiveDirectory"] =
66-
$result[$osKey]["ActiveDirectory"] | Sort-Object name
73+
$result["ActiveDirectory"] =
74+
$result["ActiveDirectory"] | Sort-Object name
6775

6876
# -----------------------------
6977
# Output JSON
7078
# -----------------------------
71-
$result | ConvertTo-Json -Depth 5
79+
80+
$dirPath = Join-Path -Path (Get-Location) -ChildPath $osKey
81+
if (-not (Test-Path -Path $dirPath -PathType Container)) {
82+
New-Item -Path $dirPath -ItemType Directory | Out-Null
83+
}
84+
85+
$jsonPath = Join-Path -Path $dirPath -ChildPath "ActiveDirectory.json"
86+
$result | ConvertTo-Json -Depth 5 | Set-Content -Path $jsonPath -Encoding UTF8

securitydescriptor/tests/scripts/Dump-LocalFileSystemAcls.ps1

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ $os = Get-CimInstance Win32_OperatingSystem
1414
$osKey = "$($os.Caption) - $($os.Version)"
1515

1616
$result = @{
17-
$osKey = @{
18-
LocalFileSystem = @()
17+
Metadata = @{
18+
Timestamp = $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
19+
OS = @{
20+
OSVersion = $os.Version
21+
OSArchitecture = $os.OSArchitecture
22+
OSBuild = $os.BuildNumber
23+
OSVersionString = $os.VersionString
24+
}
1925
}
26+
LocalFileSystem = @()
2027
}
2128

2229
# -----------------------------
@@ -28,10 +35,11 @@ foreach ($root in $roots) {
2835
Get-ChildItem -Path $root -Recurse -Force -ErrorAction SilentlyContinue |
2936
ForEach-Object {
3037
try {
38+
Write-Host $_.FullName
3139
$acl = Get-Acl -LiteralPath $_.FullName
3240
$sdBytes = $acl.GetSecurityDescriptorBinaryForm()
3341

34-
$result[$osKey]["LocalFileSystem"] += [PSCustomObject]@{
42+
$result["LocalFileSystem"] += [PSCustomObject]@{
3543
name = $_.FullName -replace "\\", "/"
3644
hexdata = (Convert-BytesToHex $sdBytes)
3745
}
@@ -43,10 +51,16 @@ foreach ($root in $roots) {
4351
}
4452

4553
# Deterministic ordering
46-
$result[$osKey]["LocalFileSystem"] =
47-
$result[$osKey]["LocalFileSystem"] | Sort-Object name
54+
$result["LocalFileSystem"] =
55+
$result["LocalFileSystem"] | Sort-Object name
4856

4957
# -----------------------------
5058
# Output JSON
5159
# -----------------------------
52-
$result | ConvertTo-Json -Depth 5
60+
$dirPath = Join-Path -Path (Get-Location) -ChildPath $osKey
61+
if (-not (Test-Path -Path $dirPath -PathType Container)) {
62+
New-Item -Path $dirPath -ItemType Directory | Out-Null
63+
}
64+
65+
$jsonPath = Join-Path -Path $dirPath -ChildPath "LocalFileSystem.json"
66+
$result | ConvertTo-Json -Depth 5 | Set-Content -Path $jsonPath -Encoding UTF8

0 commit comments

Comments
 (0)