Exemple #1
0
        public RESTStatus RunTask(SQLLib sql, PushRunTask Req, NetworkConnectionInfo ni, string MachineID)
        {
            if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false)
            {
                ni.Error   = "Access denied";
                ni.ErrorID = ErrorFlags.AccessDenied;
                return(RESTStatus.Denied);
            }

            string guid = Guid.NewGuid().ToString();

            PushData p = new PushData();

            p.Action          = "runtask";
            p.ReplyID         = guid;
            p.AdditionalData1 = JsonConvert.SerializeObject(Req);

            PushServiceHelper.SendPushService(MachineID, p, 0);
            PushDataResponse resp = PushServiceHelper.PopResponse(MachineID, 0, guid);

            if (resp == null)
            {
                ni.Error   = "No response";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }

            try
            {
                Res = JsonConvert.DeserializeObject <PushRunTaskResult>(resp.Data.ToString());
            }
            catch
            {
                ni.Error   = "Faulty data";
                ni.ErrorID = ErrorFlags.NoData;
                return(RESTStatus.NoContent);
            }
            return(RESTStatus.Success);
        }
Exemple #2
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtFilename.Text.Trim() == "")
            {
                MessageBox.Show(this, "Please specifiy a filename to execute on the remote computer.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            switch (txtFilename.Text.ToLower().Trim())
            {
            case "cmd": txtFilename.Text = SystemRoot + "system32\\cmd.exe"; break;

            case "powershell": txtFilename.Text = SystemRoot + "System32\\WindowsPowerShell\\v1.0\\Powershell.exe"; break;
            }

            if (lstSessions.SelectedItem == null && lstRunAs.SelectedIndex != 2)
            {
                MessageBox.Show(this, "Please specifiy the session where to run the program.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            SessionElement sess = (SessionElement)lstSessions.SelectedItem;

            PushRunTask nt = new PushRunTask();

            nt.Executable = txtFilename.Text;
            nt.Args       = txtArgs.Text;
            nt.SessionID  = sess == null ? 0 : sess.SessionID;
            nt.Username   = txtUsername.Text;
            nt.Password   = txtPassword.Text;
            nt.Option     = (PushRunTaskOption)lstRunAs.SelectedIndex;

            PushRunTaskResult Res = Program.net.PushRunFile(MachineID, nt);

            if (Res == null)
            {
                MessageBox.Show(this, "No response from Server / Agent.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (Res.Result == 0)
            {
                if (lstRunAs.SelectedIndex == 2)
                {
                    string Exec      = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FoxSDC_RedirConsole.exe");
                    string SessionID = Program.net.CloneSession();
                    if (string.IsNullOrWhiteSpace(SessionID) == true)
                    {
                        MessageBox.Show(this, "Program started successfully at the remote location, but didn't got a cloned Session ID.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    try
                    {
                        Process p = new Process();
                        p.StartInfo.FileName        = Exec;
                        p.StartInfo.Arguments       = "-direct \"" + Program.net.ConnectedURL + "\" \"" + MachineID + "\" \"" + SessionID + "\" \"" + Res.SessionID + "\"";
                        p.StartInfo.UseShellExecute = false;
                        p.Start();
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(this, "Cannot start the process " + Exec + " - " + ee.Message, Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        Debug.WriteLine(ee.ToString());
                        return;
                    }
                }
                this.Close();
                return;
            }
            else
            {
                string errorMessage = new Win32Exception((int)(Res.Result)).Message;
                MessageBox.Show(this, "Failed to run task: 0x" + Res.Result.ToString("X") + " - " + errorMessage, Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
        }
Exemple #3
0
        static void RunRemoteApp(string Server, string MID, string Username, string Password, string Program, string Args)
        {
            ConsoleColor c = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;

#if DEBUG
            Console.WriteLine("MachineID:      " + MID);
#endif

            if (Password == "*")
            {
                IntPtr      hwnd = ConsoleUtilities.GetConsoleWindow();
                frmPassword pwd  = new frmPassword(Server, Username);
                if (pwd.ShowDialog(new WindowWrapper(hwnd)) != System.Windows.Forms.DialogResult.OK)
                {
                    Console.ForegroundColor = c;
                    return;
                }
                Password = pwd.Password;
            }

            Console.WriteLine("Connecting to server: " + Server);

            net = new Network();
            if (net.Connect(Server) == false)
            {
                Console.ForegroundColor = c;
                net = null;
                return;
            }

            if (net.Login(Username, Password) == false)
            {
                if (net.LoginError == null)
                {
                    Console.WriteLine("Login failed: ???");
                }
                else
                {
                    Console.WriteLine("Login failed: " + net.LoginError.Error);
                }
                Console.ForegroundColor = c;
                net = null;
                return;
            }

            if (LoopPing == false)
            {
                if (net.PushPing(MID) == false)
                {
                    Console.WriteLine("Remote machine does not respond to \"Ping\"");
                    Console.ForegroundColor = c;
                    net.CloseConnection();
                    net = null;
                    return;
                }
            }
            else
            {
                Console.CancelKeyPress += Console_CancelKeyPress_BreakPing;
                do
                {
                    if (net.PushPing(MID) == false)
                    {
                        Console.WriteLine("Remote machine does not respond to \"Ping\" - Retrying");
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        break;
                    }
                } while (LoopPing == true);
                Console.CancelKeyPress -= Console_CancelKeyPress_BreakPing;
                if (LoopPing == false)
                {
                    Console.ForegroundColor = c;
                    net.CloseConnection();
                    net = null;
                    return;
                }
            }

            PushRunTask rt = new PushRunTask();
            rt.Executable = Program;
            rt.Args       = Args;
            rt.Option     = PushRunTaskOption.SystemUserConsoleRedir;

            PushRunTaskResult rtres = net.PushRunFile(MID, rt);
            if (rtres == null)
            {
                Console.WriteLine("Cannot start application: ???");
                Console.ForegroundColor = c;
                net.CloseConnection();
                net = null;
                return;
            }
            if (rtres.Result != 0)
            {
                string errorMessage = new Win32Exception((int)(rtres.Result)).Message;
                Console.WriteLine("Cannot start application: 0x" + rtres.Result.ToString("X") + " " + errorMessage);
                Console.ForegroundColor = c;
                net.CloseConnection();
                net = null;
                return;
            }

            StdIOSession = rtres.SessionID;
            MachineID    = MID;

#if DEBUG
            Console.WriteLine("SessionID:      " + net.Session);
            Console.WriteLine("STDIOSessionID: " + StdIOSession);
#endif

            Console.WriteLine("Connected.");
            Console.ForegroundColor = c;
            Thread.Sleep(1000);
        }
Exemple #4
0
        private void openCommandPromptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (LstOnly == true)
            {
                return;
            }
            if (lstComputers.SelectedItems.Count == 0)
            {
                return;
            }
            foreach (ListViewItem l in lstComputers.SelectedItems)
            {
                ComputerData cd = (ComputerData)l.Tag;
                if (cd.Approved == true)
                {
                    PushRunTask nt = new PushRunTask();
                    nt.Executable = cd.SystemRoot;
                    if (nt.Executable.EndsWith("\\") == false)
                    {
                        nt.Executable += "\\";
                    }
                    nt.Executable += "System32\\cmd.exe";
                    nt.Args        = "";
                    nt.SessionID   = 0;
                    nt.Username    = "";
                    nt.Password    = "";
                    nt.Option      = PushRunTaskOption.SystemUserConsoleRedir;

                    PushRunTaskResult Res = Program.net.PushRunFile(cd.MachineID, nt);
                    if (Res == null)
                    {
                        MessageBox.Show(this, "No response from Server / Agent.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    if (Res.Result == 0)
                    {
                        string Exec      = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FoxSDC_RedirConsole.exe");
                        string SessionID = Program.net.CloneSession();
                        if (string.IsNullOrWhiteSpace(SessionID) == true)
                        {
                            MessageBox.Show(this, "Program started successfully at the remote location, but didn't got a cloned Session ID.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        try
                        {
                            Process p = new Process();
                            p.StartInfo.FileName        = Exec;
                            p.StartInfo.Arguments       = "-direct \"" + Program.net.ConnectedURL + "\" \"" + cd.MachineID + "\" \"" + SessionID + "\" \"" + Res.SessionID + "\"";
                            p.StartInfo.UseShellExecute = false;
                            p.Start();
                        }
                        catch (Exception ee)
                        {
                            MessageBox.Show(this, "Cannot start the process " + Exec + " - " + ee.Message, Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            Debug.WriteLine(ee.ToString());
                            return;
                        }
                    }
                }
            }
        }