Skip to main content

HackTheBox machine lifecycle automation: spawn, attack, stop.

Project description

htbctl

Python library and CLI for HackTheBox machine lifecycle automation.

spawn → wait for IP → attack → stop

Requires Python 3.9+. Works with free and VIP HTB accounts.


Install

pip install htbctl

Setup

  1. Go to https://app.hackthebox.com/profile/settingsApp TokensCreate App Token
  2. Save the token in any of these locations (checked in order):
# Option A — dedicated config (recommended)
mkdir -p ~/.config/htbctl
echo "HTB_TOKEN=eyJ..." > ~/.config/htbctl/.env

# Option B — .env in current directory
echo "HTB_TOKEN=eyJ..." > .env

# Option C — environment variable
export HTB_TOKEN=eyJ...

Or pass the token directly in Python:

htb = HTBIntegration(token="eyJ...")
htb = HTBIntegration(env_path="path/to/.env")
  1. Make sure HTB VPN is connected — spawned machines are only reachable through VPN.

Python API

from htbctl import HTBIntegration

# Reads: ~/.config/htbctl/.env → .env → HTB_TOKEN env var
with HTBIntegration() as htb:
    machine = htb.spawn("Cap")
    print(machine.ip)   # 10.10.11.xx
    # ... run your exploit here ...
# machine is stopped automatically

Explicit token:

htb = HTBIntegration(token="eyJ...")
machine = htb.spawn("Precious")
htb.stop("Precious")

CLI

htbctl login                        # verify token
htbctl list                         # list all retired machines
htbctl list cap                     # filter by name

htbctl spawn Precious               # spawn a machine, print IP
htbctl spawn Precious --force       # stop active machine first, then spawn

htbctl stop Precious                # stop by name
htbctl stop --active                # stop whatever is running

SpawnedMachine

machine = htb.spawn("Cap")
machine.name        # "Cap"
machine.ip          # "10.10.11.xx"
machine.os          # "Linux"
machine.difficulty  # "Easy"
machine.machine_id  # 351

Exceptions

from htbctl import HTBError, HTBAuthError, HTBMachineNotFoundError, HTBSpawnError, HTBRateLimitError
Exception When
HTBAuthError Invalid or expired token
HTBMachineNotFoundError Machine name not found
HTBSpawnError Spawn failed or IP timeout
HTBRateLimitError API rate limit (HTTP 429)
HTBError Base class for everything above

Logging

The library is silent by default. To see what's happening:

import logging
logging.getLogger("htbctl").addHandler(logging.StreamHandler())
logging.getLogger("htbctl").setLevel(logging.DEBUG)

The CLI enables logging automatically with [htbctl] prefix.


Credits & Alternatives

This project was inspired by pyhackthebox by @clubby789.

Why htbctl exists:

  • pyhackthebox is a general-purpose client (last update: 2022)
  • htbctl is focused on automation: spawn → attack → stop
  • App Token auth only (no email/password/OTP)
  • Context manager with auto-stop

If you need full HTB API coverage (challenges, leaderboards, user profiles) — use pyhackthebox. If you need to automate machine attacks — use htbctl.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htbctl-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htbctl-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file htbctl-0.1.0.tar.gz.

File metadata

  • Download URL: htbctl-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for htbctl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cae0df8e3049f1463cdaa43b72d09c03de74ed2ca3218c07f9e31698fdca7eba
MD5 627922b4761c5289e585bf94c71f56a0
BLAKE2b-256 0d08da90caed5b4361b3852c38271c37cfaf6d2fa397b5f45713e6c0e080bad0

See more details on using hashes here.

File details

Details for the file htbctl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: htbctl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for htbctl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cac89c19db4334a5b33bf0eaad63a1a794fd8e8a4d0abcac51095fdbce3ae430
MD5 89e3b039245759d238ec347898fc96a3
BLAKE2b-256 5e084649003e2df9f33066d315ceb9bc40779c7935c43c7ecfb862785d23ddfd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page