protected internal static string GetSignatureStatus(string Path)
        {
            if (!WindowsFileSystemUtils.NeedsSignature(Path))
            {
                return("");
            }
            string sigStatus = WinTrust.VerifyEmbeddedSignature(Path);

            return(sigStatus);
        }
Ejemplo n.º 2
0
 protected internal static string GetFilePermissions(FileSystemInfo fileInfo)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(WindowsFileSystemUtils.GetFilePermissions(fileInfo));
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         return(LinuxFileSystemUtils.GetFilePermissions(fileInfo));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        public override void Execute()
        {
            if (!CanRunOnPlatform())
            {
                return;
            }

            wb = new WriteBuffer(runId);
            Start();

            if (this.roots == null || this.roots.Count() == 0)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    foreach (var driveInfo in DriveInfo.GetDrives())
                    {
                        if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed)
                        {
                            this.roots.Add(driveInfo.Name);
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    this.roots.Add("/");   // @TODO Improve this
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    this.roots.Add("/"); // @TODO Improve this
                }
            }

            foreach (var root in this.roots)
            {
                Log.Information("{0} root {1}", Strings.Get("Scanning"), root.ToString());
                try
                {
                    var fileInfoEnumerable = DirectoryWalker.WalkDirectory(root);
                    Parallel.ForEach(fileInfoEnumerable,
                                     (fileInfo =>
                    {
                        try
                        {
                            FileSystemObject obj = null;
                            if (fileInfo is DirectoryInfo)
                            {
                                if (!Filter.IsFiltered(Helpers.RuntimeString(), "Scan", "File", "Path", fileInfo.FullName))
                                {
                                    obj = new FileSystemObject()
                                    {
                                        Path = fileInfo.FullName,
                                        Permissions = FileSystemUtils.GetFilePermissions(fileInfo)
                                    };
                                }
                            }
                            else
                            {
                                if (!Filter.IsFiltered(Helpers.RuntimeString(), "Scan", "File", "Path", fileInfo.FullName))
                                {
                                    obj = new FileSystemObject()
                                    {
                                        Path = fileInfo.FullName,
                                        Permissions = FileSystemUtils.GetFilePermissions(fileInfo),
                                        Size = (ulong)(fileInfo as FileInfo).Length,
                                    };
                                    if (WindowsFileSystemUtils.NeedsSignature(obj.Path))
                                    {
                                        if (WindowsFileSystemUtils.IsLocal(obj.Path) || downloadCloud)
                                        {
                                            obj.SignatureStatus = WindowsFileSystemUtils.GetSignatureStatus(fileInfo.FullName);
                                            obj.Characteristics = WindowsFileSystemUtils.GetDllCharacteristics(fileInfo.FullName);
                                        }
                                        else
                                        {
                                            obj.SignatureStatus = "Cloud";
                                        }
                                    }
                                    if (INCLUDE_CONTENT_HASH)
                                    {
                                        obj.ContentHash = FileSystemUtils.GetFileHash(fileInfo);
                                    }
                                }
                            }
                            if (obj != null)
                            {
                                Write(obj);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Warning(ex, "Error processing {0}", fileInfo?.FullName);
                        }
                    }));
                }
                catch (Exception ex)
                {
                    Log.Warning(ex, "Error collecting file system information: {0}", ex.Message);
                }
            }

            Stop();

            DatabaseManager.Commit();
        }