Ejemplo n.º 1
0
    def GetSummary(self):
        """Gets a client summary object.

    Returns:
      rdfvalue.ClientSummary
    """
        self.max_age = 0
        summary = rdfvalue.ClientSummary(client_id=self.urn)
        summary.system_info.node = self.Get(self.Schema.HOSTNAME)
        summary.system_info.system = self.Get(self.Schema.SYSTEM)
        summary.system_info.release = self.Get(self.Schema.OS_RELEASE)
        summary.system_info.version = str(self.Get(self.Schema.OS_VERSION, ""))
        summary.system_info.kernel = self.Get(self.Schema.KERNEL)
        summary.system_info.fqdn = self.Get(self.Schema.FQDN)
        summary.system_info.machine = self.Get(self.Schema.ARCH)
        summary.system_info.install_date = self.Get(self.Schema.INSTALL_DATE)
        summary.users = self.Get(self.Schema.USER)
        summary.interfaces = self.Get(self.Schema.LAST_INTERFACES)
        summary.client_info = self.Get(self.Schema.CLIENT_INFO)
        summary.serial_number = self.Get(
            self.Schema.HARDWARE_INFO).serial_number
        summary.timestamp = self.age
        summary.system_manufacturer = self.Get(
            self.Schema.HARDWARE_INFO).system_manufacturer

        return summary
Ejemplo n.º 2
0
  def testClientSummaryToExportedNetworkInterfaceConverter(self):
    client_summary = rdfvalue.ClientSummary(
        interfaces=[rdfvalue.Interface(
            mac_address="123456",
            ifname="eth0",
            addresses=[
                rdfvalue.NetworkAddress(
                    address_type=rdfvalue.NetworkAddress.Family.INET,
                    packed_bytes=socket.inet_aton("127.0.0.1"),
                ),
                rdfvalue.NetworkAddress(
                    address_type=rdfvalue.NetworkAddress.Family.INET,
                    packed_bytes=socket.inet_aton("10.0.0.1"),
                    ),
                rdfvalue.NetworkAddress(
                    address_type=rdfvalue.NetworkAddress.Family.INET6,
                    packed_bytes=socket.inet_pton(socket.AF_INET6,
                                                  "2001:720:1500:1::a100"),
                    )
                ]
            )]
        )

    converter = export.ClientSummaryToExportedNetworkInterfaceConverter()
    results = list(converter.Convert(rdfvalue.ExportedMetadata(),
                                     client_summary,
                                     token=self.token))
    self.assertEqual(len(results), 1)
    self.assertEqual(results[0].mac_address, "123456".encode("hex"))
    self.assertEqual(results[0].ifname, "eth0")
    self.assertEqual(results[0].ip4_addresses, "127.0.0.1 10.0.0.1")
    self.assertEqual(results[0].ip6_addresses, "2001:720:1500:1::a100")
Ejemplo n.º 3
0
    def testNoApplicableTests(self):
        """Try to run linux tests on windows."""
        summary = rdfvalue.ClientSummary(
            system_info=rdfvalue.Uname(system="Windows",
                                       node="hostname",
                                       release="7",
                                       version="6.1.7601SP1",
                                       machine="AMD64",
                                       kernel="6.1.7601",
                                       fqdn="hostname.example.com"))
        self.client = aff4.FACTORY.Open(self.client_id,
                                        mode="rw",
                                        token=self.token)
        self.client.Set(self.client.SchemaCls.SUMMARY(summary))
        self.client.Flush()

        args = rdfvalue.EndToEndTestFlowArgs(test_names=[
            "TestListDirectoryOSLinuxDarwin", "MockEndToEndTest",
            "TestListDirectoryOSLinuxDarwin"
        ])

        self.assertRaises(
            flow.FlowError, list,
            test_lib.TestFlowHelper("EndToEndTestFlow",
                                    self.client_mock,
                                    client_id=self.client_id,
                                    token=self.token,
                                    args=args))
Ejemplo n.º 4
0
    def Run(self):
        # Fix the time to avoid regressions.
        with test_lib.FakeTime(42):
            client_urn = self.SetupClients(1)[0]

            # Delete the certificates as it's being regenerated every time the
            # client is created.
            with aff4.FACTORY.Open(client_urn, mode="rw",
                                   token=self.token) as client_obj:
                client_obj.DeleteAttribute(client_obj.Schema.CERT)

            flow_id = flow.GRRFlow.StartFlow(flow_name="Interrogate",
                                             client_id=client_urn,
                                             token=self.token)

            # Put something in the output collection
            flow_obj = aff4.FACTORY.Open(flow_id,
                                         aff4_type="GRRFlow",
                                         token=self.token)
            flow_state = flow_obj.Get(flow_obj.Schema.FLOW_STATE)

            with aff4.FACTORY.Create(flow_state.context.output_urn,
                                     aff4_type="RDFValueCollection",
                                     token=self.token) as collection:
                collection.Add(rdfvalue.ClientSummary())

        self.Check("GET",
                   "/api/flows/%s/%s/status" %
                   (client_urn.Basename(), flow_id.Basename()),
                   replace={flow_id.Basename(): "F:ABCDEF12"})
Ejemplo n.º 5
0
  def testClientSummaryToExportedClientConverter(self):
    client_summary = rdfvalue.ClientSummary()
    metadata = rdfvalue.ExportedMetadata(hostname="ahostname")

    converter = export.ClientSummaryToExportedClientConverter()
    results = list(converter.Convert(metadata, client_summary,
                                     token=self.token))

    self.assertEqual(len(results), 1)
    self.assertEqual(results[0].metadata.hostname, "ahostname")
Ejemplo n.º 6
0
 def _SetSummaries(self, client_id):
     summary = rdfvalue.ClientSummary(
         system_info=rdfvalue.Uname(system="Darwin",
                                    node=client_id,
                                    release="OSX",
                                    version="10.9.2",
                                    machine="AMD64",
                                    kernel="13.1.0",
                                    fqdn="%s.example.com" % client_id))
     client = aff4.FACTORY.Create(client_id,
                                  "VFSGRRClient",
                                  mode="rw",
                                  token=self.token)
     client.Set(client.SchemaCls.SUMMARY(summary))
     client.Flush()
Ejemplo n.º 7
0
 def setUp(self):
     super(TestEndToEndTestFlow, self).setUp()
     summary = rdfvalue.ClientSummary(
         system_info=rdfvalue.Uname(system="Linux",
                                    node="hostname",
                                    release="debian",
                                    version="14.04",
                                    machine="x86_64",
                                    kernel="3.15-rc2",
                                    fqdn="hostname.example.com"))
     self.client = aff4.FACTORY.Open(self.client_id,
                                     mode="rw",
                                     token=self.token)
     self.client.Set(self.client.SchemaCls.SUMMARY(summary))
     self.client.Flush()
     self.client_mock = action_mocks.ActionMock("ListDirectory", "StatFile")
Ejemplo n.º 8
0
    def Start(self):
        """Start off all the tests."""
        self.state.Register("summary",
                            rdfvalue.ClientSummary(client_id=self.client_id))

        # Create the objects we need to exist.
        self.Load()
        fd = aff4.FACTORY.Create(self.client.urn.Add("network"),
                                 "Network",
                                 token=self.token)
        fd.Close()

        self.CallClient("GetPlatformInfo", next_state="Platform")
        self.CallClient("GetInstallDate", next_state="InstallDate")
        self.CallClient("GetClientInfo", next_state="ClientInfo")
        self.CallClient("GetConfiguration", next_state="ClientConfiguration")
        self.CallClient("EnumerateInterfaces",
                        next_state="EnumerateInterfaces")
        self.CallClient("EnumerateFilesystems",
                        next_state="EnumerateFilesystems")
Ejemplo n.º 9
0
    def GetSummary(self):
        """Gets a client summary object."""
        summary = self.Get(self.Schema.SUMMARY)
        if summary is None:
            summary = rdfvalue.ClientSummary(client_id=self.urn)
            summary.system_info.node = self.Get(self.Schema.HOSTNAME)
            summary.system_info.system = self.Get(self.Schema.SYSTEM)
            summary.system_info.release = self.Get(self.Schema.OS_RELEASE)
            summary.system_info.version = str(
                self.Get(self.Schema.OS_VERSION, ""))
            summary.system_info.fqdn = self.Get(self.Schema.FQDN)
            summary.system_info.machine = self.Get(self.Schema.ARCH)
            summary.system_info.install_date = self.Get(
                self.Schema.INSTALL_DATE)

            summary.users = self.Get(self.Schema.USER)
            summary.interfaces = self.Get(self.Schema.INTERFACES)
            summary.client_info = self.Get(self.Schema.CLIENT_INFO)

        return summary
Ejemplo n.º 10
0
    def testRdfFormatter(self):
        """Hints format RDF values with arbitrary values and attributes."""
        # Create a complex RDF value
        rdf = rdfvalue.ClientSummary()
        rdf.system_info.system = "Linux"
        rdf.system_info.node = "coreai.skynet.com"
        # Users (repeated)
        rdf.users = [rdfvalue.User(username=u) for u in ("root", "jconnor")]
        # Interface (nested, repeated)
        addresses = [
            rdfvalue.NetworkAddress(human_readable=a)
            for a in ("1.1.1.1", "2.2.2.2", "3.3.3.3")
        ]
        eth0 = rdfvalue.Interface(ifname="eth0", addresses=addresses[:2])
        ppp0 = rdfvalue.Interface(ifname="ppp0", addresses=addresses[2])
        rdf.interfaces = [eth0, ppp0]

        template = (
            "{system_info.system} {users.username} {interfaces.ifname} "
            "{interfaces.addresses.human_readable}")
        hinter = hints.Hinter(template=template)
        expected = "Linux root,jconnor eth0,ppp0 1.1.1.1,2.2.2.2,3.3.3.3"
        result = hinter.Render(rdf)
        self.assertEqual(expected, result)