コード例 #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
ファイル: Network.cs プロジェクト: RunOnceEx/CoreSploit
        /// <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
ファイル: Network.cs プロジェクト: RunOnceEx/CoreSploit
        /// <summary>
        /// Conducts a port scan of specified ComputerNames on specified ports and reports open ports.
        /// </summary>
        /// <param name="ComputerNames">ComputerNames to port scan.</param>
        /// <param name="Ports">Ports to scan.</param>
        /// <param name="Ping">Optional switch. If true, pings the ComputerNames to ensure each is up before port scanning.</param>
        /// <param name="Timeout">Timeout (in milliseconds) before a port is considered down.</param>
        /// <param name="Threads">Number of threads with which to portscan simultaneously</param>
        /// <returns>List of PortScanResults</returns>
        public static CoreSploitResultList <PortScanResult> PortScan(IList <string> ComputerNames, IList <int> Ports,
                                                                     bool Ping = true, int Timeout = 250, int Threads = 100)
        {
            IList <string> scanAddresses = Utilities.ConvertCidrToIPs(ComputerNames).Distinct().ToList();
            IList <int>    scanPorts     = Ports.Where(P => P > 1 && P < 65536).Distinct().ToList();

            if (Ping)
            {
                CoreSploitResultList <PingResult> pingResults = Network.Ping(scanAddresses, Timeout, Threads);
                scanAddresses = pingResults.Where(PR => PR.IsUp).Select(PR => PR.ComputerName).ToList();
            }

            IList <PortScanResult> portScanResults = new List <PortScanResult>();

            using (CountdownEvent waiter = new CountdownEvent(scanAddresses.Count * Ports.Count))
            {
                object portScanResultsLock = new object();
                int    runningThreads      = 0;
                foreach (string ComputerName in scanAddresses)
                {
                    foreach (int Port in scanPorts)
                    {
                        TcpClient client = null;
                        if (!Utilities.IsIP(ComputerName))
                        {
                            client = new TcpClient();
                        }
                        else
                        {
                            IPAddress.TryParse(ComputerName, out IPAddress address);
                            client = new TcpClient(address.AddressFamily);
                        }

                        PortScanResult portScanResult = new PortScanResult(ComputerName, Port, true);
                        while (runningThreads >= Threads)
                        {
#warning this may not work properly -scottie
                            waiter.Wait();
                            runningThreads--;
                        }

                        IAsyncResult asyncResult = client.BeginConnect(ComputerName, Port, new AsyncCallback((state) =>
                        {
                            try
                            {
                                client.EndConnect(state);
                                client.Close();
                            }
                            catch
                            {
                                portScanResult.IsOpen = false;
                            }

                            if (portScanResult.IsOpen)
                            {
                                lock (portScanResultsLock)
                                {
                                    portScanResults.Add(portScanResult);
                                }
                            }

                            ((CountdownEvent)state.AsyncState).Signal();
                        }), waiter);
                        runningThreads++;
                    }
                }

                waiter.Wait(Timeout * scanAddresses.Count * Ports.Count);
            }

            CoreSploitResultList <PortScanResult> results = new CoreSploitResultList <PortScanResult>();
            results.AddRange(portScanResults);

            return(results);
        }
コード例 #4
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);
        }