Exemple #1
0
        protected override void ProcessRecord(INessusConnection nessusConnection, CancellationToken cancellationToken)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(OutFile))
                {
                    OutFile = PrepareFileName(OutFile, Format);

                    Directory.CreateDirectory(Path.GetDirectoryName(OutFile));

                    using (var outStream = File.OpenWrite(OutFile))
                    {
                        nessusConnection.ExportAsync(Id, HistoryId, Format, outStream, cancellationToken)
                        .Wait(cancellationToken);
                    }
                    WriteVerbose($"Nessus scan saved into ${Path.GetFullPath(OutFile)}");
                }
                else
                {
                    using (var outStream = new MemoryStream())
                    {
                        nessusConnection.ExportAsync(Id, HistoryId, Format, outStream, cancellationToken)
                        .Wait(cancellationToken);
                        WriteObject(Encoding.UTF8.GetString(outStream.ToArray()));
                    }
                }
            }
            catch (AggregateException e)
            {
                WriteError(new ErrorRecord(e.Flatten().InnerException,
                                           string.Empty,
                                           ErrorCategory.ConnectionError,
                                           nessusConnection));
            }
        }
Exemple #2
0
        protected override void ProcessRecord(INessusConnection nessusConnection, CancellationToken cancellationToken)
        {
            var scanResults = nessusConnection.GetScanResultAsync(Id, HistoryId, cancellationToken).Result;

            var vulns = GetVulnerabilities(scanResults);

            WriteObject(vulns, true);
        }
Exemple #3
0
        protected override void InitialLoad(INessusConnection nessusConnection, CancellationToken cancellationToken)
        {
            WriteVerbose("Getting scans from the server...");

            var task = nessusConnection.GetScansAsync(cancellationToken);

            task.Wait(cancellationToken);
            _scans = task.Result.OrderBy(x => x.Name).ToList();

            WriteVerbose($"{_scans.Count()} scan(s) found");
        }
Exemple #4
0
        protected override void BeginProcessing()
        {
            _tokenSource = new CancellationTokenSource();
            if (Profile == null)
            {
                if (string.IsNullOrWhiteSpace(ProfileFile))
                {
                    var defaultProfile = FindProfileInDefaultLocations();

                    if (defaultProfile == null)
                    {
                        throw new FileNotFoundException(
                                  $@"Profile file cannot be found. Please use -{
                                    nameof(ProfileFile)
                                } parameter or create it using New-NessusProfile -OutFile <path to file> in one of default locations:{
                                    Environment.NewLine
                                }{string.Join(Environment.NewLine, DefaultProfileLocations)}");
                    }

                    ProfileFile = defaultProfile.Path;
                    Profile     = defaultProfile.Profile;
                }
                else
                {
                    ProfileFile = Environment.ExpandEnvironmentVariables(ProfileFile);
                    Profile     = NessusProfile.FromProtectedString(File.ReadAllText(ProfileFile));
                }

                WriteVerbose($"Using {Path.GetFullPath(ProfileFile)} profile.");
            }

            _nessusConnection = new NessusConnection(Profile.Server, Profile.Port, Profile.UserName, Profile.Password);
            try
            {
                WriteVerbose($"Connecting to Nessus server at {Profile.Server}:{Profile.Port}");

                _nessusConnection.OpenAsync(_tokenSource.Token).Wait(_tokenSource.Token);

                InitialLoad(_nessusConnection, _tokenSource.Token);
            }
            catch (AggregateException e)
            {
                var err = e.Flatten().InnerException;

                WriteError(new ErrorRecord(err, string.Empty, ErrorCategory.ConnectionError, _nessusConnection));
            }
            catch (Exception e)
            {
                WriteError(new ErrorRecord(e, string.Empty, ErrorCategory.ConnectionError, _nessusConnection));
            }
        }
Exemple #5
0
        protected override void ProcessRecord(INessusConnection nessusConnection, CancellationToken cancellationToken)
        {
            WriteVerbose("Getting scan history records from the server...");

            try
            {
                var task = Id == default(int) ? nessusConnection.GetAllScanHistoriesAsync(cancellationToken) : nessusConnection.GetScanHistoryAsync(Id, cancellationToken);

                task.Wait(cancellationToken);

                var historyRecords = task.Result.OrderByDescending(x => x.LastUpdateDate).ToList();

                WriteVerbose($"{historyRecords.Count} history record(s) found");

                WriteObject(historyRecords, true);
            }
            catch (AggregateException e)
            {
                WriteError(new ErrorRecord(e.Flatten().InnerException, string.Empty, ErrorCategory.ConnectionError, nessusConnection));
            }
        }
Exemple #6
0
 protected override void ProcessRecord(INessusConnection nessusConnection, CancellationToken cancellationToken)
 {
     WriteObject(_scans, true);
 }
Exemple #7
0
 protected abstract void ProcessRecord(INessusConnection nessusConnection, CancellationToken cancellationToken);
Exemple #8
0
 protected virtual void InitialLoad(INessusConnection nessusConnection, CancellationToken cancellationToken)
 {
 }