---
title: "SECCON Beginners CTF 2024 Participation Report (+ miniWriteup)"
author: "taksas"
language: "en"
direction: "ltr"
published: "2024-06-16 16:39:34"
updated: "2024-06-16 16:40:37"
canonical_html: "https://taksas.net/en/archives/1260"
original_html: "https://taksas.net/archives/1260"
auto_translated: true
categories: ["blog"]
---

# SECCON Beginners CTF 2024 Participation Report (+ miniWriteup)

> **Machine Translation (English)**: Automatically translated from the original Japanese document: [https://taksas.net/archives/1260](https://taksas.net/archives/1260)

A Blog category topic for the first time in a while.

[![](https://taksas.net/wp-content/uploads/2024/06/ctf4b_1-1024x576.png)](https://taksas.net/wp-content/uploads/2024/06/ctf4b_1.png)

[![](https://taksas.net/wp-content/uploads/2024/06/ctf4b_2-1024x576.png)](https://taksas.net/wp-content/uploads/2024/06/ctf4b_2.png)

I am happy that I solved it with great balance and that I was able to solve my first crypto problem.

## Safe Prime (crypto) {#safe-prime-crypto}

A problem exploiting a vulnerability in RSA encryption.

Ricerca Security's[this article](https://ricercasecurity.blogspot.com/2023/06/ricerca-ctf-2023-writeup-crypto.html)was very helpful.

The following formula is particularly useful. It summarizes in one line that if c, e, p, q, and n are known, the original m can be calculated.

```python
print(long_to_bytes(pow(c, pow(e, -1, (p - 1) * (   (2*p + 1)    - 1)), n)).decode())
```

Since c, e, and n are provided as part of the problem, I have to do something about p and q.

p is 512 bits and q is 2*p+1, so brute-forcing is impossible, which seems to be what guarantees the strength of RSA encryption.

As for the solution, I focused on the relationship between p and q. If you can pull out the quadratic formula, you realize that p and q can actually be derived quite easily.

[![](https://taksas.net/wp-content/uploads/2024/06/2024-06-16_15-58-42_000-1-1024x767.jpg)](https://taksas.net/wp-content/uploads/2024/06/2024-06-16_15-58-42_000-1.jpg)

With that, m can be derived with negligible computational complexity.

## getRank (misc) {#getrank-misc}

A game where you receive a flag as a reward for hitting the 1st place system score.

Since I don't have time to play the game properly, first and foremost, I will make it so that I can send just the score directly to the score server.

The structure of the game's rank check button is like this ↓

```text
<button onclick="getRank()" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
        Get Rank
      </button>
```

It appears that the getRank function is being called. The structure of the getRank function is as follows:

```text
 function getRank() {
        const rankElement = document.getElementById("rank");
        const messageElement = document.getElementById("message");

        fetch("/", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({ input: `${score}` }),
        })
          .then((response) => response.json())
          .then((data) => {
            rankElement.textContent = data.rank ?? "-1";
            messageElement.textContent =
              data.message ?? "Error occurred.";
          })
          .catch((error) => {
            rankElement.textContent = "-1";
            messageElement.textContent = "Error occurred.";
            console.error(error);
          });
      }
```

It is clear that it should work if you POST a JSON with an arbitrarily specified score. I used a Chrome extension client called "Boomerang – SOAP & REST Client".

Next, the score to be sent also needs to be considered.

The current 1st place score is 10 ** 255, and it must be exceeded. Additionally, numbers with 300 or more characters are not accepted.

Furthermore, as seen in the chall function,

```text
if (score > 10 ** 255) {
    // hmm...your score is too big?
    // you need a handicap!
    for (let i = 0; i < 100; i++) {
      score = Math.floor(score / 10);
    }
  }
```

There is a specification where an extreme penalty is automatically applied if the submitted score exceeds 10**255. I mean, what even is that? ()

In other words, one must either bypass the score penalty function or ensure the score still exceeds 10**255 even after the penalty.

The key point here is line 39, the parseInt function.

```text
  let score = parseInt(input);
```

I will take advantage of the fact that the 300-character limit is checked at the string type input stage, while the 10**255 limit is checked after parseInt.

As a specific solution, I will utilize the specifications of parseInt. The specifications are[summarized clearly on](https://chalcedony.hatenablog.com/entry/20140722/1406029797)this site.

By starting the input with "0x", parseInt can also represent hexadecimal numbers. Since the 300-character limit is judged in the hexadecimal state and the 10**255 limit is judged in the decimal state after parseInt, these specifications can be used to bypass the aforementioned limits.

There are numbers that are 300 characters or fewer in hexadecimal and are greater than 10**355 after conversion to decimal. That's it: POST an appropriate hexadecimal number that meets the requirements, and get the flag.

## simpleoverflow (pwnable) {#simpleoverflow-pwnable}

Classic CTF4B.

It is simply a matter of storing 1 in the int-type is_admin variable by utilizing the fact that the read function writes even out of bounds of the array.

It is deeply moving that something that tormented me during my freshman year of university is something I now enjoy.

# Summary {#まとめ}

It is gratifying that there has been progress in crypto, which I was unable to touch at all last year.
