Created
January 29, 2023 14:20
-
-
Save mtask/9b2a70cc4f32cc9d2e06634aab6a5590 to your computer and use it in GitHub Desktop.
Convert SIDs in usert rights assingments to names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$RESULT = @{} | |
$OUTFILE = $env:TEMP+"\out.cf" | |
# Use SecEdit to export USER_RIGHTS configuration | |
SecEdit.exe /export /areas USER_RIGHTS /cfg $OUTFILE >NULL | |
# Loop over output file's content | |
foreach($line in Get-Content -Path $OUTFILE) { | |
$line_arr = $line.Split(' ') | |
# Seperate privilige name | |
$PRIV = $line_arr[0] | |
# Output contains some other lines as well.. | |
#.. and this ensures that we are only checking relevant lines | |
if ($line -match '[A-Za-z]+\s=\s.*') { | |
# Seperate SIDs that are seperated with comma | |
foreach( $sid_str in $line_arr[2].Split(',') ) { | |
# Some names are already converted lik "Guest" | |
if ( $sid_str.StartsWith('*S-') ) { | |
$sid_str = $sid_str.Replace('*', '') | |
$CONVERTED_SID = $([wmi]"Win32_SID.SID='$sid_str'"|select -ExpandProperty AccountName) | |
if ($RESULT.ContainsKey($PRIV) ) { | |
$RESULT[$PRIV] += $CONVERTED_SID | |
} | |
else{ | |
$RESULT.add($PRIV, @($CONVERTED_SID)) | |
} | |
}else { | |
if ($RESULT.ContainsKey($PRIV) ) { | |
$RESULT[$PRIV] += $sid_str | |
} | |
else{ | |
$RESULT.add($PRIV, @($sid_str)) | |
} | |
} | |
} | |
} | |
} | |
# Remove SecEdit export file | |
del $OUTFILE | |
# Convert results to JSON | |
Write-Host $($RESULT | ConvertTo-Json -Depth 4) |
Author
mtask
commented
Jan 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment