Exemplo n.º 1
0
        static void Main(string[] cargs)
        {
            Console.WriteLine();
            Console.WriteLine("         SharpStat");
            Console.WriteLine("       By @raikiasec");
            Console.WriteLine("----------------------------");
            Dictionary <string, string> args = ArgParser.Parse(cargs);

            if (args["computers"] == "")
            {
                args["computers"] = GetDomainComputers(args);
                if (args["computers"] == "")
                {
                    Console.WriteLine("Error: You must specify target computers to run this against");
                    Environment.Exit(1);
                }
            }
            if (args["file"] == "")
            {
                Console.WriteLine("Error: You must specify a file location to temporarily save the output");
                Environment.Exit(1);
            }
            else if (args["file"].IndexOf("C:\\") == -1)
            {
                Console.WriteLine("Error: File location must begin with C:\\");
                Environment.Exit(1);
            }
            else
            {
                args["file"] = args["file"].Replace("C:\\", "");
            }

            foreach (string target in args["computers"].Split(','))
            {
                Console.WriteLine("Starting on " + target + "...");
                if (PortScan(target))
                {
                    if (RunWmiNetstat(target, args["file"]))
                    {
                        Thread.Sleep(1000);
                        ReadAndDeleteResults(target, args["file"]);
                    }
                }
            }
            Console.WriteLine("--------------------");
            Console.WriteLine("SharpStat is done!");
        }
Exemplo n.º 2
0
        public static Dictionary <string, string> Parse(string[] args)
        {
            Dictionary <string, string> returnVal = new Dictionary <string, string>();

            // set defaults
            returnVal["dc"]        = Environment.GetEnvironmentVariable("USERDNSDOMAIN");
            returnVal["domain"]    = Environment.GetEnvironmentVariable("USERDOMAIN");
            returnVal["computers"] = "";
            returnVal["file"]      = "";
            returnVal["verbose"]   = null;
            string currentKey = "";

            foreach (string str in args)
            {
                if (str.Substring(0, 1) == "-")
                {
                    currentKey = str.Substring(1);
                    bool expectedKey = false;
                    foreach (string exp in returnVal.Keys)
                    {
                        if (string.Equals(currentKey, exp, StringComparison.OrdinalIgnoreCase))
                        {
                            expectedKey = true;
                            break;
                        }
                    }
                    if (!expectedKey)
                    {
                        ArgParser.Usage();
                    }
                    else
                    {
                        returnVal[currentKey] = "";
                    }
                }
                else
                {
                    returnVal[currentKey] = str;
                }
            }
            return(returnVal);
        }