Example #1
0
from grr.server.grr_response_server import flow_utils
from grr.server.grr_response_server import server_startup
from grr.server.grr_response_server.aff4_objects import standard

# Check if fuse is installed. If it's not, set it to None so we know to mock it
# out later.
try:
    # pylint: disable=g-import-not-at-top
    import fuse
    # pylint: enable=g-import-not-at-top
except (EnvironmentError, ImportError):
    # We check for ImportErrors and EnvironmentErrors since submit checks throw an
    # EnvironmentError when fuse isn't installed.
    fuse = None

flags.DEFINE_string("aff4path", "/",
                    "Path in AFF4 to use as the root of the filesystem.")

flags.DEFINE_string("mountpoint", None,
                    "Path to point at which the system should be mounted.")

flags.DEFINE_bool(
    "background", False,
    "Whether or not to run the filesystem in the background,"
    " not viewing debug information.")

flags.DEFINE_float("timeout", 30,
                   "How long to poll a flow for before giving up.")

flags.DEFINE_integer(
    "max_age_before_refresh", 60 * 5,
    "Measured in seconds. Do a client-side update if it's"
Example #2
0
from grr.config import contexts
from grr.core.grr_response_core.lib import config_lib
from grr.core.grr_response_core.lib import flags
from grr.core.grr_response_core.lib import registry
from grr.core.grr_response_core.lib import stats
from grr.server.grr_response_server import aff4
from grr.server.grr_response_server import data_store
from grr.server.grr_response_server import server_logging
from grr.server.grr_response_server.blob_stores import memory_stream_bs
from grr.server.grr_response_server.data_stores import fake_data_store

# Make sure we do not reinitialize multiple times.
INIT_RAN = False

flags.DEFINE_string(
    "test_data_store", None,
    "The data store implementation to use for running "
    "the tests.")


def TestInit():
    """Only used in tests and will rerun all the hooks to create a clean state."""
    global INIT_RAN

    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    # Tests use both the server template grr_server.yaml as a primary config file
    # (this file does not contain all required options, e.g. private keys), and
    # additional configuration in test_data/grr_test.yaml which contains typical
    # values for a complete installation.
    flags.FLAGS.config = config_lib.Resource().Filter(
Example #3
0
from grr_response_server import maintenance_utils
from grr_response_server import server_startup
from grr_response_server import worker_lib
from grr_response_server.aff4_objects import aff4_grr
from grr_response_server.aff4_objects import security

# All the functions in this lib we want in local namespace.
# pylint: disable=wildcard-import
from grr_response_server.console_utils import *
# pylint: enable=wildcard-import

from grr_response_server.flows.general import memory
# pylint: enable=unused-import

flags.DEFINE_string(
    "client", None, "Initialise the console with this client id "
    "(e.g. C.1234345).")

flags.DEFINE_string("reason", None,
                    "Create a default token with this access reason ")

flags.DEFINE_string(
    "code_to_execute", None,
    "If present, no console is started but the code given in "
    "the flag is run instead (comparable to the -c option of "
    "IPython).")

flags.DEFINE_string(
    "command_file", None,
    "If present, no console is started but the code given in "
    "command file is supplied as input instead.")
Example #4
0
from grr.core.grr_response_core.lib import flags
from grr.core.grr_response_core.lib import registry
from grr.core.grr_response_core.lib import utils
from grr.server.grr_response_server.gui import api_auth_manager
# This import guarantees that all API-related RDF types will get imported
# (as they're all references by api_call_router).
# pylint: disable=unused-import
from grr.server.grr_response_server.gui import api_call_router
# pylint: enable=unused-import
from grr.server.grr_response_server.gui import api_regression_http
from grr.server.grr_response_server.gui import webauth
from grr.test_lib import test_lib

flags.DEFINE_string(
    "generate", "",
    "Generate golden regression data for tests using a given connection type.")


class ApiRegressionTestMetaclass(registry.MetaclassRegistry):
    """Automatica test classes generation through a metaclass."""

    connection_mixins = {}

    @classmethod
    def RegisterConnectionMixin(cls, mixin):
        cls.connection_mixins[mixin.connection_type] = mixin

    def __init__(cls, name, bases, env_dict):  # pylint: disable=no-self-argument
        registry.MetaclassRegistry.__init__(cls, name, bases, env_dict)
Example #5
0
from grr.server.grr_response_server.gui import api_auth_manager
from grr.server.grr_response_server.gui import api_call_router_with_approval_checks
from grr.server.grr_response_server.gui import webauth
from grr.server.grr_response_server.gui import wsgiapp_testlib
from grr.server.grr_response_server.hunts import implementation
from grr.server.grr_response_server.hunts import standard
from grr.server.grr_response_server.rdfvalues import flow_runner as rdf_flow_runner
from grr.server.grr_response_server.rdfvalues import objects as rdf_objects
from grr.test_lib import acl_test_lib
from grr.test_lib import action_mocks
from grr.test_lib import artifact_test_lib as ar_test_lib
from grr.test_lib import hunt_test_lib
from grr.test_lib import test_lib

flags.DEFINE_string(
    "chrome_driver_path", None,
    "Path to the chrome driver binary. If not set, webdriver "
    "will search on PATH for the binary.")

flags.DEFINE_bool(
    "use_headless_chrome", False, "If set, run Chrome driver in "
    "headless mode. Useful when running tests in a window-manager-less "
    "environment.")

# A increasing sequence of times.
TIME_0 = test_lib.FIXED_TIME
TIME_1 = TIME_0 + rdfvalue.Duration("1d")
TIME_2 = TIME_1 + rdfvalue.Duration("1d")


def DateString(t):
    return t.Format("%Y-%m-%d")
Example #6
0
# Make sure we load the client plugins
from grr_response_client import client_plugins
# pylint: enable=unused-import

from grr_response_client import client_startup
from grr_response_client import comms
from grr_response_client import vfs
from grr.config import contexts
from grr.core.grr_response_core.lib import flags
from grr.core.grr_response_core.lib.rdfvalues import crypto as rdf_crypto
from grr.core.grr_response_core.lib.rdfvalues import paths as rdf_paths

flags.DEFINE_integer("nrclients", 1, "Number of clients to start")

flags.DEFINE_string("cert_file", "",
                    "Path to a file that stores all certificates for"
                    "the client pool.")

flags.DEFINE_bool("enroll_only", False,
                  "If specified, the script will enroll all clients and exit.")

flags.DEFINE_bool("fast_poll", False,
                  "If specified, every client in the pool will work in the "
                  "fast poll mode. This is useful for benchmarks, as in fast "
                  "poll mode the timeouts are predictable and benchmarks "
                  "results are more stable.")


class PoolGRRClient(threading.Thread):
  """A GRR client for running in pool mode."""
Example #7
0
import csv
import os

# pylint: disable=unused-import,g-bad-import-order
from grr_response_server import server_plugins
# pylint: enable=unused-import,g-bad-import-order

from grr.core.grr_response_core.lib import flags
from grr.core.grr_response_core.lib import utils
from grr_response_server import aff4
from grr_response_server import data_store
from grr_response_server import server_startup

from grr_response_server.aff4_objects import filestore

flags.DEFINE_string("filename", "", "File with hashes.")
flags.DEFINE_integer("start", None, "Start row in the file.")


def _ImportRow(store, row, product_code_list, op_system_code_list):
    sha1 = row[0].lower()
    md5 = row[1].lower()
    crc = int(row[2].lower(), 16)
    file_name = utils.SmartUnicode(row[3])
    file_size = int(row[4])
    special_code = row[7]
    store.AddHash(sha1, md5, crc, file_name, file_size, product_code_list,
                  op_system_code_list, special_code)


def ImportFile(store, filename, start):
Example #8
0
import logging

# We need to import the server_plugins module before other server init modules.
# pylint: disable=unused-import,g-bad-import-order
from grr.server.grr_response_server import server_plugins
# pylint: disable=unused-import,g-bad-import-order

from grr import config
from grr.config import contexts
from grr.core.grr_response_core.lib import flags
from grr.server.grr_response_server import access_control
from grr.server.grr_response_server import data_store
from grr.server.grr_response_server import server_startup
from grr_response_test.end_to_end_tests import runner

flags.DEFINE_string("api_endpoint", "http://localhost:8000",
                    "GRR API endpoint.")

flags.DEFINE_string("api_user", "admin", "Username for GRR API.")

flags.DEFINE_string("api_password", "", "Password for GRR API.")

flags.DEFINE_string("client_id", "", "Id for client to run tests against.")

flags.DEFINE_list(
    "whitelisted_tests", [],
    "(Optional) comma-separated list of tests to run (skipping all others).")

flags.DEFINE_list(
    "blacklisted_tests", [],
    "(Optional) comma-separated list of tests to skip. Trumps "
    "--whitelisted_tests if there are any conflicts.")
Example #9
0
#!/usr/bin/env python
"""This is a single binary that runs all the GRR components.

To use this entry point you must run "grr_config_updater initialize" first.
"""

from grr.config import server as config_server

from grr.core.grr_response_core.lib import flags
from grr.server.grr_response_server.bin import frontend
from grr.server.grr_response_server.bin import worker
from grr.server.grr_response_server.gui import admin_ui

flags.DEFINE_string("component", None,
                    "Component to start: [frontend|admin_ui|worker].")

flags.DEFINE_version(config_server.VERSION["packageversion"])


def main(argv):
    """Sets up all the component in their own threads."""

    # We use .startswith so that multiple copies of services can easily be
    # created using systemd as worker1 worker2 ... worker25 etc.

    if not flags.FLAGS.component:
        raise ValueError("Need to specify which component to start.")

    # Start as a worker.
    if flags.FLAGS.component.startswith("worker"):
        worker.main([argv])
Example #10
0
from grr_api_client import api
from grr_api_client import api_shell_lib
from grr.config import contexts
from grr.config import server as config_server
from grr.core.grr_response_core.lib import flags
from grr.server.grr_response_server import access_control
from grr.server.grr_response_server import fleetspeak_connector
from grr.server.grr_response_server import server_startup
from grr.server.grr_response_server.bin import api_shell_raw_access_lib

flags.DEFINE_integer(
    "page_size", 1000,
    "Page size used when paging through collections of items. Default is 1000.")

flags.DEFINE_string(
    "username", None, "Username to use when making raw API calls. If not "
    "specified, USER environment variable value will be used.")

flags.DEFINE_string(
    "exec_code", None,
    "If present, no IPython shell is started but the code given in "
    "the flag is run instead (comparable to the -c option of "
    "IPython). The code will be able to use a predefined "
    "global 'grrapi' object.")

flags.DEFINE_string(
    "exec_file", None,
    "If present, no IPython shell is started but the code given in "
    "command file is supplied as input instead. The code "
    "will be able to use a predefined global 'grrapi' "
    "object.")