Пример #1
0
        /// <summary>
        /// Gets a directory listing of a directory.
        /// </summary>
        /// <param name="Path">The path of the directory to get a listing of.</param>
        /// <returns>CoreSploitResultList of FileSystemEntryResults.</returns>
        public static CoreSploitResultList <FileSystemEntryResult> GetDirectoryListing(string Path)
        {
            CoreSploitResultList <FileSystemEntryResult> results = new CoreSploitResultList <FileSystemEntryResult>();

            foreach (string dir in Directory.GetDirectories(Path))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(dir);
                results.Add(new FileSystemEntryResult
                {
                    Name              = dirInfo.FullName,
                    Length            = 0,
                    CreationTimeUtc   = dirInfo.CreationTimeUtc,
                    LastAccessTimeUtc = dirInfo.LastAccessTimeUtc,
                    LastWriteTimeUtc  = dirInfo.LastWriteTimeUtc
                });
            }
            foreach (string file in Directory.GetFiles(Path))
            {
                FileInfo fileInfo = new FileInfo(file);
                results.Add(new FileSystemEntryResult
                {
                    Name              = fileInfo.FullName,
                    Length            = fileInfo.Length,
                    CreationTimeUtc   = fileInfo.CreationTimeUtc,
                    LastAccessTimeUtc = fileInfo.LastAccessTimeUtc,
                    LastWriteTimeUtc  = fileInfo.LastWriteTimeUtc
                });
            }
            return(results);
        }
Пример #2
0
        /// <summary>
        /// Pings specified ComputerNames to identify live systems.
        /// </summary>
        /// <param name="ComputerNames">ComputerNames to ping.</param>
        /// <param name="Timeout">Timeout (in milliseconds) before a ComputerName is considered down.</param>
        /// <param name="Threads">Number of threads with which to ping simultaneously</param>
        /// <returns></returns>
        public static CoreSploitResultList <PingResult> Ping(IList <string> ComputerNames, int Timeout = 250,
                                                             int Threads = 100)
        {
            IList <string> pingAddresses = Utilities.ConvertCidrToIPs(ComputerNames).Distinct().ToList();
            CoreSploitResultList <PingResult> pingResults = new CoreSploitResultList <PingResult>();

            using (CountdownEvent waiter = new CountdownEvent(pingAddresses.Count))
            {
                object pingResultsLock = new object();
                int    runningThreads  = 0;
                foreach (string ComputerName in pingAddresses)
                {
                    Ping       ping       = new Ping();
                    PingResult pingResult = new PingResult(ComputerName, true);
                    ping.PingCompleted += new PingCompletedEventHandler((sender, e) =>
                    {
                        if (e.Reply != null && e.Reply.Status == IPStatus.Success)
                        {
                            lock (pingResultsLock)
                            {
                                pingResults.Add(pingResult);
                            }
                        }

                        ((CountdownEvent)e.UserState).Signal();
                    });
                    while (runningThreads >= Threads)
                    {
#warning Causes a core dump on Linux
                        waiter.Wait();
                        runningThreads--;
                    }

                    try
                    {
                        ping.SendAsync(ComputerName, Timeout, waiter);
                        runningThreads++;
                    }
                    catch
                    {
                    }
                }

                waiter.Wait(Timeout * pingAddresses.Count);
            }

            return(pingResults);
        }
Пример #3
0
        /// <summary>
        /// Gets a list of running processes on the system.
        /// </summary>
        /// <returns>List of ProcessResults.</returns>
        public static CoreSploitResultList <ProcessResult> GetProcessList()
        {
            Platform processorArchitecture = Platform.Unknown;

            if (System.Environment.Is64BitOperatingSystem)
            {
                processorArchitecture = Platform.x64;
            }
            else
            {
                processorArchitecture = Platform.x86;
            }
            Process[] processes = Process.GetProcesses().OrderBy(P => P.Id).ToArray();
            CoreSploitResultList <ProcessResult> results = new CoreSploitResultList <ProcessResult>();

            foreach (Process process in processes)
            {
                int    processId       = process.Id;
                int    parentProcessId = 0;
                string processName     = process.ProcessName;
                string processPath     = string.Empty;
                int    sessionId       = process.SessionId;
                //string processOwner = GetProcessOwner(process);
                Platform processArch = Platform.Unknown;

                if (parentProcessId != 0)
                {
                    try
                    {
                        processPath = process.MainModule.FileName;
                    }
                    catch (System.ComponentModel.Win32Exception) { }
                }

                /**
                 * if (processorArchitecture == Platform.x64)
                 * {
                 *  processArch = IsWow64(process) ? Win32.Kernel32.Platform.x86 : Win32.Kernel32.Platform.x64;
                 * }
                 * else if (processorArchitecture == Win32.Kernel32.Platform.x86)
                 * {
                 *  processArch = Win32.Kernel32.Platform.x86;
                 * }
                 * else if (processorArchitecture == Win32.Kernel32.Platform.IA64)
                 * {
                 *  processArch = "x86";
                 * }
                 **/
                results.Add(new ProcessResult
                {
                    Pid       = processId,
                    Ppid      = parentProcessId,
                    Name      = processName,
                    Path      = processPath,
                    SessionID = sessionId,
                    //Owner = processOwner,
                    //Architecture = processArch
                });
            }
            return(results);
        }