# shellcheck shell=sh
# doctor.sh — concise health check for the HTB workstation.
doctor__row() {
_label=$1; shift
_found=""
for _candidate in "$@"; do
if command -v "$_candidate" >/dev/null 2>&1; then
_found=$(command -v "$_candidate")
break
fi
done
if [ -n "$_found" ]; then
printf ' %s%-24s%s %s\n' "$(pe_fg "$PE_RP_FOAM")" "$_label" "$(pe_reset)" "$_found"
else
printf ' %s%-24s%s %s\n' "$(pe_fg "$PE_RP_GOLD")" "$_label" "$(pe_reset)" 'not found'
fi
}
doctor__heading() {
printf '\n%s%s%s\n' "$(pe_fg "$PE_RP_IRIS")" "$1" "$(pe_reset)"
}
doctor__mode() {
stat -c '%a' "$1" 2>/dev/null \
|| stat -f '%Lp' "$1" 2>/dev/null \
|| printf '?'
}
doctor__tunnel() {
if command -v ip >/dev/null 2>&1; then
ip -o -4 addr show 2>/dev/null \
| awk '$2 ~ /^(tun|tap|wg)/ {print $2 " " $4; exit}'
elif command -v ifconfig >/dev/null 2>&1; then
ifconfig 2>/dev/null | awk '
/^[[:alnum:]][^:]*:/ {iface=$1; sub(/:$/, "", iface)}
iface ~ /^(utun|tun|tap|wg)/ && $1 == "inet" {print iface " " $2; exit}'
fi
}
doctor_main() {
pe_dirs_ensure || pe_die "could not prepare pentest-env directories"
printf '%spentest-env doctor%s\n' "$(pe_bold)$(pe_fg "$PE_RP_IRIS")" "$(pe_reset)"
printf ' %-24s %s / %s\n' 'platform' "$(uname -s)" "$(uname -m)"
printf ' %-24s %s\n' 'work root' "$PE_WORKROOT"
printf ' %-24s %s\n' 'wordlists' "$PE_WORDLIST_ROOT"
doctor__heading 'Core lab tools'
doctor__row 'SQLCipher' "$PE_SQLCIPHER" sqlcipher
doctor__row 'Table formatter' column
doctor__row 'Nmap' nmap
doctor__row 'FFUF' ffuf
doctor__row 'Feroxbuster' feroxbuster
doctor__row 'Nuclei' nuclei
doctor__row 'NetExec' nxc netexec
doctor__row 'Impacket' secretsdump.py impacket-secretsdump
doctor__row 'Certipy' certipy
doctor__row 'Metasploit' msfconsole
doctor__row 'Wireshark CLI' tshark
doctor__row 'OpenVPN' openvpn
doctor__heading 'ARM64 challenge support'
doctor__row 'x86-64 emulator' qemu-x86_64
doctor__row 'multiarch GDB' gdb-multiarch
doctor__row 'native GDB' gdb
doctor__heading 'Isolation and permissions'
for _entry in "data|$PE_DATA_DIR" "state|$PE_STATE_DIR" \
"backups|$PE_BACKUP_DIR" "VPN profiles|$PE_VPN_DIR"; do
_label=${_entry%%|*}; _path=${_entry#*|}
_mode=$(doctor__mode "$_path")
printf ' %-24s mode %s %s\n' "$_label" "$_mode" "$_path"
done
if [ -f "$PE_DB" ]; then
printf ' %-24s mode %s\n' 'encrypted database' "$(doctor__mode "$PE_DB")"
else
printf ' %-24s %s\n' 'encrypted database' "not initialized (run: pe init)"
fi
doctor__heading 'Lab tunnel'
_tunnel=$(doctor__tunnel)
if [ -n "$_tunnel" ]; then
printf ' %sconnected%s %s\n' "$(pe_fg "$PE_RP_FOAM")" "$(pe_reset)" "$_tunnel"
else
printf ' %snot connected%s import a pack with: pe vpn import ~/Downloads/file.ovpn\n' \
"$(pe_fg "$PE_RP_GOLD")" "$(pe_reset)"
fi
doctor__heading 'Safety defaults'
printf ' scan/fullscan/webenum require a tun/tap/utun/wg route unless PE_ALLOW_NO_VPN=1.\n'
printf ' tmux persistence is off so command lines and pane secrets are not saved.\n'
printf ' prefix commands containing secrets with a leading space to omit shell history.\n'
}