Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing recent changes. #1055

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

* Removed support for Chipsec based flows.
* Removed ClientArtifactCollector flow and related client actions.
* Removed indexing endpoints on snapshot `uname` (searching is still possible
by individual and combination of system name, release and version).
* Removed support for foreman rules using `uname` of an endpoint (this can be
simulated by using 3 rules for system name, release and version).

### API removed

* GetClientLoadStats API method (`/api/clients/<client_id>/load-stats/<metric>`).
Client load stats collection functionality was removed from GRR, as
it was rarely used and Fleetspeak already collects basic client stats anyway.
Instead of fixing/maintaining the GRR client load stats logic, we will
better to invest into Fleetspeak's client load stats enhancements.
* ApiReportData definition (used by GetReport, `/api/stats/reports/<name>`)
changed: support for stack, line and pie charts removed. All stack/line/pie
chart report plugins removed (namely: GRRVersion1ReportPlugin,
GRRVersion7ReportPlugin, GRRVersion30ReportPlugin, LastActiveReportPlugin,
OSBreakdown1ReportPlugin, OSBreakdown7ReportPlugin, OSBreakdown14ReportPlugin,
OSBreakdown30ReportPlugin, OSReleaseBreakdown1ReportPlugin,
OSReleaseBreakdown7ReportPlugin, OSReleaseBreakdown14ReportPlugin,
OSReleaseBreakdown30ReportPlugin, SystemFlowsReportPlugin,
UserFlowsReportPlugin, MostActiveUsersReportPlugin, UserActivityReportPlugin).

### Planned for removal

Note: GRR release 3.4.7.1 is the **last release** containing the following
Expand Down
19 changes: 19 additions & 0 deletions api_client/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ grr_api_shell --basic_auth_username "user" --basic_auth_password "pwd" \
http://localhost:1234
```

Download a single file collected from a GRR client (helpful for large files
\> 4GB that can't be added to an archive):

```bash
grr_api_shell --basic_auth_username "user" --basic_auth_password "pwd" \
--exec_code 'grrapi.Client("C.1234567890ABCDEF").File("/fs/os/var/log/syslog").GetBlob().WriteToFile("./syslog")' \
http://localhost:1234
```


Download an archive of all files collected with OS-handler (not TSK/NTFS) from a
GRR client:

Expand All @@ -202,3 +212,12 @@ grr_api_shell --basic_auth_username "user" --basic_auth_password "pwd" \
--exec_code 'for r in grrapi.Client("C.1234567890ABCDEF").Flow("F:BB628B23").ListResults(): print(str(r.payload))' \
http://localhost:1234
```

Decrypt a file from a Collect Large File flow:

```bash
cat encrypted_file | \
grr_api_shell --basic_auth_username "user" --basic_auth_password "pwd" \
--exec_code 'grrapi.Client("C.1234567890ABCDEF").Flow("F:BB628B23").Get().DecryptLargeFile()' \
http://localhost:1234 > decrypted_file
```
12 changes: 8 additions & 4 deletions api_client/python/grr_api_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def CreateHunt(
flow_name=flow_name,
flow_args=flow_args,
hunt_runner_args=hunt_runner_args,
context=self._context)
context=self._context,
)

def CreatePerClientFileCollectionHunt(
self,
hunt_args: hunt_pb2.ApiCreatePerClientFileCollectionHuntArgs,
) -> hunt.Hunt:
return hunt.CreatePerClientFileCollectionHunt(
hunt_args, context=self._context)
hunt_args, context=self._context
)

def ListHunts(self) -> utils.ItemsIterator[hunt.Hunt]:
return hunt.ListHunts(context=self._context)
Expand All @@ -87,7 +89,8 @@ def GrrBinary(
path: str,
) -> config.GrrBinaryRef:
return config.GrrBinaryRef(
binary_type=binary_type, path=path, context=self._context)
binary_type=binary_type, path=path, context=self._context
)

def GrrUser(self) -> user.GrrUser:
return user.GrrUser(context=self._context)
Expand Down Expand Up @@ -132,6 +135,7 @@ def InitHttp(
verify=verify,
cert=cert,
trust_env=trust_env,
validate_version=validate_version)
validate_version=validate_version,
)

return GrrApi(connector=connector)
57 changes: 37 additions & 20 deletions api_client/python/grr_api_client/api_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import sys


from grr_api_client import api
from grr_api_client import api_shell_lib

Expand All @@ -17,51 +16,68 @@ def __init__(self):
super().__init__()

self.add_argument(
"api_endpoint", type=str, help="API endpoint specified as host[:port]")
"api_endpoint", type=str, help="API endpoint specified as host[:port]"
)

self.add_argument(
"--page_size",
type=int,
help="Page size used when paging through collections of items.")
help="Page size used when paging through collections of items.",
)
self.add_argument(
"--basic_auth_username",
type=str,
help="HTTP basic auth username (HTTP basic auth will be used if this "
"flag is set).")
help=(
"HTTP basic auth username (HTTP basic auth will be used if this "
"flag is set)."
),
)
self.add_argument(
"--basic_auth_password",
type=str,
help="HTTP basic auth password (will be used if basic_auth_username is "
"set).")
help=(
"HTTP basic auth password (will be used if basic_auth_username is "
"set)."
),
)
self.add_argument(
"--no-check-certificate",
dest="no_check_certificate",
action="store_true",
help="If set, don't verify server's SSL certificate.")
help="If set, don't verify server's SSL certificate.",
)
self.add_argument(
"--no-check-version",
dest="no_check_version",
action="store_true",
help="Skip server version compatibility check")
help="Skip server version compatibility check",
)
self.add_argument(
"--debug",
dest="debug",
action="store_true",
help="Enable debug logging.")
help="Enable debug logging.",
)
self.add_argument(
"--exec_code",
type=str,
help="If present, no console 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.")
help=(
"If present, no console 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."
),
)
self.add_argument(
"--exec_file",
type=str,
help="If present, no console 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.")
help=(
"If present, no console 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."
),
)


def main(argv=None):
Expand All @@ -84,14 +100,15 @@ def main(argv=None):
page_size=flags.page_size,
auth=auth,
verify=not flags.no_check_certificate,
validate_version=not flags.no_check_version)
validate_version=not flags.no_check_version,
)

if flags.exec_code and flags.exec_file:
print("--exec_code --exec_file flags can't be supplied together")
sys.exit(1)
elif flags.exec_code:
# pylint: disable=exec-used
exec (flags.exec_code, dict(grrapi=grrapi))
exec(flags.exec_code, dict(grrapi=grrapi))
# pylint: enable=exec-used
elif flags.exec_file:
api_shell_lib.ExecFile(flags.exec_file, grrapi)
Expand Down
2 changes: 1 addition & 1 deletion api_client/python/grr_api_client/api_shell_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def IPShell(argv=None, user_ns=None, banner=None):
def ExecFile(filepath, grrapi):
with open(filepath, "r") as filedesc:
ast = compile(filedesc.read(), filename=filepath, mode="exec")
exec (ast, {"grrapi": grrapi}) # pylint: disable=exec-used
exec(ast, {"grrapi": grrapi}) # pylint: disable=exec-used
6 changes: 4 additions & 2 deletions api_client/python/grr_api_client/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def __init__(


def ListArtifacts(
context: api_context.GrrApiContext) -> utils.ItemsIterator[Artifact]:
context: api_context.GrrApiContext,
) -> utils.ItemsIterator[Artifact]:
"""Lists all registered Grr artifacts."""
args = api_artifact_pb2.ApiListArtifactsArgs()

items = context.SendIteratorRequest("ListArtifacts", args)
return utils.MapItemsIterator(
lambda data: Artifact(data=data, context=context), items)
lambda data: Artifact(data=data, context=context), items
)
Loading
Loading