Skip to content

Instantly share code, notes, and snippets.

@noraj
Last active August 7, 2021 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noraj/46f8ec31205f72a604b13ffa4c03dfbc to your computer and use it in GitHub Desktop.
Save noraj/46f8ec31205f72a604b13ffa4c03dfbc to your computer and use it in GitHub Desktop.
Leave a TryHackMe room

What?

Here is a short JS snippet to leave a room on TryHackMe.

Why?

Context: I joined the room https://tryhackme.com/room/linuxctf a long time ago when it was free but has become VIP-only, so I have it appearing in "My rooms" but cannot do it and since I'm redirected to the VIP subscription page I can't leave it.

How?

New method (new.js)

  1. Go to the page of any room (must be a room).
  2. Replace code value with the room code (look at the URL). Eg. linuxctf for https://tryhackme.com/room/linuxctf.
  3. Run the JS snippet un your browser console (press F12).

Note: a solution inspired by szymex73 better snippet.

Old method (old.js)

Replace _csrf value with an anti-CSRF token from any other room (CTRL + U and look for (CTRL+F) csrfToken), eg:

    const csrfToken = "token-here"
    $.ajaxSetup({ headers: { 'CSRF-Token': csrfToken } }) // all $.post headers include token (needs csrfProtection middleware)

    const roomCode = "ccradare2"
    const simpleRoom = false 
    const ctfRoom = false 
    const events = {"tickets":false}

Replace code value with the room code (look at the URL). Eg. linuxctf for https://tryhackme.com/room/linuxctf.

Run the JS snippet un your browser console (press F12).

fetch('/room/leave', {
method: 'POST',
body: JSON.stringify({
code: 'room-code',
_csrf: csrfToken
}),
headers: {
'Content-Type': 'application/json'
}
});
fetch('https://tryhackme.com/room/leave', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: '_csrf=token-here&code=room-code'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment