コード例 #1
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Build an nmap context with the specified options
        /// </summary>
        /// <param name="scanType">The desired type of scan to perform</param>
        /// <param name="ports">The ports to scan (null of empty for default ports)</param>
        /// <returns>An nmap context for performing the desired scan</returns>
        private NmapContext _portScanCommon(ScanType scanType, string ports)
        {
            NmapContext ctx = GetContext();

            // We always try to detect the OS and the service versions
            ctx.Options.AddAll(new[]
            {
                NmapFlag.ServiceVersion,
                NmapFlag.OsDetection
            });

            // Add the appropriate flag if we're not performing a default scan
            if (scanType != ScanType.Default)
            {
                ctx.Options.Add(_scanTypeToNmapFlag[scanType]);
            }

            // Unless we specify UDP only, then perform a UDP scan in the same run
            if (scanType != ScanType.Default && scanType != ScanType.Udp)
            {
                ctx.Options.Add(NmapFlag.UdpScan);
            }

            // If we have a port specification, then use it
            if (!string.IsNullOrEmpty(ports))
            {
                ctx.Options.Add(NmapFlag.PortSpecification, ports);
            }

            return(ctx);
        }
コード例 #2
0
 public void when_Run_is_called_and_Path_is_null_then_should_throw_ApplicationException()
 {
     var nc = new NmapContext
         {
             Path = null
         };
     nc.Run();
 }
コード例 #3
0
 public void when_Run_is_called_and_Path_is_invalid_then_should_throw_ApplicationException()
 {
     var nc = new NmapContext
         {
             Path = Path.GetRandomFileName()
         };
     nc.Run();
 }
コード例 #4
0
 public void when_Run_is_called_and_Path_is_empty_then_should_throw_ApplicationException()
 {
     var nc = new NmapContext
         {
             Path = string.Empty
         };
     nc.Run();
 }
コード例 #5
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Perform a TCP port scan on the specified ports with service detection and OS detection.
        /// </summary>
        /// <param name="scanType">The type of scan to perform</param>
        /// <param name="ports">A list of ports to scan</param>
        /// <returns>A ScanResult object detailing the results of the port scan</returns>
        public ScanResult PortScan(ScanType scanType, IEnumerable <int> ports)
        {
            NmapContext ctx = _portScanCommon(scanType,
                                              string.Join(",",
                                                          ports.Select(x => x.ToString(CultureInfo.InvariantCulture))));

            return(new ScanResult(ctx.Run()));
        }
コード例 #6
0
        public void when_Run_is_called_and_OutputPath_is_null_then_should_throw_ApplicationException()
        {
            var nc = new NmapContext
            {
                OutputPath = null
            };

            nc.Run();
        }
コード例 #7
0
        public void when_Run_is_called_and_OutputPath_is_empty_then_should_throw_ApplicationException()
        {
            var nc = new NmapContext
            {
                OutputPath = string.Empty
            };

            nc.Run();
        }
コード例 #8
0
        public void when_Run_is_called_and_Path_is_invalid_then_should_throw_ApplicationException()
        {
            var nc = new NmapContext
            {
                Path = Path.GetRandomFileName()
            };

            nc.Run();
        }
コード例 #9
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Perform host discovery and OS detection on the intended target (preferably a subnet or IP range)
        /// </summary>
        /// <returns>A collection of Hosts detailing the results of the discovery</returns>
        public IEnumerable <Host> HostDiscovery()
        {
            NmapContext ctx = GetContext();

            ctx.Options.AddAll(new[]
            {
                NmapFlag.TcpSynScan,
                NmapFlag.OsDetection
            });

            return(new ScanResult(ctx.Run()).Hosts);
        }
コード例 #10
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Perform ping discovery on the intended target (preferably a subnet or IP range)
        /// </summary>
        /// <returns>A collection of Hosts detailing the results of the discovery</returns>
        public IEnumerable <Host> PingDiscovery(double maxRate = -1)
        {
            NmapContext ctx = GetContext();

            ctx.Options.AddAll(new[]
            {
                NmapFlag.PingScan,
            });
            if (maxRate > 0)
            {
                ctx.Options[NmapFlag.MaxRate] = maxRate.ToString(CultureInfo.InvariantCulture);
            }

            return(new ScanResult(ctx.Run()).Hosts);
        }
コード例 #11
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Determine whether the intended target is firewalled.
        /// </summary>
        /// <returns>Returns true if the intended targer is firewalled and false otherwise. If used on a subnet or IP range, this determines if any host has a firewall.</returns>
        public bool FirewallProtected()
        {
            NmapContext ctx = GetContext();

            ctx.Options.AddAll(new[]
            {
                NmapFlag.AckScan,
                NmapFlag.FragmentPackets
            });

            var sr = new ScanResult(ctx.Run());

            return
                (sr.Hosts.Any(
                     x =>
                     (x.ExtraPorts.First().Count > 0 && x.ExtraPorts.First().State == "filtered") ||
                     x.Ports.Any(y => y.Filtered)));
        }
コード例 #12
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Create a new NmapContext with the intended target and our persistent options
        /// </summary>
        /// <returns>NmapContext with the intended target and our persistent options</returns>
        private NmapContext GetContext()
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                throw new ApplicationException("No network reachable");
            }

            var ctx = new NmapContext
            {
                Target      = Target.ToString(),
                WindowStyle = NmapWindowStyle
            };

            if (PersistentOptions != null)
            {
                ctx.Options.AddAll(PersistentOptions);
            }

            return(ctx);
        }
コード例 #13
0
ファイル: Scanner.cs プロジェクト: rexwhitten/SaltwaterTaffy
        /// <summary>
        ///     Create a new NmapContext with the intended target and our persistent options
        /// </summary>
        /// <returns>NmapContext with the intended target and our persistent options</returns>
        private NmapContext GetContext()
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                throw new ApplicationException("No network reachable");
            }

            var ctx = new NmapContext
                {
                    Target = Target.ToString()
                };

            if (PersistentOptions != null)
            {
                ctx.Options.AddAll(PersistentOptions);
            }

            return ctx;
        }
コード例 #14
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Perform a TCP port scan on the specified ports with service detection and OS detection.
        /// </summary>
        /// <param name="scanType">The type of scan to perform</param>
        /// <param name="ports">A string detailing which ports to scan (e.g., "10-20,33")</param>
        /// <returns>A ScanResult object detailing the results of the port scan</returns>
        public ScanResult PortScan(ScanType scanType, string ports)
        {
            NmapContext ctx = _portScanCommon(scanType, ports);

            return(new ScanResult(ctx.Run()));
        }
コード例 #15
0
ファイル: Scanner.cs プロジェクト: OidaTiftla/SaltwaterTaffy
        /// <summary>
        ///     Perform the desired scan with service detection and OS detection.
        /// </summary>
        /// <returns>A ScanResult object detailing the results of the port scan</returns>
        public ScanResult PortScan(ScanType scanType)
        {
            NmapContext ctx = _portScanCommon(scanType, null);

            return(new ScanResult(ctx.Run()));
        }