Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sexfrance/v8-randomness-predictor

A Python-based predictor using z3 to reverse-engineer and predict random values generated by Math.random in V8 with 100% accuracy. This script leverages a series of Math.random() values (min 5) to deduce future states.
https://github.com/sexfrance/v8-randomness-predictor

algorithm javascript math-random nodejs number-generation predictor python randomness-prediction reverse-algorithms reverse-engineering security-analysis v8 v8-engine xorshift z3-solver

Last synced: about 2 months ago
JSON representation

A Python-based predictor using z3 to reverse-engineer and predict random values generated by Math.random in V8 with 100% accuracy. This script leverages a series of Math.random() values (min 5) to deduce future states.

Awesome Lists containing this project

README

        



V8 Randomness Predictor



A Python-based predictor using z3 to reverse-engineer and predict random values generated by Math.random in V8 with 100% accuracy. This script leverages a series of Math.random() values (min 5) to deduce future states.




๐Ÿ’ฌ Discord
ยท
๐Ÿ“œ ChangeLog
ยท
โš ๏ธ Report Bug
ยท
๐Ÿ’ก Request Feature


---

### โš™๏ธ Installation

- Requires: `Python 3.8+`
- Set up a virtual environment:
```bash
python3 -m venv venv
```
- Activate the environment:
```bash
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
```
- Install requirements:
```bash
pip install -r requirements.txt
```
- Install [nodejs](https://nodejs.org/) (optional)

---

### ๐Ÿ”ฅ Features

- **Debug Logging**: Debug logging through `logmagix` that tracks each prediction stage.
- **Z3 Integration**: Uses Z3 to reverse the XORSHIFT+128 algorithm behind `Math.random` in V8.
- **Custom Sequence Input**: Optionally, input your own sequence of `Math.random()` values for testing.
- **Automated Prediction**: Computes the next `Math.random()` output based on previous values.
- **Error Handling**: Verifies the Z3 model's validity and provides detailed feedback.

---

### ๐Ÿ” Usage

1. **Generate Random Numbers**: Use V8 (Node.js, Chrome, etc.) to produce a sequence of random values with `Math.random()`. An example sequence can be generated by running:

```js
Array.from(Array(5), Math.random);
```

Optionally, set a seed in Node.js to reproduce the same random sequence:

```js
node --random_seed=1337
Array.from(Array(5), Math.random)
```

2. **Run the Predictor**: Input the random sequence into the script. For example:

```bash
python main.py --sequence "[0.9311600617849973, 0.3551442693830502, 0.7923158995678377, 0.787777942408997, 0.376372264303491]"
```

Or for testing purposes you can run the python code directly (requires NodeJS):

```bash
python main.py
```

3. **Output Example**:

```plaintext
Using Sequence: [0.376372264303491, 0.787777942408997, 0.7923158995678377, 0.3551442693830502, 0.9311600617849973]
States: {'se_state0': 4268050313212552111, 'se_state1': 6942842836049070467}
Successfully guessed result: 0.23137147109312428
```

---

### ๐Ÿ“น Demo

![Demo](https://i.imgur.com/85yw8di.gif)

---

### ๐Ÿ“œ ChangeLog

```diff
v1.0.0 โ‹ฎ 11/10/2024
! Initial release with Math.random predictor
```

---





**Inspired by**: [PwnFunction](https://github.com/PwnFunction/v8-randomness-predictor)