dissect.target.tools.shell
#
Module Contents#
Classes#
Subclassed cmd.Cmd to provide some additional features. |
|
Hub Cli for interacting with multiple targets. |
|
CLI for interacting with a target and browsing the filesystem. |
|
CLI for interacting with a target and browsing the filesystem. |
|
CLI for browsing the registry. |
Functions#
Parse the LS_COLORS environment variable so we can use it later. |
|
Helper method to colorize strings according to LS_COLORS. |
|
Generator context manager that chains piped subprocessess and |
|
Generator context manager that chains piped subprocessess, with a chain's |
|
Helper method for generating a mode string from a numerical mode value. |
|
Helper method for starting a regular, Python or registry shell for one or multiple targets. |
|
Helper method for starting a |
|
Helper method for starting a (I)Python shell with multiple targets. |
|
Helper method for instatiating the appropriate CLI. |
|
Helper method for running a cmd.Cmd cli. |
|
Attributes#
- dissect.target.tools.shell.log#
- dissect.target.tools.shell.STAT_TEMPLATE = Multiline-String#
Show Value
""" File: {path} {symlink} Size: {size} {filetype} Inode: {inode} Links: {nlink} Access: ({modeord}/{modestr}) Uid: ( {uid} ) Gid: ( {gid} ) Access: {atime} Modify: {mtime} Change: {ctime}"""
- dissect.target.tools.shell.FALLBACK_LS_COLORS = 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00...'#
- dissect.target.tools.shell.prepare_ls_colors() dict[str, str] #
Parse the LS_COLORS environment variable so we can use it later.
- dissect.target.tools.shell.LS_COLORS#
- class dissect.target.tools.shell.TargetCmd(target: dissect.target.target.Target)#
Bases:
cmd.Cmd
Subclassed cmd.Cmd to provide some additional features.
- Add new simple commands by implementing:
do_<cmd>(self, line)
- Add new complex commands by implementing:
cmd_<cmd>(self, args, stdout)
Simple commands are plain cmd.Cmd commands. Output is generally presented using print().
Complex command allow @arg decorators for argparse argument parsing. Additionally, complex commands allow their output to be piped to external commands. Complex commands should therefor always write to the stdout handle that is passed as argument.
- CMD_PREFIX = 'cmd_'#
- __getattr__(attr: str) Any #
- static check_compatible(target: dissect.target.target.Target) bool #
- get_names() list[str] #
- default(line: str) bool | None #
Called on an input line when the command prefix is not recognized.
If this method is not overridden, it prints an error message and returns.
- emptyline() None #
This function forces Python’s cmd.Cmd module to behave like a regular shell.
When entering an empty command, the cmd module will by default repeat the previous command. By defining an empty
emptyline
function we make sure no command is executed instead. See https://stackoverflow.com/a/16479030
- do_python(line: str) bool | None #
drop into a Python shell
- do_clear(line: str) bool | None #
clear the terminal screen
- do_cyber(line: str) bool | None #
cyber
- do_exit(line: str) bool | None #
exit shell
- class dissect.target.tools.shell.TargetHubCli(targets: list[dissect.target.target.Target], cli: TargetCmd)#
Bases:
cmd.Cmd
Hub Cli for interacting with multiple targets.
- prompt = 'dissect> '#
- doc_header = Multiline-String#
Show Value
"""Target Hub ========== List and enter targets by using 'list' and 'enter'. Documented commands (type help <topic>):"""
- default(line: str) bool | None #
Called on an input line when the command prefix is not recognized.
If this method is not overridden, it prints an error message and returns.
- emptyline() None #
Called when an empty line is entered in response to the prompt.
If this method is not overridden, it repeats the last nonempty command entered.
- do_exit(line: str) bool | None #
exit shell
- do_list(line: str) bool | None #
list the loaded targets
- do_enter(line: str) bool | None #
enter a target by number or name
- complete_enter(text: str, line: str, begidx: int, endidx: int) list[str] #
- do_python(line: str) bool | None #
drop into a Python shell
- class dissect.target.tools.shell.TargetCli(target: dissect.target.target.Target)#
Bases:
TargetCmd
CLI for interacting with a target and browsing the filesystem.
- property prompt: str#
- completedefault(text: str, line: str, begidx: int, endidx: int)#
Method called to complete an input line when no command-specific complete_*() method is available.
By default, it returns an empty list.
- resolve_path(path: str) dissect.target.helpers.fsutil.TargetPath #
- resolve_glob_path(path: str) Iterator[dissect.target.helpers.fsutil.TargetPath] #
- check_file(path: str) dissect.target.helpers.fsutil.TargetPath | None #
- check_dir(path: str) dissect.target.helpers.fsutil.TargetPath | None #
- chdir(path: str) None #
Change directory to the given path.
- scandir(path: str, color: bool = False) list[tuple[dissect.target.helpers.fsutil.TargetPath, str]] #
List a directory for the given path.
- do_cd(line: str) bool | None #
change directory
- do_pwd(line: str) bool | None #
print current directory
- do_disks(line: str) bool | None #
print target disks
- do_volumes(line: str) bool | None #
print target volumes
- do_filesystems(line: str) bool | None #
print target filesystems
- do_info(line: str) bool | None #
print target information
- cmd_ls(args: argparse.Namespace, stdout: TextIO) bool | None #
list directory contents
- print_extensive_file_stat(stdout: TextIO, target_path: dissect.target.helpers.fsutil.TargetPath, name: str) None #
Print the file status.
- cmd_find(args: argparse.Namespace, stdout: TextIO) bool | None #
search for files in a directory hierarchy
- cmd_stat(args: argparse.Namespace, stdout: TextIO) bool | None #
display file status
- cmd_file(args: argparse.Namespace, stdout: TextIO) bool | None #
determine file type
- cmd_save(args: argparse.Namespace, stdout: TextIO) bool | None #
save a common file or directory to the host filesystem
- cmd_cat(args: argparse.Namespace, stdout: TextIO) bool | None #
print file content
- cmd_zcat(args: argparse.Namespace, stdout: TextIO) bool | None #
print file content from compressed files
- cmd_hexdump(args: argparse.Namespace, stdout: TextIO) bool | None #
print a hexdump of the first X bytes
- cmd_hash(args: argparse.Namespace, stdout: TextIO) bool | None #
print the MD5, SHA1 and SHA256 hashes of a file
- cmd_less(args: argparse.Namespace, stdout: TextIO) bool | None #
open the first 10 MB of a file with less
- cmd_zless(args: argparse.Namespace, stdout: TextIO) bool | None #
open the first 10 MB of a compressed file with zless
- cmd_readlink(args: argparse.Namespace, stdout: TextIO) bool | None #
print resolved symbolic links or canonical file names
- cmd_registry(args: argparse.Namespace, stdout: TextIO) bool | None #
drop into a registry shell
- cmd_enter(args: argparse.Namespace, stdout: TextIO) None #
load one or more files as sub-targets and drop into a sub-shell
- class dissect.target.tools.shell.UnixConfigTreeCli(target: dissect.target.target.Target)#
Bases:
TargetCli
CLI for interacting with a target and browsing the filesystem.
- property prompt: str#
- check_compatible() bool #
- resolve_path(path: str | dissect.target.helpers.fsutil.TargetPath | None) dissect.target.helpers.fsutil.TargetPath #
- resolve_key(path) dissect.target.filesystem.FilesystemEntry #
- resolve_glob_path(path: dissect.target.helpers.fsutil.TargetPath) Iterator[dissect.target.helpers.fsutil.TargetPath] #
- class dissect.target.tools.shell.RegistryCli(target: dissect.target.target.Target, registry: dissect.target.helpers.regutil.RegfHive | None = None)#
Bases:
TargetCmd
CLI for browsing the registry.
- property prompt: str#
- static check_compatible(target: dissect.target.target.Target) bool #
- completedefault(text: str, line: str, begidx: int, endidx: int) list[str] #
Method called to complete an input line when no command-specific complete_*() method is available.
By default, it returns an empty list.
- resolve_key(path: str) dissect.target.helpers.regutil.RegistryKey #
- check_key(path: str) dissect.target.helpers.regutil.RegistryKey #
- check_value(path: str) dissect.target.helpers.regutil.RegistryValue #
- chdir(path: str) None #
- scandir(path: str, color: bool = False) list[tuple[dissect.target.helpers.regutil.RegistryKey | dissect.target.helpers.regutil.RegistryValue, str]] #
- do_cd(line: str) bool | None #
change subkey
- do_up(line: str) bool | None #
go up a subkey
- do_pwd(line: str) bool | None #
print current path
- do_recommend(line: str) bool | None #
recommend a key
- cmd_ls(args: argparse.Namespace, stdout: TextIO) bool | None #
- cmd_cat(args: argparse.Namespace, stdout: TextIO) bool | None #
- dissect.target.tools.shell.fmt_ls_colors(ft: str, name: str) str #
Helper method to colorize strings according to LS_COLORS.
- dissect.target.tools.shell.build_pipe(pipe_parts: list[str], pipe_stdout: int = subprocess.PIPE) Iterator[tuple[TextIO, BinaryIO]] #
Generator context manager that chains piped subprocessess and returns a tuple (chain input stream, chain output stream).
On context exit the generator will close the input stream and wait for the subprocessess to finish.
- dissect.target.tools.shell.build_pipe_stdout(pipe_parts: list[str]) Iterator[TextIO] #
Generator context manager that chains piped subprocessess, with a chain’s outgoing stream configured to be parent’s stdout.
Generator returns a chain’s input stream from build_pipe generator.
- dissect.target.tools.shell.stat_modestr(st: dissect.target.helpers.fsutil.stat_result) str #
Helper method for generating a mode string from a numerical mode value.
- dissect.target.tools.shell.open_shell(targets: list[str | pathlib.Path], python: bool, registry: bool) None #
Helper method for starting a regular, Python or registry shell for one or multiple targets.
- dissect.target.tools.shell.target_shell(targets: list[dissect.target.target.Target], cli_cls: type[TargetCmd]) None #
Helper method for starting a
TargetCli
orTargetHubCli
for one or multiple targets.
- dissect.target.tools.shell.python_shell(targets: list[dissect.target.target.Target]) None #
Helper method for starting a (I)Python shell with multiple targets.
- dissect.target.tools.shell.create_cli(targets: list[dissect.target.target.Target], cli_cls: type[TargetCmd]) cmd.Cmd | None #
Helper method for instatiating the appropriate CLI.
- dissect.target.tools.shell.run_cli(cli: cmd.Cmd) None #
Helper method for running a cmd.Cmd cli.
Loops cli.cmdloop(), skipping KeyboardInterrupts. This is done so that ctrl+c doesn’t exit the shell but only resets the current line.
- dissect.target.tools.shell.main() None #