5

I have an issue with a program that I’m running on one of my work machines.

Treesize pro is a program that will scan an area (C:\, \\nasdrive\home, etc.) and give you a tree-view as well as other information on the area.

now I run this program on an account that has admin privileges and when I lunch it give the user account control pop up.

However if I search an area my admin account does not have access to (there are a few) it will work fine and show me all the info for the files, folder, size, modified and creation dates. I cannot open the files but I can see their names and go into subfolders. If I try this in explorer, I will get access denied.

I tried to do this with a script that I wrote it C# however if I try and do a Directory.getDirectories(); and Directory.GetFiles(); but even if I run my program as admin (right click run as admin) it will just give access denied command in the Catch block.

I really would like to know how Treesize is managing to list folders, sub-folders, and files that my account does not have access to.

Thanks

Roman Patutin
  • 2,171
  • 4
  • 23
  • 27
adam Wadsworth
  • 774
  • 1
  • 8
  • 26
  • 1
    I believe it is a matter of permissions. Your account has permission to list the contents of the folders, but not open the files. Perhaps Explorer does some clever tricks to hide folders where you can't open files and so. – Nick Feb 08 '19 at 13:48
  • 1
    Just a hint, not sure about this ... In the german wiki page (sadly not in the english version) of [TreeSize](https://de.wikipedia.org/wiki/TreeSize) is explaind, that TreeSize uses the [Master File Table](https://learn.microsoft.com/en-us/windows/desktop/fileio/master-file-table) and reads its containing meta data. Those might not be protected for not-admin users ... Again: just a guess. Second link is worth a read. – nilsK Feb 08 '19 at 13:54

1 Answers1

3

TreeSize reads the data through the NTFS backup API (see https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/back-up-files-and-directories ).

From the notes from treesize: https://manuals.jam-software.de/treesize/EN/notesonntfs.html

Access Control Lists The way users can access files and folders can be restricted. One can grant or deny other users or groups certain rights [...]. That way one can even deny administrators to access files and folders. If an administrator tries to access a folder in the Windows Explorer to which the owner denied any other users reading access, an "Access Denied" error message will be displayed. However, TreeSize is able to scan such folders, if you are logged in as administrator or as a user that has the right to perform backups (This option can be changed at "Control Panel > Administrative Tools > Local Security Policy" and with the user editor of Windows).

An in-depth look into the access rights can be found in https://learn.microsoft.com/en-us/windows/win32/fileio/file-security-and-access-rights

The SE_BACKUP_NAME and SE_RESTORE_NAME access privileges were specifically created to provide this ability to backup applications. If these privileges have been granted and enabled in the access token of the backup application process, it can then call CreateFile to open your file or directory for backup, specifying the standard READ_CONTROL access right as the value of the dwDesiredAccess parameter. However, to identify the calling process as a backup process, the call to CreateFile must include the FILE_FLAG_BACKUP_SEMANTICS flag in the dwFlagsAndAttributes parameter. This will allow the backup application process to open your file and override the standard security checking.

HANDLE hFile = CreateFile( fileName,                   // lpFileName
                       READ_CONTROL,               // dwDesiredAccess
                       0,                          // dwShareMode
                       NULL,                       // lpSecurityAttributes
                       OPEN_EXISTING,              // dwCreationDisposition
                       FILE_FLAG_BACKUP_SEMANTICS, // dwFlagsAndAttributes
                       NULL );                     // hTemplateFile

You can find more information on

Niko
  • 6,133
  • 2
  • 37
  • 49
  • Good answer. To be clear, the FILE_FLAG_BACKUP_SEMANTICS flag won't do any good unless the program is running with admin privileges or the logged on user happens to have been given special read rights over the whole file system for backup purposes. On the other hand, the Microsoft Store version of TreeSize does enjoy access by default (no admin session) to folders typically forbidden from being listed such as C:\Program Files\Windows Apps\ . This may be a side effect of the 'runFullTrust' capability declared in the app's manifest. – Julio Gorgé Apr 09 '21 at 19:09