Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-15 · v1.0.0+2026-08-14.82f92cb · 82f92cb
← Back to overview
Security article

Hack The Box - Haircut Part 1

Hack The Box - Haircut Part 1: Gain a foothold on the target via command execution, upgrade to an interactive TTY, and retrieve the user flag. • HackTheBox • netcat, nc

2019-10-165 tags
Tags

🎯 Objective

Gain a foothold on the target via command execution, upgrade to an interactive TTY, and retrieve the user flag.

🧩 Environment & Tools

  • DirBuster / gobuster for content discovery
  • Burp Suite (Repeater) for tampering requests
  • Python HTTP server to host payloads
  • Netcat for reverse shell listener
  • Python3 TTY upgrade for an interactive shell

🔎 Recon

Directory brute force

Wordlist:

text
/usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

Results revealed a few interesting endpoints worth manual testing.

Landing Dirbuster hits


🧨 Exploitation

1) Host a payload locally

I spun up a quick web server to stage payloads:

bash
python -m SimpleHTTPServer 8081
# (or) python3 -m http.server 8081

Created a simple shell/payload to pull or trigger from the target: Simple shell payload

2) Command execution via the vulnerable endpoint

Using Burp Repeater, I verified OS command execution with basic commands (e.g., ls, pwd) and then leveraged it to fetch/execute the payload from my HTTP server.

Proof of directory listing from the vulnerable endpoint: List directory via Repeater

Shell obtained: Shell acquired


🧰 Post‑Exploitation

Upgrade to a TTY

The target only had Python 3 readily usable, so I upgraded the shell:

bash
python3 -c 'import pty; pty.spawn("/bin/bash")'

From there, navigation and interaction became much smoother.


🏁 Proof / Flag

Navigated to the user’s home directory and read the flag: User flag


🧪 Commands Used (Quick Reference)

bash
# Recon
gobuster dir -u http://TARGET -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

# Stager
python3 -m http.server 8081     # or: python -m SimpleHTTPServer 8081
nc -lvnp 1337

# TTY upgrade
python3 -c 'import pty; pty.spawn("/bin/bash")'

🛡️ Mitigations (Defender Notes)

  • Validate and sanitize all user inputs; do not pass unsanitized data to system commands.
  • Prefer parameterized calls or safe libraries (avoid system(), exec*(), backticks, etc.).
  • Apply allow‑lists for expected values; reject everything else.
  • Run web apps with least privilege; restrict egress to prevent payload fetching.
  • Centralize logging & alerting on suspicious command patterns or outbound fetch attempts.

🏷️ Tags

HackTheBox, Command Injection, Burp Suite, TTY Upgrade, Recon, Linux

Navigate

In this post

  1. 01🎯 Objective
  2. 02🧩 Environment & Tools
  3. 03🔎 Recon
  4. 04Directory brute force
  5. 05🧨 Exploitation
  6. 061) Host a payload locally
  7. 072) Command execution via the vulnerable endpoint
  8. 08🧰 Post‑Exploitation
  9. 09Upgrade to a TTY
  10. 10🏁 Proof / Flag
  11. 11🧪 Commands Used (Quick Reference)
  12. 12🛡️ Mitigations (Defender Notes)
  13. 13🏷️ Tags
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.