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
- Go to https://app.hackthebox.com/profile/settings → App Tokens → Create App Token
- 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")
- 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:
pyhacktheboxis a general-purpose client (last update: 2022)htbctlis 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.
Metadata
Release files for htbctl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| htbctl-0.1.0.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| htbctl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.7 kB
Release files / htbctl-0.1.0.tar.gz
| Download URL | htbctl-0.1.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cae0df8e3049f1463cdaa43b72d09c03de74ed2ca3218c07f9e31698fdca7eba
|
|
BLAKE2b-256 checksum How to use checksums |
0d08da90caed5b4361b3852c38271c37cfaf6d2fa397b5f45713e6c0e080bad0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / htbctl-0.1.0-py3-none-any.whl
| Download URL | htbctl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cac89c19db4334a5b33bf0eaad63a1a794fd8e8a4d0abcac51095fdbce3ae430
|
|
BLAKE2b-256 checksum How to use checksums |
5e084649003e2df9f33066d315ceb9bc40779c7935c43c7ecfb862785d23ddfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|