Handle path access denied

The program crashes when trying to access a path that is not allowed.
An exampe of this can be found on the latest HackTheBox machine (TheFrizz) where the starting user can't access the path C:\Users
This commit is contained in:
Signum21 2025-03-16 05:43:48 +01:00 committed by GitHub
parent ce5cb1ad9c
commit 0b041ad694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -184,9 +184,17 @@ namespace winPEAS.Helpers
//////////////////////
public static List<string> ListFolder(String path)
{
string root = @Path.GetPathRoot(Environment.SystemDirectory) + path;
var dirs = from dir in Directory.EnumerateDirectories(root) select dir;
return dirs.ToList();
try
{
string root = @Path.GetPathRoot(Environment.SystemDirectory) + path;
var dirs = from dir in Directory.EnumerateDirectories(root) select dir;
return dirs.ToList();
}
catch(Exception ex)
{
//Path can't be accessed
return new List<string>();
}
}
internal static byte[] CombineArrays(byte[] first, byte[] second)