Write
Write
Summary
Description
Identification
PowerShell
function Find-FileWrite {
[CmdletBinding()]
param(
# File or directory path. Accepts pipeline input.
[Parameter(Mandatory, Position=0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Alias('FullName')]
[string[]]$Path,
# Scan subdirectories when Path is a directory
[switch]$Recurse,
# Export path
[string]$OutputPath = "Write.csv",
# Which rights to match
[ValidateSet('FullControl','Modify','Write')]
[string[]]$Rights = @('FullControl','Modify','Write'),
# Include inherited ACEs (default is to exclude them)
[switch]$IncludeInherited,
# Limit to these extensions when scanning directories (ignored for single files)
[string[]]$IncludeExtensions = @('.ps1','.psm1','.psd1','.bat','.cmd','.vbs','.js'),
# If set, include all files when scanning directories (don’t filter by extension)
[switch]$AllFiles)
begin {
$Allow = [System.Security.AccessControl.AccessControlType]::Allow
$FSR = [System.Security.AccessControl.FileSystemRights]
$wantFull = 'FullControl' -in $Rights
$wantMod = 'Modify' -in $Rights
$wantWrite = 'Write' -in $Rights
$results = New-Object System.Collections.Generic.List[object]
function Test-HasWantedRight {
param([System.Security.AccessControl.FileSystemRights]$r)
if ($wantFull -and (($r -band $FSR::FullControl) -ne 0)) { return $true }
if ($wantMod -and (($r -band $FSR::Modify) -ne 0)) { return $true }
if ($wantWrite -and (($r -band $FSR::Write) -ne 0)) { return $true }
return $false
}
}
process {
foreach ($p in $Path) {
if (-not (Test-Path -LiteralPath $p)) {
Write-Warning "Path not found: $p"
continue
}
$item = Get-Item -LiteralPath $p -ErrorAction SilentlyContinue
if (-not $item) {
Write-Warning "Unable to read item: $p"
continue
}
# Build file list
if ($item.PSIsContainer) {
$files = if ($Recurse) {
Get-ChildItem -LiteralPath $p -File -Recurse -ErrorAction SilentlyContinue
} else {
Get-ChildItem -LiteralPath $p -File -ErrorAction SilentlyContinue
}
if (-not $AllFiles) {
$extHash = @{}
foreach ($e in $IncludeExtensions) { $extHash[$e.ToLower()] = $true }
$files = $files | Where-Object { $extHash.ContainsKey([IO.Path]::GetExtension($_.FullName).ToLower()) }
}
}
else {
$files = ,$item
}
foreach ($f in $files) {
try {
$acl = Get-Acl -LiteralPath $f.FullName
} catch {
Write-Warning "Failed to get ACL for $($f.FullName): $($_.Exception.Message)"
continue
}
foreach ($ace in $acl.Access) {
if ($ace.AccessControlType -ne $Allow) { continue }
if (-not $IncludeInherited -and $ace.IsInherited) { continue }
if (-not (Test-HasWantedRight $ace.FileSystemRights)) { continue }
$results.Add([pscustomobject]@{
Path = $f.FullName
Identity = $ace.IdentityReference.Value
Rights = $ace.FileSystemRights
IsInherited = $ace.IsInherited
InheritanceFlags = $ace.InheritanceFlags
PropagationFlags = $ace.PropagationFlags
})
}
}
}
}
end {
if ($results.Count -gt 0) {
$results | Sort-Object Path, Identity | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
$results
} else {
Write-Verbose "No matching ACEs found."
}
}
}
File Manager

Exploitation


Important Note
Mitigation

Detection
Event ID
Description
Fields/Attributes
References
References
Last updated
Was this helpful?