I am developing a .NET Windows Service using C# that needs to download an executable file and run it.
I need the Windows Service to run with SYSTEM privileges in order to allow it to install software updates among other things.
For security reasons, I would like to download the executable to a location that is only accessible by the SYSTEM user, or at least can only be written to by the SYSTEM user.
I want to avoid a situation where a standard user could potentially copy an executable file to a known location and then for the Windows Service to run that executable with SYSTEM privileges. This is something that I'm very keen to avoid.
I've looked around, but I'm not sure what would be best for the above scenario. Should I be creating a download folder in the current user's temp directory (e.g. Path.GetTempPath()
in .NET) and setting some sort of ACL for this before downloading the executable file into it, or is there another directory on the system that is already well secured and is not accessible by standard users or even to other users generally?