Exemplo n.º 1
0
  def testExecutionTimeLimit(self):
    """Test if the time limit works."""

    (_, _, _, time_used) = client_utils_common.Execute("/bin/sleep", ["10"], 1)

    # This should take just a bit longer than one second.
    self.assertTrue(time_used < 2.0)
Exemplo n.º 2
0
    def Run(self, args):
        """Run."""
        pub_key = config_lib.CONFIG["Client.executable_signing_public_key"]
        if not args.executable.Verify(pub_key):
            raise OSError("Executable signing failure.")

        path = self.WriteBlobToFile(args.executable, args.write_path, ".pkg")

        cmd = "/usr/sbin/installer"
        cmd_args = ["-pkg", path, "-target", "/"]
        time_limit = args.time_limit

        res = client_utils_common.Execute(cmd,
                                          cmd_args,
                                          time_limit=time_limit,
                                          bypass_whitelist=True)
        (stdout, stderr, status, time_used) = res

        self.CleanUp(path)

        # Limit output to 10MB so our response doesn't get too big.
        stdout = stdout[:10 * 1024 * 1024]
        stderr = stderr[:10 * 1024 * 1024]

        result = rdfvalue.ExecuteBinaryResponse(
            stdout=stdout,
            stderr=stderr,
            exit_status=status,
            # We have to return microseconds.
            time_used=int(1e6 * time_used))
        self.SendReply(result)
Exemplo n.º 3
0
    def testExecutionTimeLimit(self):
        """Test if the time limit works."""

        _, _, _, time_used = client_utils_common.Execute(
            "/bin/sleep", ["10"], 0.1)

        # This should take just a bit longer than 0.1 seconds.
        self.assertLess(time_used, 0.5)
Exemplo n.º 4
0
  def _InstallDeb(self, path, args):
    cmd = "/usr/bin/dpkg"
    cmd_args = ["-i", path]
    time_limit = args.time_limit

    client_utils_common.Execute(cmd, cmd_args, time_limit=time_limit,
                                bypass_whitelist=True, daemon=True)

    # The installer will run in the background and kill the main process
    # so we just wait. If something goes wrong, the nanny will restart the
    # service after a short while and the client will come back to life.
    time.sleep(1000)
Exemplo n.º 5
0
    def testExecutionWhiteList(self):
        """Test if unknown commands are filtered correctly."""

        # ls is not allowed
        (stdout, stderr, status, _) = client_utils_common.Execute("ls", ["."])
        self.assertEqual(status, -1)
        self.assertEqual(stdout, "")
        self.assertEqual(stderr, "Execution disallowed by whitelist.")

        # "echo 1" is
        (stdout, stderr, status,
         _) = client_utils_common.Execute("/bin/echo", ["1"])
        self.assertEqual(status, 0)
        self.assertEqual(stdout, "1\n")
        self.assertEqual(stderr, "")

        # but not "echo 11"
        (stdout, stderr, status,
         _) = client_utils_common.Execute("/bin/echo", ["11"])
        self.assertEqual(status, -1)
        self.assertEqual(stdout, "")
        self.assertEqual(stderr, "Execution disallowed by whitelist.")
Exemplo n.º 6
0
  def ProcessFile(self, path, args):
    res = client_utils_common.Execute(
        path, args.args, args.time_limit, bypass_whitelist=True)
    (stdout, stderr, status, time_used) = res

    # Limit output to 10MB so our response doesn't get too big.
    stdout = stdout[:10 * 1024 * 1024]
    stderr = stderr[:10 * 1024 * 1024]

    self.SendReply(
        rdf_client.ExecuteBinaryResponse(
            stdout=stdout,
            stderr=stderr,
            exit_status=status,
            # We have to return microseconds.
            time_used=int(1e6 * time_used)))
Exemplo n.º 7
0
Arquivo: osx.py Projeto: wwwiretap/grr
  def ProcessFile(self, path, args):

    cmd = "/usr/sbin/installer"
    cmd_args = ["-pkg", path, "-target", "/"]
    time_limit = args.time_limit

    res = client_utils_common.Execute(cmd, cmd_args, time_limit=time_limit,
                                      bypass_whitelist=True)
    (stdout, stderr, status, time_used) = res

    # Limit output to 10MB so our response doesn't get too big.
    stdout = stdout[:10 * 1024 * 1024]
    stderr = stderr[:10 * 1024 * 1024]

    result = rdfvalue.ExecuteBinaryResponse(stdout=stdout,
                                            stderr=stderr,
                                            exit_status=status,
                                            # We have to return microseconds.
                                            time_used=int(1e6 * time_used))
    self.SendReply(result)
Exemplo n.º 8
0
    def Run(self, command):
        """Run."""
        cmd = command.cmd
        args = command.args
        time_limit = command.time_limit

        res = client_utils_common.Execute(cmd, args, time_limit)
        (stdout, stderr, status, time_used) = res

        # Limit output to 10MB so our response doesn't get too big.
        stdout = stdout[:10 * 1024 * 1024]
        stderr = stderr[:10 * 1024 * 1024]

        self.SendReply(
            rdf_client.ExecuteResponse(
                request=command,
                stdout=stdout,
                stderr=stderr,
                exit_status=status,
                # We have to return microseconds.
                time_used=int(1e6 * time_used)))
Exemplo n.º 9
0
    def Run(self, args):
        """Run."""
        pub_key = config_lib.CONFIG["Client.executable_signing_public_key"]
        if not args.executable.Verify(pub_key):
            raise OSError("Executable signing failure.")

        path = self.WriteBlobToFile(args.executable, args.write_path, ".deb")

        cmd = "/usr/bin/dpkg"
        cmd_args = ["-i", path]
        time_limit = args.time_limit

        client_utils_common.Execute(cmd,
                                    cmd_args,
                                    time_limit=time_limit,
                                    bypass_whitelist=True,
                                    daemon=True)

        # The installer will run in the background and kill the main process
        # so we just wait. If something goes wrong, the nanny will restart the
        # service after a short while and the client will come back to life.
        time.sleep(1000)
Exemplo n.º 10
0
    def Run(self, args):
        """Run."""
        # Verify the executable blob.
        args.executable.Verify(
            config_lib.CONFIG["Client.executable_signing_public_key"])

        if sys.platform == "win32":
            # We need .exe here.
            suffix = ".exe"
        else:
            suffix = ""

        lifetime = args.time_limit
        # Keep the file for at least 5 seconds after execution.
        if lifetime > 0:
            lifetime += 5

        path = self.WriteBlobToFile(args.executable, lifetime, suffix)

        res = client_utils_common.Execute(path,
                                          args.args,
                                          args.time_limit,
                                          bypass_whitelist=True)
        (stdout, stderr, status, time_used) = res

        self.CleanUp(path)

        # Limit output to 10MB so our response doesn't get too big.
        stdout = stdout[:10 * 1024 * 1024]
        stderr = stderr[:10 * 1024 * 1024]

        result = rdfvalue.ExecuteBinaryResponse(
            stdout=stdout,
            stderr=stderr,
            exit_status=status,
            # We have to return microseconds.
            time_used=int(1e6 * time_used))

        self.SendReply(result)