<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BaconPotatoCat</title>
    <description>The latest articles on DEV Community by BaconPotatoCat (@baconpotatocat).</description>
    <link>https://dev.to/baconpotatocat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F535831%2F66d71d72-b39b-4a61-a494-9619ea08353d.jpg</url>
      <title>DEV Community: BaconPotatoCat</title>
      <link>https://dev.to/baconpotatocat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baconpotatocat"/>
    <language>en</language>
    <item>
      <title>[Stacks 2020 CTF] Unlock Me - Web</title>
      <dc:creator>BaconPotatoCat</dc:creator>
      <pubDate>Wed, 09 Dec 2020 16:19:39 +0000</pubDate>
      <link>https://dev.to/baconpotatocat/stacks-2020-ctf-unlock-me-web-27bj</link>
      <guid>https://dev.to/baconpotatocat/stacks-2020-ctf-unlock-me-web-27bj</guid>
      <description>&lt;h2&gt;
  
  
  &lt;u&gt;Challenge Text&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fchallenge_text.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fchallenge_text.png%3Fraw%3Dtrue" alt="challenge text"&gt;&lt;/a&gt;&lt;/p&gt;
Unlock Me - Challenge Text


&lt;h2&gt;
  
  
  &lt;u&gt;Introduction&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;This is the write-up for the Unlock Me Web Challenge from the team &lt;strong&gt;Ov3rWr1t3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Unlock Me was a 1000 point challenge. Credentials were provided right off the bat, along with a login page with the URL of &lt;code&gt;http://yhi8bpzolrog3yw17fe0wlwrnwllnhic.alttablabs.sg:41031/&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;u&gt;Solution&lt;/u&gt;
&lt;/h2&gt;
&lt;h5&gt;
  
  
  Initial login attempt
&lt;/h5&gt;

&lt;p&gt;Right away, we attempted to login to the panel with the given credentials to see what would happen. We were greeted with the following message.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Ffailed_login.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Ffailed_login.png%3Fraw%3Dtrue" alt="failed_login"&gt;&lt;/a&gt;&lt;/p&gt;
Failed login message



&lt;p&gt;&lt;em&gt;Ah&lt;/em&gt;, it seems that there is Role Based Access Control of some sorts being implemented on the login API. Perhaps we could get more information by intercepting the request on Burpsuite?&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fburp_intercept_1.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fburp_intercept_1.png%3Fraw%3Dtrue" alt="burp_intercept_1"&gt;&lt;/a&gt;&lt;/p&gt;
Successful Login Response



&lt;p&gt;How &lt;em&gt;interesting&lt;/em&gt;. An authorization header with a Bearer token? This indicates the usage of JWTs.&lt;/p&gt;
&lt;h5&gt;
  
  
  JSON Web Tokens (JWTs)
&lt;/h5&gt;

&lt;p&gt;For those who are not familiar with the concept of JWTs, here's a quick run-through. For a more detailed explanation on JWTs, you may visit this &lt;a href="https://jwt.io/introduction/" rel="noopener noreferrer"&gt;page&lt;/a&gt;, which goes into much more depth. JWTs are a compact and self-contained method to transmit JSON objects between parties, such as a client and server. &lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_Diagram.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_Diagram.png%3Fraw%3Dtrue" alt="JWT_Diagram"&gt;&lt;/a&gt;&lt;/p&gt;
Illustration of JWT



&lt;p&gt;When you successfully login to a Web Application, the server will generate a JWT for that specific login session and send it to the client in the Response. The server does so by setting a header, known as the authorization header, with the word "Bearer" concatenated with the value of the JWT. &lt;/p&gt;

&lt;p&gt;From this point on, everytime the client requests access to any resource on the server, the request must contain this authorization header containing the JWT. Otherwise, access will be denied to the client. However, like in this case, simply having a valid JWT may not be enough to be granted access to a resource.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_Claims.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_Claims.png%3Fraw%3Dtrue" alt="JWT_Claims"&gt;&lt;/a&gt;&lt;/p&gt;
Illustration of Client/Server communication with JWTs



&lt;p&gt;JWTs contain something known as "claims". Claims are basically a key/value pair that is contained within the payload of JWT. JWTs are typically not encrypted, and are simply in &lt;code&gt;base64&lt;/code&gt;, allowing us to easily read what's inside any typical JWT we receive. Encryption is not really a concern because any sensitive data are not supposed to be stored within a JWT in the first place. Additionally, JWTs contain a &lt;strong&gt;Signature&lt;/strong&gt;, and any modifications made to a JWT will invalidate it, which will cause the server to reject it.&lt;/p&gt;

&lt;p&gt;The JWT that we received from the server can be seen to have a claim for the user's role. We can therefore infer that this value is what they use to perform their Role Based Access Control. It is clear that we need to modify this claim and somehow get the server to still think that the Signature is valid.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_decoded.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_decoded.png%3Fraw%3Dtrue" alt="JWT_Decoded"&gt;&lt;/a&gt;&lt;/p&gt;
Contents of the JWT received from the login page of the Challenge



&lt;p&gt;If we simply modify the JWT, the Signature will be invalidated.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_Signature.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2FJWT_Signature.png%3Fraw%3Dtrue" alt="JWT_Signature"&gt;&lt;/a&gt;&lt;/p&gt;
Contents of the JWT received from the login page of the Challenge


&lt;h5&gt;
  
  
  Vulnerability
&lt;/h5&gt;

&lt;p&gt;We decided to try inspecting the element of the login page, and noticed this little gem.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Flogin_element.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Flogin_element.png%3Fraw%3Dtrue" alt="login_element"&gt;&lt;/a&gt;&lt;/p&gt;
Comment within the body of the page



&lt;p&gt;This was surely a hint. Alright, so now we know the vulnerability had something to do with the Public Key used to sign the JWT. This led to us wondering; How do we get the Public Key? An idea popped into our heads; What if we just tried to access the resource directly on the website? We entered &lt;code&gt;http://yhi8bpzolrog3yw17fe0wlwrnwllnhic.alttablabs.sg:41031/public.pem&lt;/code&gt; and promptly received a download for their public key.&lt;/p&gt;

&lt;p&gt;Now we had the key, but we still had no idea what to do with it. After doing some research, we discovered that JWTs indeed had a few vulnerabilities that could be exploited. More specifically, we would be exploiting the signing algorithm defined in the header. Notice how the JWT we decoded from the login page shows that RS256 was used to sign it.&lt;/p&gt;

&lt;p&gt;RS256 utilizes RSA with SHA-256 to sign the token. Typically, the signing (encryption) is done by using the &lt;strong&gt;Private Key&lt;/strong&gt; of the server, while the verification (decryption) of the JWT is done by using the &lt;strong&gt;Public Key&lt;/strong&gt; of the server. Meanwhile, another algorithm supported by JWT, known as HS256, utilizes HMAC with SHA-256 to sign the JWT. The main difference is that HS256 uses &lt;strong&gt;Symmetric Key Encryption&lt;/strong&gt;. This means that both its signing and verification are done with one single key. This will be the key to the exploit.&lt;/p&gt;

&lt;p&gt;If the server does not check what algorithm was used to initially sign the JWT, another algorithm can be specified for the server to use when verifying it. Therefore, if we change the algorithm in the header to HS256, the server will attempt to &lt;strong&gt;use its Private Key to verify the JWT instead of using its Public Key&lt;/strong&gt;. This is because the server signed the JWT with its Private Key, and since it believes the algorithm was HS256, it will use the same key to verify the JWT.&lt;/p&gt;

&lt;p&gt;All we have to do is create a token and sign it with the Public Key that we received earlier from the server.&lt;/p&gt;
&lt;h5&gt;
  
  
  Exploit
&lt;/h5&gt;

&lt;p&gt;We found a video explaining and showcasing the exploit and made the following Python Script to generate our forged token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hmac&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;public.pem&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;pubkey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;alg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HS256&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;minion&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;admin&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;iat&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: 1607098377}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;headerBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlsafe_b64encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;encodedHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;headerBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;payloadBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlsafe_b64encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;encodedPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payloadBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encodedHeader&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;encodedPayload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlsafe_b64encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hmac&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pubkey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;UTF-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;UTF-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;signature&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that, we ran the script and obtained our forged JWT.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fforged_jwt.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fforged_jwt.png%3Fraw%3Dtrue" alt="forged_jwt"&gt;&lt;/a&gt;&lt;/p&gt;
Forged JWT



&lt;p&gt;We used Burpsuite to set this as our JWT in the Response received from the login page.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fburp_intercept_2.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fburp_intercept_2.png%3Fraw%3Dtrue" alt="burp_intercept_2"&gt;&lt;/a&gt;&lt;/p&gt;
Intercepted Response from the login page with the newly forged JWT



&lt;p&gt;&lt;em&gt;Voilà&lt;/em&gt;, we have successfully logged in and received the flag, &lt;code&gt;govtech-csg{5!gN_0F_+h3_T!m3S}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fsuccessful_login.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FBaconPotatoCat%2Fstacks2020-UnlockMe%2Fblob%2Fmain%2Fimg%2Fsuccessful_login.png%3Fraw%3Dtrue" alt="successful_login"&gt;&lt;/a&gt;&lt;/p&gt;
Successfully logged in and received the flag



&lt;h2&gt;
  
  
  &lt;u&gt;Conclusion&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;JWTs may be a basic concept to those with experience in the Web Industry, and this challenge may seem easy, but it took us hours of thinking, experimenting, researching, and &lt;em&gt;maybe&lt;/em&gt; some whisky, to crack. Overall, it was a really fun and interesting experience! The &lt;em&gt;satisfaction&lt;/em&gt; of completing a challenge that you took hours to solve is hard to beat.&lt;/p&gt;

&lt;p&gt;If you found the challenge to be...well...&lt;em&gt;challenging&lt;/em&gt;, don't worry, we did too. Everyone starts from somewhere, and each time you fail, you learn something new. Participating in more CTFs and similar events help expose you to many things you would never have known or seen, as well as occasionally introducing you to some great new tools!&lt;/p&gt;

&lt;p&gt;The point is, don't give up, and you'll reach your goals one day! I hope you enjoyed reading this write up and found it to be informative and well-written.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Resources&lt;/u&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jwt.io/introduction/" rel="noopener noreferrer"&gt;Introduction to JSON Web Tokens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/" rel="noopener noreferrer"&gt;Critical vulnerabilities in JSON Web Token libraries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/IYZeVdXeUro" rel="noopener noreferrer"&gt;How to Exploit "Json Web Token"(JWT) vulnerabilities | Full Practical&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By &lt;em&gt;Bacon Potato Cat&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
      <category>ctf</category>
      <category>jwt</category>
    </item>
  </channel>
</rss>
