From 0b041ad69481eedd671b862cf348ffc3b063087b Mon Sep 17 00:00:00 2001 From: Signum21 Date: Sun, 16 Mar 2025 05:43:48 +0100 Subject: [PATCH] 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 --- winPEAS/winPEASexe/winPEAS/Helpers/MyUtils.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/winPEAS/winPEASexe/winPEAS/Helpers/MyUtils.cs b/winPEAS/winPEASexe/winPEAS/Helpers/MyUtils.cs index c183446..5fb7e50 100644 --- a/winPEAS/winPEASexe/winPEAS/Helpers/MyUtils.cs +++ b/winPEAS/winPEASexe/winPEAS/Helpers/MyUtils.cs @@ -184,9 +184,17 @@ namespace winPEAS.Helpers ////////////////////// public static List 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(); + } } internal static byte[] CombineArrays(byte[] first, byte[] second)