TOTP demo server

Target for Exercise C: Session handling. The server guards /login/totp with a valid, current time-based one-time password (TOTP) code, so you can’t replay a captured code. Your extension solves this by injecting a fresh code on every request.

We preconfigured the server to match the walkthrough:

  • Secret: JBSWY3DPEHPK3PXP (Base32).
  • Path: /login/totp.
  • Header: X-TOTP-Code.

Run

Download TotpDemo.java

No build step and no dependencies. Run it from IntelliJ or from a terminal.

IntelliJ

  1. Right-click the src folder and go to New > Directory. IntelliJ suggests standard source folders: select test/java.
    IntelliJ creates src/test/java and marks it as a test sources root. The starter project ships only src/main/java, so you add this folder yourself.
  2. Drag TotpDemo.java into the new src/test/java folder.
  3. Click the green Run arrow in the gutter next to main, or right-click the file and click Run ‘TotpDemo.main()’.

IntelliJ runs the file with the project SDK. Keeping it in src/test/java also keeps it out of your extension JAR. Stop it with the red Stop button.

Terminal

You need a JDK 21 or later on your PATH:

java TotpDemo.java        # http://localhost:8888
java TotpDemo.java 9000   # custom port

Stop with Ctrl+C.

Note: If you let IntelliJ download the JDK for you (File > Project Structure > SDK > Download JDK), that JDK is not on your terminal’s PATH. Running java TotpDemo.java then fails with a “command not found” error. Run it from IntelliJ instead, or install a standalone JDK 21.

Endpoints

Path Content-Type Purpose
/ text/html Index describing the demo (browse to fill proxy history)
/login/totp application/json Protected endpoint. Needs a current X-TOTP-Code header; returns 200 granted or 401 denied

Use with Burp

  1. Load your TOTP extension in Burp (same secret). It registers a session handling action via api.http().registerSessionHandlingAction().
  2. Add a session handling rule that invokes it:
    1. Go to Settings > Sessions > Session handling rules and click Add.
    2. Under Rule actions, click Add > Invoke a Burp extension and select your action.
    3. Go to the Scope tab and select Repeater (and set a URL scope).
  3. Send a request to http://localhost:8888/login/totp from Repeater. Don’t add the header yourself. The rule invokes your action, which injects it.
  4. The server checks X-TOTP-Code against the current 30-second window (±1 window for clock skew):
    • 200 {"status":"granted"}: valid current code
    • 401 {"status":"denied"}: missing, stale, or wrong

The server console prints the received code, expected code, and verdict for every request. Because the action regenerates on every send, re-sending after 30 seconds succeeds, whereas a captured static code would not.