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
No build step and no dependencies. Run it from IntelliJ or from a terminal.
IntelliJ
- Right-click the
srcfolder and go to New > Directory. IntelliJ suggests standard source folders: select test/java.
IntelliJ createssrc/test/javaand marks it as a test sources root. The starter project ships onlysrc/main/java, so you add this folder yourself. - Drag
TotpDemo.javainto the newsrc/test/javafolder. - 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.javathen 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
- Load your TOTP extension in Burp (same secret). It registers a session handling action via
api.http().registerSessionHandlingAction(). - Add a session handling rule that invokes it:
- Go to Settings > Sessions > Session handling rules and click Add.
- Under Rule actions, click Add > Invoke a Burp extension and select your action.
- Go to the Scope tab and select Repeater (and set a URL scope).
- 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.
- The server checks
X-TOTP-Codeagainst the current 30-second window (±1 window for clock skew):200 {"status":"granted"}: valid current code401 {"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.