Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
How can I create a protected directory that I can guarantee has only been modified by a specific user?

I am developing a .NET Windows Service using C# that runs as the SYSTEM user so that it has permissions to install software updates etc.

I want the service to download an executable file to a protected directory and launch it. However, I want to make sure that I've considered security and that it isn't possible for another user to copy a file into the directory that the service uses and then have the file executed with SYSTEM privileges.

I've looked into creating a directory that only the SYSTEM user has access to using an ACL as follows.

var localSystemIdentifier = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);

var directorySecurity = new DirectorySecurity();
directorySecurity.AddAccessRule(new FileSystemAccessRule(localSystemIdentifier, FileSystemRights.FullControl, AccessControlType.Allow));
directorySecurity.SetOwner(_localSystemIdentifier);

Directory.CreateDirectory(_pathToTempBootstrapperDirectory, directorySecurity);

Subsequent to this, I check that the owner of the directory is the SYSTEM user before I allow a cached copy of the executable file that has been downloaded to be used.

var acl = Directory.GetAccessControl(_pathToTempBootstrapperDirectory);

if (acl.GetOwner(typeof(SecurityIdentifier)) != localSystemIdentifier)
{
    cache = false;
}

However, if a user with the right permissions was able to change the owner of the directory to themselves, copy in a file, and then change the owner back to the SYSTEM user, the above check would not be of any benefit.

Perhaps the only option is to always recreate the download folder with the strict ACL and redownload the file every time to prevent the possibility of the scenario above.

In short, my question is as follows; is there a way that I can create a protected directory that I can guarantee has only ever been created or modified by the SYSTEM user?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

if a user with the right permissions was able to change the owner of the directory

If a user has administrative permissions he/she can just do whatever he/she wants without the help from your program. Raymond Chen calls this the "airtight hatchway", i.e. you need to protect against a user doing things he/she would not otherwise be allowed to, but there is no reason to protect against things the user already have permission to do.

I'm not an expert in windows permissions, but think that taking over ownership of a directory owned by SYSTEM requires admin permission.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!