コード例 #1
0
        public void PSOutputParser_NoUserName()
        {
            // Made up ps output from a system where $USER wasn't a thing
            const string input =
                "CurrentUserName: \n" +
                "    A B        C\n" +
                "    1 root     /sbin/init\n" +
                "  720          dbus-daemon --system --fork\n" +
                " 2389 greggm   -bash\n";

            List <PSOutputParser.Process> r = PSOutputParser.Parse(input);

            Assert.AreEqual(3, r.Count);

            uint[]   pids        = { 1, 720, 2389 };
            string[] userNames   = { "root", "", "greggm" };
            string[] commandLine = { "/sbin/init", "dbus-daemon --system --fork", "-bash" };
            for (int c = 0; c < r.Count; c++)
            {
                Assert.AreEqual(pids[c], r[c].Id);
                Assert.AreEqual(userNames[c], r[c].UserName);
                Assert.AreEqual(commandLine[c], r[c].CommandLine);
                bool isSameUser = pids[c] != 1;
                Assert.AreEqual(isSameUser, r[c].IsSameUser);
            }
        }
コード例 #2
0
        public void PSOutputParser_Ubuntu14()
        {
            // example output from ps on a real Ubuntu 14 machine (with many processes removed):
            const string input =
                "CurrentUserName: greggm\n" +
                "    A B        C\n" +
                "    1 root     /sbin/init\n" +
                "    2 root     [kthreadd]\n" +
                "  720 message+ dbus-daemon --system --fork\n" +
                " 2389 greggm   -bash\n" +
                " 2580 root     /sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-d08a482b-ff90-4007-9b13-6500eb94b673-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0\n" +
                " 2913 greggm   ps -axww -o pid=A,ruser=B,args=C\n";

            List <PSOutputParser.Process> r = PSOutputParser.Parse(input);

            Assert.AreEqual(5, r.Count);

            uint[]   pids        = { 1, 2, 720, 2389, 2580 };
            string[] userNames   = { "root", "root", "message+", "greggm", "root" };
            string[] commandLine = { "/sbin/init", "[kthreadd]", "dbus-daemon --system --fork", "-bash", "/sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-d08a482b-ff90-4007-9b13-6500eb94b673-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0" };
            for (int c = 0; c < r.Count; c++)
            {
                Assert.AreEqual(pids[c], r[c].Id);
                Assert.AreEqual(userNames[c], r[c].UserName);
                Assert.AreEqual(commandLine[c], r[c].CommandLine);
                bool isSameUser = pids[c] == 2389;
                Assert.AreEqual(isSameUser, r[c].IsSameUser);
            }
        }
コード例 #3
0
        public void PSOutputParser_NoUserName()
        {
            // Made up ps output from a system where $USER wasn't a thing
            const string username     = "";
            const string architecture = "";
            const string input        =
                "pppppppppp ffffffff rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr COMMAND\n" +
                "         1        0 root                             /sbin/init\n" +
                "       720        0                                  dbus-daemon --system --fork\n" +
                "      2389        0 greggm                           -bash\n";

            List <Process> r = PSOutputParser.Parse(input, new SystemInformation(username, architecture));

            Assert.Equal(3, r.Count);

            uint[]   pids        = { 1, 720, 2389 };
            string[] userNames   = { "root", "", "greggm" };
            string[] commandLine = { "/sbin/init", "dbus-daemon --system --fork", "-bash" };
            for (int c = 0; c < r.Count; c++)
            {
                Assert.Equal(pids[c], r[c].Id);
                Assert.Equal(userNames[c], r[c].UserName);
                Assert.Equal(commandLine[c], r[c].CommandLine);
                bool isSameUser = pids[c] != 1;
                Assert.Equal(isSameUser, r[c].IsSameUser);
            }
        }
コード例 #4
0
        public void PSOutputParser_Ubuntu14()
        {
            const string username     = "******";
            const string architecture = "x86_64";
            // example output from ps on a real Ubuntu 14 machine (with many processes removed):
            const string input =
                "pppppppppp ffffffff rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr COMMAND\n" +
                "         1        0 root                             /sbin/init\n" +
                "         2        0 root                             [kthreadd]\n" +
                "       720        0 message+                         dbus-daemon --system --fork\n" +
                "      2389        0 greggm                           -bash\n" +
                "      2580        0 root                             /sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-d08a482b-ff90-4007-9b13-6500eb94b673-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0\n" +
                "      2913        0 greggm                           ps axww -o pid=pppppppppp -o flags=ffffffff -o ruser=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr -o args\n";

            List <Process> r = PSOutputParser.Parse(input, new SystemInformation(username, architecture));

            Assert.Equal(5, r.Count);

            uint[]   pids        = { 1, 2, 720, 2389, 2580 };
            string[] userNames   = { "root", "root", "message+", "greggm", "root" };
            string[] commandLine = { "/sbin/init", "[kthreadd]", "dbus-daemon --system --fork", "-bash", "/sbin/dhclient -d -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-d08a482b-ff90-4007-9b13-6500eb94b673-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0" };
            for (int c = 0; c < r.Count; c++)
            {
                Assert.Equal(pids[c], r[c].Id);
                Assert.Equal(userNames[c], r[c].UserName);
                Assert.Equal(commandLine[c], r[c].CommandLine);
                bool isSameUser = pids[c] == 2389;
                Assert.Equal(isSameUser, r[c].IsSameUser);
            }
        }
コード例 #5
0
ファイル: SSHConnection.cs プロジェクト: optikos/MIEngine
        public override List <Process> ListProcesses()
        {
            string username        = string.Empty;
            var    usernameCommand = _remoteSystem.Shell.ExecuteCommand("id -u -n", Timeout.InfiniteTimeSpan);

            if (usernameCommand.ExitCode == 0)
            {
                username = usernameCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'id' command ends with a newline
            }

            string architecture        = string.Empty;
            var    architectureCommand = _remoteSystem.Shell.ExecuteCommand("uname -m", Timeout.InfiniteTimeSpan);

            if (architectureCommand.ExitCode == 0)
            {
                architecture = architectureCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'uname -m' command ends with a newline
            }

            SystemInformation systemInformation = new SystemInformation(username, architecture);

            var command = _remoteSystem.Shell.ExecuteCommand(PSOutputParser.PSCommandLine, Timeout.InfiniteTimeSpan);

            if (command.ExitCode != 0)
            {
                throw new CommandFailedException(StringResources.Error_PSFailed);
            }

            return(PSOutputParser.Parse(command.Output, systemInformation));
        }
コード例 #6
0
        public void PSOutputParser_SmallCol()
        {
            // made up output for what could happen if the fields were all just 1 character in size
            const string input =
                "CurrentUserName: greggm\n" +
                "A B C\n" +
                "9 r /sbin/init";

            List <PSOutputParser.Process> r = PSOutputParser.Parse(input);

            Assert.AreEqual(1, r.Count);
            Assert.AreEqual <uint>(9, r[0].Id);
            Assert.AreEqual("r", r[0].UserName);
            Assert.AreEqual("/sbin/init", r[0].CommandLine);
        }
コード例 #7
0
        public void PSOutputParser_SmallCol()
        {
            const string username     = "******";
            const string architecture = "x86_64";
            // made up output for what could happen if the fields were all just 1 character in size
            const string input =
                "A B C D\n" +
                "9 0 r /sbin/init";

            List <Process> r = PSOutputParser.Parse(input, new SystemInformation(username, architecture));

            Assert.Single(r);
            Assert.Equal <uint>(9, r[0].Id);
            Assert.Equal("r", r[0].UserName);
            Assert.Equal("/sbin/init", r[0].CommandLine);
        }
コード例 #8
0
ファイル: SSHConnection.cs プロジェクト: Trass3r/MIEngine
        public override List<Process> ListProcesses()
        {
            string username = string.Empty;
            var usernameCommand = _remoteSystem.Shell.ExecuteCommand("id -u -n");
            if (usernameCommand.ExitCode == 0)
            {
                username = usernameCommand.Output.TrimEnd('\n', '\r'); // trim line endings because 'id' command ends with a newline
            }

            var command = _remoteSystem.Shell.ExecuteCommand(PSOutputParser.PSCommandLine);
            if (command.ExitCode != 0)
            {
                throw new CommandFailedException(StringResources.Error_PSFailed);
            }

            return PSOutputParser.Parse(command.Output, username);
        }