예제 #1
0
  def Render(self, args, token=None):
    fd = aff4.FACTORY.Open("aff4:/hunts", mode="r", token=token)

    children = list(fd.ListChildren())
    children.sort(key=operator.attrgetter("age"), reverse=True)
    if args.count:
      children = children[args.offset:args.offset + args.count]
    else:
      children = children[args.offset:]

    hunt_list = []
    for hunt in fd.OpenChildren(children=children):
      if not isinstance(hunt, hunts.GRRHunt) or not hunt.state:
        continue

      hunt_list.append(hunt)

    hunt_list.sort(key=lambda hunt: hunt.GetRunner().context.create_time,
                   reverse=True)

    encoded_hunt_list = []
    for hunt in hunt_list:
      encoded_hunt = api_aff4_object_renderers.RenderAFF4Object(
          hunt, [rdfvalue.ApiAFF4ObjectRendererArgs(limit_lists=0)])
      encoded_hunt_list.append(encoded_hunt)

    return encoded_hunt_list
예제 #2
0
    def Render(self, args, token=None):
        end = args.count or sys.maxint
        rendered_clients = []

        # An empty query matches all clients, use the universal keyword ".".
        query = args.query or "."
        keywords = shlex.split(query)
        if not keywords:
            raise ValueError("Couldn't parse query string.")

        index = aff4.FACTORY.Create(client_index.MAIN_INDEX,
                                    aff4_type="ClientIndex",
                                    mode="rw",
                                    token=token)
        result_urns = sorted(index.LookupClients(keywords),
                             key=str)[args.offset:args.offset + end]
        result_set = aff4.FACTORY.MultiOpen(result_urns, token=token)

        for child in result_set:
            rendered_client = api_aff4_object_renderers.RenderAFF4Object(
                child, [
                    rdfvalue.ApiAFF4ObjectRendererArgs(
                        type_info="WITH_TYPES_AND_METADATA")
                ])
            rendered_clients.append(rendered_client)

        return dict(query=args.query,
                    offset=args.offset,
                    count=len(rendered_clients),
                    items=rendered_clients)
예제 #3
0
    def testRendersAff4VolumeWithTypeInfo(self):
        data = self.renderer.RenderObject(
            self.fd,
            rdfvalue.ApiAFF4ObjectRendererArgs(type_info="WITH_TYPES"))

        self.assertEqual(
            data, {
                "age_policy": "NEWEST_TIME",
                "attributes": {
                    "aff4:type": {
                        "age": 42,
                        "mro": ["RDFString", "RDFBytes", "RDFValue", "object"],
                        "type": "RDFString",
                        "value": "AFF4Volume"
                    },
                    "metadata:last": {
                        "age":
                        42,
                        "mro": [
                            "RDFDatetime", "RDFInteger", "RDFString",
                            "RDFBytes", "RDFValue", "object"
                        ],
                        "type":
                        "RDFDatetime",
                        "value":
                        42000000
                    }
                },
                "urn": "aff4:/tmp/foo/bar",
                "aff4_class": "AFF4Volume"
            })
예제 #4
0
    def Render(self, args, token=None):
        end = args.count or sys.maxint
        rendered_clients = []

        keywords = shlex.split(args.query)

        index = aff4.FACTORY.Create(client_index.MAIN_INDEX,
                                    aff4_type="ClientIndex",
                                    mode="rw",
                                    token=token)
        result_urns = sorted(index.LookupClients(keywords),
                             key=str)[args.offset:args.offset + end]
        result_set = aff4.FACTORY.MultiOpen(result_urns, token=token)

        for child in result_set:
            rendered_client = api_aff4_object_renderers.RenderAFF4Object(
                child, [
                    rdfvalue.ApiAFF4ObjectRendererArgs(
                        type_info="WITH_TYPES_AND_METADATA")
                ])
            rendered_clients.append(rendered_client)

        return dict(query=args.query,
                    offset=args.offset,
                    count=len(rendered_clients),
                    items=rendered_clients)
예제 #5
0
 def Render(self, args, token=None):
   hunt = aff4.FACTORY.Open(
       HUNTS_ROOT_PATH.Add(args.hunt_id),
       aff4_type="GRRHunt",
       token=token)
   return api_aff4_object_renderers.RenderAFF4Object(
       hunt, [ApiGRRHuntRendererArgs(with_full_summary=True),
              rdfvalue.ApiAFF4ObjectRendererArgs(limit_lists=10)])
예제 #6
0
    def Render(self, args, token=None):
        client = aff4.FACTORY.Open(args.client_id,
                                   aff4_type="VFSGRRClient",
                                   token=token)

        return api_aff4_object_renderers.RenderAFF4Object(
            client, [
                rdfvalue.ApiAFF4ObjectRendererArgs(
                    type_info="WITH_TYPES_AND_METADATA")
            ])
예제 #7
0
    def _RenderHuntList(self, hunt_list):
        hunts_list = sorted(
            hunt_list,
            reverse=True,
            key=lambda hunt: hunt.GetRunner().context.create_time)

        encoded_hunt_list = []
        for hunt in hunts_list:
            encoded_hunt = api_aff4_object_renderers.RenderAFF4Object(
                hunt, [rdfvalue.ApiAFF4ObjectRendererArgs(limit_lists=0)])
            encoded_hunt_list.append(encoded_hunt)

        return encoded_hunt_list
예제 #8
0
    def testRendersAff4Volume(self):
        data = self.renderer.RenderObject(self.fd,
                                          rdfvalue.ApiAFF4ObjectRendererArgs())

        self.assertEqual(
            data, {
                "age_policy": "NEWEST_TIME",
                "attributes": {
                    "aff4:type": "AFF4Volume",
                    "metadata:last": 42000000
                },
                "urn": "aff4:/tmp/foo/bar",
                "aff4_class": "AFF4Volume"
            })
예제 #9
0
    def testRenderersAff4VolumeWithTypeInfoAndDescriptions(self):
        data = self.renderer.RenderObject(
            self.fd,
            rdfvalue.ApiAFF4ObjectRendererArgs(
                type_info="WITH_TYPES_AND_METADATA"))

        self.assertEqual(
            data, {
                "age_policy": "NEWEST_TIME",
                "attributes": {
                    "aff4:type": {
                        "age": 42,
                        "mro": ["RDFString", "RDFBytes", "RDFValue", "object"],
                        "type": "RDFString",
                        "value": "AFF4Volume"
                    },
                    "metadata:last": {
                        "age":
                        42,
                        "mro": [
                            "RDFDatetime", "RDFInteger", "RDFString",
                            "RDFBytes", "RDFValue", "object"
                        ],
                        "type":
                        "RDFDatetime",
                        "value":
                        42000000
                    }
                },
                "urn": "aff4:/tmp/foo/bar",
                "aff4_class": "AFF4Volume",
                "metadata": {
                    "aff4:type": {
                        "description":
                        "The name of the "
                        "AFF4Object derived class."
                    },
                    "metadata:last": {
                        "description":
                        "The last time any "
                        "attribute of this "
                        "object was written."
                    }
                }
            })
예제 #10
0
    def testAdditionalArgumentsAreParsedCorrectly(self):
        additional_args = api_call_renderers.FillAdditionalArgsFromRequest(
            {
                "AFF4Object.limit_lists": "10",
                "RDFValueCollection.with_total_count": "1"
            }, {
                "AFF4Object": rdfvalue.ApiAFF4ObjectRendererArgs,
                "RDFValueCollection":
                rdfvalue.ApiRDFValueCollectionRendererArgs
            })
        additional_args = sorted(additional_args, key=lambda x: x.name)

        self.assertListEqual([x.name for x in additional_args],
                             ["AFF4Object", "RDFValueCollection"])
        self.assertListEqual(
            [x.type for x in additional_args],
            ["ApiAFF4ObjectRendererArgs", "ApiRDFValueCollectionRendererArgs"])
        self.assertListEqual([x.args for x in additional_args], [
            rdfvalue.ApiAFF4ObjectRendererArgs(limit_lists=10),
            rdfvalue.ApiRDFValueCollectionRendererArgs(with_total_count=True)
        ])