Resources

class htv.resources.HtvVault(path=None)[source]

Bases: object

Dataclass representing the HtbVault. It allows to manage the vault, adding/removing/opening resources, listing them or initializing/deleting the entire vault

Variables:

_path – [Path] Path to the vault. May contain environment variables

Parameters:

[str|Path] (path) – Path to the vault. If None, the default directory from conf will be used

static clean()[source]

Clean-up vault

Deletes hidden directories created by text editors, in addition to cached and temp files. These files/dirs usually start by ‘.’ or ‘_’. .gitignore file and .git dir are always excluded.

Return type:

int

Returns:

0 on success. 1 if an error occurred

static remove_resources(*args)[source]

Remove resources from the vault

Parameters:

args – resource(s) name or index

Return type:

int

Returns:

The number of resources deleted

makedirs(reset=False)[source]

Create vault dir structure

Parameters:

reset (bool) – If True, and the vault already exists, the vault is deleted and reset to initial state

Return type:

int

Returns:

0 if vault initialized successfully. 1 otherwise

removedirs()[source]

Removes the entire vault

Return type:

int

Returns:

0 on success

add_resources(res, _stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Add resource(s) to the vault

Parameters:
  • res (HtvResource | list[HtvResource]) – HtbResource or a list of them. If None, user will be prompt to input required Resource data

  • _stdout (tqdm | TextIO) – Stdout to log information. Default to STDOUT

Return type:

int

Returns:

number of resources added successfully

list_resources(*args, regex=None)[source]

List resources from the vault

Parameters:
  • args – resource types HtbResource.type

  • regex (str) – regex applied on the resource name. If None, no filter is applied

Return type:

list[Path]

Returns:

A list with the resources found, or None if no match

use_resource(*args)[source]

Opens resource(s)

Parameters:

args – Name(s) and/or index(es) of the resources to be opened

Return type:

HtvResource | list[HtvResource] | None

Returns:

A HtbResource, or a list of them. None if the resource could not be opened

class htv.resources.HtvResource(**kwargs)[source]

Bases: CustomResource

Dataclass representing a generic HtbResource. This class is the parent of all resource types that can be found in HTB

Variables:
  • __type__ – [str] Resource type ID (short-name). Possible values datasources/sources.yml

  • __resource_dir__ – [str] Location for these resources within the vault (relative path)

# :ivar _metadata: [Metadata]: resource information

makedirs()[source]

Dump serialized object to file

Serializes and dumps this instance into a file (info.json). Additional arguments are tuples specifying other default files to be created,

Return type:

None

Returns:

None

open()[source]

Open the resource

Open the resource in all the possible ways: opening the URL in a web browser, opening the Vault with your favorite editor (Obsidian, Code), and opening virtual-box to run your PwnBox or Kali instance.

Return type:

None

Returns:

None

class htv.resources.HtvPath(**kwargs)[source]

Bases: HtvResource

Abstract class representing a Path in the HTB academy

Variables:

_sections – [list] Collection of modules and/or exercises

property progress: str

Completion status string

property sections

Collection of modules and/or exercises

makedirs(*args, missing_ok=False)[source]

Create the directory structure of the path, including the corresponding modules/exercises

Parameters:

missing_ok (bool) – If True, user will not be prompted to add the missing modules

Return type:

None

Returns:

None

class htv.resources.HtvModule(**kwargs)[source]

Bases: HtvResource

Modules represent some knowledge that is related together around a topic. It includes Sections, which are single pages focused on a single subtopic.

Modules can be aggregated in a HtvPath

Variables:

_sections – list[str] Module sections (Section)

class Section(__type__=None, title=None, number=1)[source]

Bases: object

Sections are like data-pills. A post, not long, focused on a single topic

Dataclass representing a Section of a HtbModule

Variables:
  • __type__ – [str] Type of section (interactive, document)

  • title – [str] Section title used in the section template. May contain spaces

  • name – [str] Secured file name (utils.FsTools.secure_filename())

Parameters:
  • __type__ – Type of section (interactive, document)

  • title (str) – Section title, may contain spaces

add_section(__type__, name)[source]

Adds a new section to this module

Parameters:
  • __type__ – Type of section (interactive / document)

  • name (str) – Title of the section. May contain spaces

Return type:

Section

Returns:

the new Section added

remove_section(index)[source]

Removes a section from this module

Parameters:

index (int) – Index of the section to be removed

Return type:

Section

Returns:

the removed Section

class htv.resources.HtvExercise(**kwargs)[source]

Bases: HtvResource

Abstract class representing a resource from HTB lab

Variables:

_tasks – [list[Task]] List of tasks associated to this resource

class Task(text=None, answer=None, points=None, number=None)[source]

Bases: object

Dataclass representing a Task within a HtbResource

Variables:
  • number – [int] Task number (default 1)

  • text – [str] Task text, brief question or goal

  • answer – [str] Task answer or solution (default None)

  • points – [int] Points obtained when completing the task

to_markdown()[source]
Return type:

str

Returns:

string with the MarkDown representation of the Task

add_task(text=None, answer=None, points=0, index=None)[source]

Adds a new Task to this machine

Parameters:
  • text (str) – Text of the task

  • answer (str) – Answer of the task

  • points (int) – Points of the task

  • index (int) – Index of the task. Defaults to None (auto-increment)

Return type:

Task

Returns:

the added Task

remove_task(index)[source]

Removes a Task from this machine

Parameters:

index (int) – Index of the Task to be removed

Return type:

Task

Returns:

the removed Task