> For the complete documentation index, see [llms.txt](https://arne-ctf.gitbook.io/ctf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://arne-ctf.gitbook.io/ctf/2023/bucketctf/rev-random-security.md).

# Rev - Random security

Medium | 452 points

## Description

<div align="left"><figure><img src="https://4077916634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9J6tnLQGbY0Or10P4xUT%2Fuploads%2FKPi33Z6EGJFoCU4z1x1J%2Fimage.png?alt=media&amp;token=30abfcc6-8b1a-42f5-830d-cbd6d1907e68" alt=""><figcaption></figcaption></figure></div>

## Solution

<div align="left"><figure><img src="https://4077916634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9J6tnLQGbY0Or10P4xUT%2Fuploads%2FsWlpbstPoHmnUz0Pikna%2Fimage.png?alt=media&amp;token=63c83195-79e9-46c8-bd30-2f625d94b875" alt=""><figcaption><p>Interaction with server</p></figcaption></figure></div>

In this challenge, the server gives us a random number and if we give back a wrong number, it will print **"WRONG DOUBLE!!!!!"**. Also, in the challenge description, the word **Java** is highlighted which suggest that this challenge has something to do with Java randomization.

A quick google search reveals that Java's random is just a linear congruential generator which can be easily cracked. Rather than reinventing the wheel, I will use the code from this Github page: <https://github.com/fta2012/ReplicatedRandom>

The modified Java code:

```java
import java.util.Random;

public class ReplicatedRandomTest {
    public static void main(String args[]) {
        Random r = new Random();
        ReplicatedRandom rr = new ReplicatedRandom();
        rr.replicateState(Double.parseDouble("0.9326890248362221"));
        for (int j = 0; j < 10; j++)
            System.out.println(rr.nextDouble());
        System.out.println();
    }
}
```

The code will predict the next 10 doubles but we will only need the first one.

<div align="left"><figure><img src="https://4077916634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9J6tnLQGbY0Or10P4xUT%2Fuploads%2Fx2alSAUugoFE41NPgFo1%2Fimage.png?alt=media&amp;token=871e0857-7ac2-4ab2-b3aa-6b3b1eab0c74" alt=""><figcaption><p>Predicted number</p></figcaption></figure></div>

Flag: `bucket{RaNd0m_nUmb3r5_53cur3_d24d8c961}`
