Exemplo n.º 1
0
 public void when_Run_is_called_and_Path_is_null_then_should_throw_ApplicationException()
 {
     var nc = new NmapContext
         {
             Path = null
         };
     nc.Run();
 }
Exemplo n.º 2
0
 public void when_Run_is_called_and_Path_is_empty_then_should_throw_ApplicationException()
 {
     var nc = new NmapContext
         {
             Path = string.Empty
         };
     nc.Run();
 }
Exemplo n.º 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();
 }
Exemplo n.º 4
0
        /// <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()));
        }
Exemplo n.º 5
0
        public void when_Run_is_called_and_OutputPath_is_null_then_should_throw_ApplicationException()
        {
            var nc = new NmapContext
            {
                OutputPath = null
            };

            nc.Run();
        }
Exemplo n.º 6
0
        public void when_Run_is_called_and_OutputPath_is_empty_then_should_throw_ApplicationException()
        {
            var nc = new NmapContext
            {
                OutputPath = string.Empty
            };

            nc.Run();
        }
Exemplo n.º 7
0
        public void when_Run_is_called_and_Path_is_invalid_then_should_throw_ApplicationException()
        {
            var nc = new NmapContext
            {
                Path = Path.GetRandomFileName()
            };

            nc.Run();
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 10
0
        /// <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)));
        }
Exemplo n.º 11
0
        /// <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()));
        }
Exemplo n.º 12
0
        /// <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()));
        }