Exemplo n.º 1
0
        public static void ExecuteAssembly(string computer, string path, string argument, List <string> flags, string auth = "ntlm", string scheme = "HTTP")
        {
            Console.WriteLine("[*] Executing Assembly");
            string command = PsFunction.ExecuteAssembly(path, argument, flags);

            try
            {
                (Collection <PSObject> result, Collection <ErrorRecord> errors) = InvokeCommand(computer, command, false, auth, scheme);
                foreach (var obj in result)
                {
                    Console.WriteLine(obj.ToString());
                }
                if (errors.Count > 0)
                {
                    Console.WriteLine("[-] Error While Executing Assembly");
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[-] Failed to Executing Assembly");
                Console.WriteLine(e);
                return;
            }
        }
Exemplo n.º 2
0
        public static void ExecuteAssembly(string computer, string path, string argument, List <string> flags, string auth = "ntlm", string scheme = "HTTP")
        {
            Console.WriteLine("[*] Executing Assembly");
            string caller;
            string randomPath = "C:\\windows\\temp\\" + Guid.NewGuid().ToString() + ".ps1";
            string command    = PsFunction.ExecuteAssembly(path, argument);

            if (flags.Contains("system"))
            {
                caller = PsFunction.RunAsSystem(command);
            }
            else if (flags.Contains("delegwalk"))
            {
                caller = PsFunction.RunDelegationWalk(command);
            }
            else
            {
                caller = command;
            }

            //Console.WriteLine(command);
            //Console.WriteLine(caller);

            try
            {
                (Collection <PSObject> result, Collection <ErrorRecord> errors) = InvokeCommand(computer, caller, false, auth, scheme);
                foreach (var obj in result)
                {
                    Console.WriteLine(obj.ToString());
                }
                if (errors.Count > 0)
                {
                    Console.WriteLine("[-] Error While Executing Assembly");
                    return;
                }
                //delete uploaded ps file
                if (caller != command)
                {
                    try
                    {
                        (Collection <PSObject> result2, Collection <ErrorRecord> errors2) = InvokeCommand(computer, String.Format("if(test-path {0}){{remove-item {0} -force}}", randomPath), false, auth, scheme);
                    }
                    catch
                    {
                        Console.WriteLine(String.Format("  [-] Failed to delete {0}", randomPath));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[-] Failed While Executing Assembly");
                Console.WriteLine(e);
                return;
            }
        }