Skip to content
PURPLEDUEL

The token that talks

Encodings & secrets · hard level · 5 objectives · 1000 XP in total

The online shop Faro Shop recognizes users by a token written in the session cookie. The alarm flags a suspicious visitor in the admin panel: find out which token they used and what a careless programmer had forgotten inside it.

Lab 9 of 10 in the Encodings & secrets path. If you get stuck you have 3 hints, from the vaguest to the most precise: they cost 0, 60 and 180 XP.

What you learn

Objectives complete themselves while you work in the terminal; each one is worth experience points:

  • Find the suspicious visitor's token in the log (100 XP)
  • Isolate a part of the token with cut (100 XP)
  • Bring the URL-safe alphabet back to normal base64 (150 XP)
  • Decode the token's payload (150 XP)

Topics: codici, jwt, base64url, sessioni.

Commands you will use

The terminal is simulated and understands about forty Linux commands. In this lab you will mostly need these:

  • cat: prints the contents of a file: the most direct way to read configurations, notes and logs.
  • grep: finds the lines that contain a word, even across whole folders with -r. It is the main tool for analysing text and logs.
  • cut: extracts one column from each line using a chosen separator, to isolate a specific field of a log.
  • tr: replaces characters with others: with the right rules it applies or undoes ROT13.
  • base64: encodes and decodes Base64, the format that turns bytes into text. It protects nothing: it can be undone without a key.
  • xxd: shows a file in hexadecimal and can also turn hexadecimal back into text.
  • |: the vertical bar | chains commands: the output of the first becomes the input of the next, so small tools form a complete analysis.

The simulated environment

You work in a simulated Linux shell, in the home folder of the user runner: invented files and folders, no network target.

The defensive lesson

Once the lab is solved, the write-up explains what went wrong and how to protect yourself:

A JWT is made of three parts (header, payload and signature) in base64url: reading the header and the payload needs no key, because they are only encoded, not encrypted. The signature guarantees that the content was not altered, not that it is secret. Here the programmer had left a debug key in the payload and the header declared alg none, that is no signature: a server that accepts these tokens recognizes anyone as an administrator. Defense: never put secrets in the contents of a token; accept only the algorithms you expect (never none) and always verify signature and expiry; short-lived tokens; cookies with HttpOnly and Secure; and revoke suspicious sessions at once.

Before and after this lab

To unlock it you must have solved:

After this lab you can move on to:

The Encodings & secrets path

Encodings & secrets teaches a distinction that saves a lot of data: encoding is not encrypting. Base64, hexadecimal, ROT13 and mirrored text change how information looks but do not protect it, because anyone can turn it back into plain text without a key. In the labs you recognise these formats by their look, peel them off one layer at a time even when they are stacked, extract readable text from a compiled program and understand why real protection needs real encryption, salted hashes and a secrets manager.

All labs in the Encodings & secrets path

Learn more with the guides

All guides