コード例 #1
0
        // Selected port scan method
        public static bool SelectedPortScan(string strippedIp, string scanType, string Username, string Password, string domainURL, string nekoFolder)
        {
            if (scanType == "1")
            {
                string results = "";
                // Get port numbers from user
                Console.WriteLine("\r\nPlease enter port numbers separated by commas: ");
                string ports = Console.ReadLine();
                if (ports != "")
                {
                    // Remove any spaces
                    if (ports.Contains(" "))
                    {
                        ports.Replace(" ", "");
                    }
                    Console.WriteLine("\r\nStarting selected scan on port(s): " + Convert.ToString(ports) + Environment.NewLine, Console.ForegroundColor = ConsoleColor.Red);
                    Console.ResetColor();
                    // Add ports to list
                    List <int> portList = new List <int>();
                    // Split out data by comma values
                    string[] fullList = ports.Split(',');
                    // Iteratively add to list
                    foreach (var portNumber in fullList)
                    {
                        portList.Add(Convert.ToInt32(portNumber));
                    }
                    // Run scan
                    foreach (var portNumber in fullList)
                    {
                        // Go through all 255 IPs of last octet
                        for (int i = 1; i < 256; i++)
                        {
                            try
                            {
                                var client = new TcpClient();
                                {
                                    if (!client.ConnectAsync(strippedIp + Convert.ToString(i), Convert.ToInt32(portNumber)).Wait(1000))
                                    {
                                        // connection failure
                                        Console.WriteLine("Connection to " + strippedIp + Convert.ToString(i) + " on port: " + Convert.ToInt32(portNumber) + " failed.");
                                    }
                                    else
                                    {
                                        Console.WriteLine("Connection to " + strippedIp + Convert.ToString(i) + " on port: " + Convert.ToInt32(portNumber) + " succeeded.");
                                        results = "Connection to " + strippedIp + Convert.ToString(i) + " on port: " + Convert.ToInt32(portNumber) + " succeeded.";
                                        // Append results to text file
                                        File.AppendAllText(nekoFolder + "\\Network IP Scan " + strippedIp + Convert.ToString(i) + ".txt", results + Environment.NewLine + Environment.NewLine);
                                        string wmiHost = "\\Network IP Scan " + strippedIp + Convert.ToString(i) + ".txt";
                                        if (results.Contains("succeeded") && Convert.ToInt32(portNumber) == 135)
                                        {
                                            Console.WriteLine("Port 135 confirmed", Console.ForegroundColor = ConsoleColor.DarkRed);
                                            Console.ResetColor();
                                            // Launch WMI recon
                                            GatherInfoUsingWMI.Parameters(strippedIp + Convert.ToString(i), Username, Password, domainURL, nekoFolder, wmiHost);
                                            // Add host to WMI list
                                            UserChoices.UserScanSelection.WMITargets.Add(strippedIp + Convert.ToString(i));
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
            else if (scanType == "2")
            {
                string results = "";
                // Get port number from user
                Console.WriteLine("\r\nPlease enter port numbers separated by commas: ");
                string ports = Console.ReadLine();
                if (ports != "")
                {
                    // Remove spaces
                    if (ports.Contains(" "))
                    {
                        ports.Replace(" ", "");
                    }
                    Console.WriteLine("\r\nStarting selected scan on port(s): " + Convert.ToString(ports));
                    // Add ports to list array
                    string[] fullList = ports.Split(',');

                    // Run scan
                    foreach (var portNumber in fullList)
                    {
                        // Go through each IP
                        for (int i = 1; i < 256; i++)
                        {
                            try
                            {
                                var client = new TcpClient();
                                {
                                    if (!client.ConnectAsync(strippedIp + Convert.ToString(i), Convert.ToInt32(portNumber)).Wait(1000))
                                    {
                                        // connection failure
                                        Console.WriteLine("Connection to " + strippedIp + Convert.ToString(i) + " on port: " + Convert.ToInt32(portNumber) + " failed.");
                                    }
                                    else
                                    {
                                        Console.WriteLine("Connection to " + strippedIp + Convert.ToString(i) + " on port: " + Convert.ToInt32(portNumber) + " succeeded.");
                                        results = "Connection to " + strippedIp + Convert.ToString(i) + " on port: " + Convert.ToInt32(portNumber) + " succeeded.";
                                        // Append results to text document
                                        File.AppendAllText(nekoFolder + "\\Network IP Scan " + strippedIp + Convert.ToString(i) + ".txt", results + Environment.NewLine + Environment.NewLine);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: Scan.cs プロジェクト: endisphotic/C-Sharp-Tools
 // Ports
 public static void Ports(string strippedIP, int startIp, int stopIp, int portStart, int portStop, string type, string Username, string Password, string domainURL, string nekoFolder)
 {
     // WMI Scan
     if (type == "1")
     {
         // Go through all IPs
         for (int i = startIp; i < stopIp; i++)
         {
             // And loop through each port
             for (int j = portStart; j < portStop; j++)
             {
                 string results = "";
                 try
                 {
                     var client = new TcpClient();
                     {
                         if (!client.ConnectAsync(strippedIP + Convert.ToString(i), +j).Wait(1000))
                         {
                             // connection failure
                             Console.WriteLine("Connection to " + strippedIP + Convert.ToString(i) + " on port: " + Convert.ToString(j) + " failed.");
                         }
                         else
                         {
                             Console.WriteLine("Connection to " + strippedIP + Convert.ToString(i) + " on port: " + Convert.ToString(j) + " succeeded.");
                             results = "Connection to " + strippedIP + Convert.ToString(i) + " on port: " + Convert.ToString(j) + " succeeded.";
                             // Write out results
                             File.AppendAllText(nekoFolder + "\\Network IP Scan " + strippedIP + Convert.ToString(i) + ".txt", results + Environment.NewLine + Environment.NewLine);
                             string wmiHost = "\\Network IP Scan " + strippedIP + Convert.ToString(i) + ".txt";
                             if (results.Contains("succeeded") && (j) == 135)
                             {
                                 Console.WriteLine("Port 135 confirmed", Console.ForegroundColor = ConsoleColor.DarkRed);
                                 Console.ResetColor();
                                 // Launch WMI recon info
                                 GatherInfoUsingWMI.Parameters(strippedIP + Convert.ToString(i), Username, Password, domainURL, nekoFolder, wmiHost);
                                 // Add to WMI list
                                 UserScanSelection.WMITargets.Add(strippedIP + Convert.ToString(i));
                             }
                         }
                     }
                 }
                 catch (Exception)
                 {
                     // Console.WriteLine(e);
                 }
             }
         }
     }
     // Network only
     else if (type == "2")
     {
         // Loop through IPs
         for (int i = startIp; i < stopIp; i++)
         {
             // Loop through ports
             for (int j = portStart; j < portStop; j++)
             {
                 string results = "";
                 try
                 {
                     var client = new TcpClient();
                     {
                         if (!client.ConnectAsync(strippedIP + Convert.ToString(i), +j).Wait(1000))
                         {
                             // connection failure
                             Console.WriteLine("Connection to " + strippedIP + Convert.ToString(i) + " on port: " + Convert.ToString(j) + " failed.");
                         }
                         else
                         {
                             Console.WriteLine("Connection to " + strippedIP + Convert.ToString(i) + " on port: " + Convert.ToString(j) + " succeeded.");
                             results = "Connection to " + strippedIP + Convert.ToString(i) + " on port: " + Convert.ToString(j) + " succeeded.";
                             // Write out results
                             File.AppendAllText(nekoFolder + "\\Network IP Scan " + strippedIP + Convert.ToString(i) + ".txt", results + Environment.NewLine + Environment.NewLine);
                         }
                     }
                 }
                 catch (Exception)
                 {
                     // Console.WriteLine(e);
                 }
             }
         }
     }
 }