How to change file permissions on Windows via powershell / cmd?

I want to achieve the permissions aspect equivalent on Windows side via PowerShell or cmd, however I couldn't find a solution in order to correctly do this. If someone could help me to achieve this in the correct way.

[sudo] adduser test
[sudo] gcc vuln.c -o vuln -fno-stack-protector -m32 -z execstack

the part I am getting issues to make it Windows style

[sudo] chown root:test vuln
[sudo] chmod 550 vuln
[sudo] chmod u+s vuln
-r-sr-x--- 1 root test 7392 Dec 22 00:27 vuln

1 Answer

The permission system on Windows is called ACL. To edit the ACL list use

  • cacls on Windows prior to Vista

    For example to add Read-Only permission to myfile.txt

    CACLS myfile.txt /E /G "Power Users":R
  • icacls on Windows Vista and up

    For example to grant the group FileAdmins 'Delete' and 'Write DAC' permissions to C:\demo\example:

    icacls "C:\demo\example" /grant:r FileAdmins:(D,WDAC)
  • Get-Acl and Set-Acl in PowerShell

    For example to copy the ACL from C:\Dog.txt to C:\Cat.txt use this

    Get-Acl -Path "C:\Dog.txt" | Set-Acl -Path "C:\Cat.txt"

To take ownership you'll need to use takeown: takeown /f lostfile. In PowerShell you can use System.Security.AccessControl.FileSecurity.SetOwner

For more information

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like