Hack The Box: Invite Challenge
Tags: security, hackthebox, ctf, cybersecurity
Published: 2021-02-11 10:21:15

[![htb-invitation-chal.png](https://i.postimg.cc/T1QFfX62/htb-invitation-chal.png)](https://postimg.cc/hQzp16vN)

Okay, guys! So I decided that I'll solve Hack The Box challenges but I can't see a signup option. Can you? So that what brings you here. Oh but I do see *invite challenge* and we need to solve it in order to make an account. Basically, it's a test to check whether you can worthy to have an account on this site 😂. Alright, jokes apart, and let's jump into it.

## Breaking In

So it says *hack this page to get invite code*. Sure! one and the only thing that comes to my mind is Developer tools. Let's open it up.

[![invitation-console.png](https://i.postimg.cc/SQGwWcM0/invitation-console.png)](https://postimg.cc/Yjhn7GR8)

Ah! and here we have a big skull trying to tell us something. So there is an **interesting JavaScript file** which we need to find. Let's have a look at the network panel and filter out **JS** files.

[![invitation-network-tool.png](https://i.postimg.cc/y8Dt45rB/invitation-network-tool.png)](https://postimg.cc/G41qvMCS)

The name of the file is eye-catching, **inviteapi.min.js**. Feels like this file has something to do with the invitation code. Let's open it up and it's minified/obfuscated (it's unreadable). You must be thinking, *"then how do we understand what's it doing?"*. Here is the answer:

![dev tool](http://www.quickmeme.com/img/12/126260c064247664d64234d222af9dbe5b70ab89c5b1d989e6a0fa1ffc5f2673.jpg)

and I'll set the breakpoint at **line 24**. Why? because it is returning some value and possibly it can be the invitation code. Now after setting the breakpoint refresh the page and you'll see the return value as shown below.

[![invitation-debug.png](https://i.postimg.cc/KYLW4T2H/invitation-debug.png)](https://postimg.cc/CZh7QzdG)

Oops! looks like I was wrong 😖. This code returns a function rather than an invitation code but the name of the function sounds as if it generates the invitation code. Let's call the function in the console.

```js
makeInviteCode()
```

[![invitation-mic.png](https://i.postimg.cc/CLL9JdGR/invitation-mic.png)](https://postimg.cc/PN965XFH)

and here we have something. Oh, it's an encrypted string, and notice it also mentions the algorithm it's encrypted with: **ROT13**. Head over to [rot13.com](http://rot13.com) and decrypt it.

[![invitation-level-1.png](https://i.postimg.cc/vHqkKMh3/invitation-level-1.png)](https://postimg.cc/svWTBkth)

So it turns out this is also not the invitation code. Decrypted string says that we need to make a *POST* request to `/api/invite/generate`. Let's do it using the `fetch()` API.

```js
fetch('/api/invite/generate',{
    method: "POST"
})
.then(response=>response.json())
.then(data=>console.log(data))
```

and we get following result:

[![invitation-final.png](https://i.postimg.cc/sgb8VctW/invitation-final.png)](https://postimg.cc/dhmn68QQ)

okay, so we got another object as a response. Here we can see some string. Ah! this is the invitation code or is it? Notice object also has a key `format=encoded` which indicates this string is encoded, possibly **base64**. Let's give it a try.

You can use any online **base64** decoder or use the function `atob()` right in your console to decode the base64 string.

Now the final result looks like an invitation code.

It was fun and I think it is a clever idea as well to implement such a challenge right at the login. Anyways this is the end of this post. See you on the other end.



> "A man who flies from his fear may find that he has only taken a shortcut to meet it."  -Sador, Children of Húrin