Ejemplo n.º 1
0
        public virtual void Run(out List <List <IToolResults> > listOfToolResults)
        {
            string       eventDescription = string.Empty;
            DateTime     start            = DateTime.Now;
            IToolOptions _options;

            _options = new NMapToolOptions();
            (_options as NMapToolOptions).Range = this.Range;
            (_options as NMapToolOptions).Path  = this.Configuration ["nmapPath"];

            NMap nmap = new NMap(_options as NMapToolOptions);

            eventDescription = "Starting profile creation with nmap at " + DateTime.Now.ToLongTimeString().ToString() + " for profile: " + this.Name;

            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine(eventDescription);

            this.CurrentResults = (nmap.Run(this) as NMapToolResults);

            eventDescription = "Found " + this.CurrentResults.Hosts.Count + " hosts for profile " + this.Name + ": " + DateTime.Now.ToString();
            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine(eventDescription);

            List <Thread> portThreads = new List <Thread> ();
            List <string> deepResults;

            ProfileHost profileHost;

            eventDescription = "Entering deep scan phase: " + DateTime.Now.ToString();
            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine(eventDescription);
            foreach (NMapHost host in this.CurrentResults.Hosts)
            {
                deepResults = new List <string> ();

                foreach (Port port in host.Ports)
                {
                    string ip     = host.IPAddressv4;
                    string portNo = port.PortNumber.ToString();

                    Thread thread = new Thread(() => deepResults.Add(new NMap(_options as NMapToolOptions).DeepScan(ip, portNo)));

                    thread.Start();

                    portThreads.Add(thread);
                }

                while (portThreads.Where(t => t.IsAlive).Count() > 0)
                {
                    Thread.Sleep(500);
                }

                foreach (Thread thread in portThreads)
                {
                    thread.Join();
                }

                foreach (Port port in host.Ports)
                {
                    string fp = String.Format("\n{0}/{1}", port.PortNumber, (port.IsTCP ? "tcp" : "udp"));
                    port.DeepScan = deepResults
                                    .Where(s => s.Contains(fp))
                                    .FirstOrDefault();
                }
            }



            eventDescription = "Finished deep scan phase: " + DateTime.Now.ToString();
            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine(eventDescription);

            listOfToolResults = new List <List <IToolResults> > ();          //yuck
            foreach (NMapHost host in this.CurrentResults.Hosts)
            {
                List <IToolResults> toolResults;
                ScanHost(host, out toolResults);

                listOfToolResults.Add(toolResults);
            }

            DateTime end = DateTime.Now;

            TimeSpan time = end - start;

            this.Duration = time.TotalSeconds.ToString();
        }
Ejemplo n.º 2
0
        public virtual void Run(out List<List<IToolResults>> listOfToolResults)
        {
            string eventDescription = string.Empty;
            DateTime start = DateTime.Now;
            IToolOptions _options;

            _options = new NMapToolOptions ();
            (_options as NMapToolOptions).Range = this.Range;
            (_options as NMapToolOptions).Path = this.Configuration ["nmapPath"];

            NMap nmap = new NMap (_options as NMapToolOptions);

            eventDescription = "Starting profile creation with nmap at " + DateTime.Now.ToLongTimeString ().ToString() + " for profile: " + this.Name;

            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine (eventDescription);

            this.CurrentResults = (nmap.Run (this) as NMapToolResults);

            eventDescription = "Found " + this.CurrentResults.Hosts.Count + " hosts for profile " + this.Name + ": " + DateTime.Now.ToString();
            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine (eventDescription);

            List<Thread > portThreads = new List<Thread> ();
            List<string > deepResults;

            ProfileHost profileHost;

            eventDescription = "Entering deep scan phase: " + DateTime.Now.ToString();
            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine(eventDescription);
            foreach (NMapHost host in this.CurrentResults.Hosts) {
                deepResults = new List<string> ();

                foreach (Port port in host.Ports) {
                    string ip = host.IPAddressv4;
                    string portNo = port.PortNumber.ToString ();

                    Thread thread = new Thread (() => deepResults.Add (new NMap (_options as NMapToolOptions).DeepScan (ip, portNo)));

                    thread.Start ();

                    portThreads.Add (thread);

                }

                while (portThreads.Where(t => t.IsAlive).Count() > 0)
                    Thread.Sleep (500);

                foreach (Thread thread in portThreads)
                    thread.Join ();

                foreach (Port port in host.Ports) {
                    string fp = String.Format ("\n{0}/{1}", port.PortNumber, (port.IsTCP ? "tcp" : "udp"));
                    port.DeepScan = deepResults
                                .Where (s => s.Contains (fp))
                                .FirstOrDefault ();

                }

            }

            eventDescription = "Finished deep scan phase: " + DateTime.Now.ToString();
            CreateEvent(DateTime.Now, eventDescription, 1);
            Console.WriteLine(eventDescription);

            listOfToolResults = new List<List<IToolResults>> (); //yuck
            foreach (NMapHost host in this.CurrentResults.Hosts) {
                List<IToolResults> toolResults;
                ScanHost (host, out toolResults);

                listOfToolResults.Add (toolResults);
            }

            DateTime end = DateTime.Now;

            TimeSpan time = end - start;

            this.Duration = time.TotalSeconds.ToString ();
        }