
관리자 그룹(sid: S-1-5-32-544)에게만 파일 또는 폴더의 소유권(SeTakeOwnershipPrivilege)을 가져올 수 있는 권한이 있는지 확인해야 합니다.
이 권한이 있는 모든 사용자/그룹의 개요를 어떻게 볼 수 있습니까?
내가 이미 찾아서 시도한 것은 다음 명령입니다.
secedit /export /areas USER_RIGHTS /cfg output.txt
파일의 출력은 매우 유용해 보입니다.
[유니코드]
유니코드=예
[권한 권한]
SeNetworkLogonRight = *S-1-5-32-544
...
SeTakeOwnershipPrivilege = *S-1-5-32-544
...
[버전]
서명="$CHICAGO$"
개정=1
위의 이 방법을 사용하면 Powershell 스크립트에서 파일을 읽고 권한을 검색한 후 나중에 파일을 삭제해야 합니다.
외부 모듈이나 실행 파일 없이 Powershell에서 이 작업을 수행하는 다른 방법이 있습니까?
공급해 주셔서 감사합니다.
건배
데이비드
답변1
을 이용하는 또 다른 방법이 있습니다.LsaEnumerateAccountsWithUserRightWin32 API 함수. 이는 C#으로 코딩해야 합니다(핀보크) 스크립트와 코드 정의가 매우 길고 지저분해질 것입니다.
위의 내용을 피하고 대신 실행 파일을 래핑하겠습니다. 바퀴를 재발명하는 이유는 무엇입니까?
# Check this priviledge.
$privilege = 'SeDenyInteractiveLogonRight'
# Create temp file for executable output.
$tempFile = [System.IO.Path]::GetTempFileName()
# Run the executable and wait for it to finish.
Start-Process -FilePath secedit.exe -ArgumentList "/export /areas USER_RIGHTS /cfg $tempFile" -Wait -WindowStyle Hidden
# Run through lines in the output file.
Get-Content $tempFile -Encoding Unicode | Where-Object {
# Where the privilege is listed.
$_ -match $privilege } | ForEach-Object {
# Seperate the key and values.
$_.split('=')[1].split(',') | ForEach-Object {
# Ouput the user/SID values
$_.trim()
}
}
답변2
순수한 PS 솔루션은 아니지만 그럼에도 불구하고 옵션입니다. :)
Microsoft의 AccessChk 유틸리티(여기에서 다운로드하십시오) SecEdit 대신.
SecEdit와 달리 AccessChk는 stdout으로 출력하므로 출력을 PS 변수로 쉽게 캡처한 다음 해당 변수를 확인할 수 있습니다(중간 파일 필요 없음).
다음과 같은 것 :
$privToCheckFor = "SeTakeOwnershipPrivilege"
$groupPrivs = .\accesschk -a administrators *
if ((Out-String -InputObject $groupPrivs).IndexOf($privToCheckFor) -ge 0) {
Write-Host "Has Privilege"
} else {
Write-Host "Doesn't Have Privilege"
}
답변3
답변4
해결책은 다음과 같습니다.
(Get-WmiObject -Namespace root\rsop\computer -Class RSOP_UserPrivilegeRight | Where-Object {$_.UserRight -eq "SeTakeOwnershipPrivilege"}).AccountList