nullcon2023-chall-randrevenge

PHP PRNG prediction challenge for NullCon 2023 Berlin
git clone https://git.sinitax.com/sinitax/nullcon2023-chall-randrevenge
Log | Files | Refs | sfeed.txt

index.php (786B)


      1<?php
      2
      3session_start();
      4
      5function main() {
      6	if ($_SERVER["REQUEST_METHOD"] == "POST"
      7			&& $_SERVER["REQUEST_URI"] == "/submit") {
      8		if (!isset($_SESSION["expiry"])) {
      9			echo "Invalid session!";
     10			return;
     11		}
     12
     13		if (time() > $_SESSION["expiry"]) {
     14			echo "You're too slow!";
     15			return;
     16		}
     17
     18		if (intval($_POST["next"]) != $_SESSION["next"]) {
     19			echo "Wrong prediction!";
     20			return;
     21		}
     22
     23		echo "FLAG " . getenv("FLAG");
     24	} else {
     25		srand(random_int(0, 4294967295));
     26
     27		$t = time();
     28		echo strval($t) . "\n";
     29
     30		echo strval(rand()) . "\n";
     31		for ($i = 0; $i < 300; $i++) {
     32			if (($i % 60) == ($t % 60)) {
     33				echo strval(rand()) . "\n";
     34			} else {
     35				rand();
     36			}
     37		}
     38
     39		$_SESSION["next"] = rand();
     40		$_SESSION["expiry"] = time() + 60;
     41
     42		echo "Good luck :P";
     43	}
     44}
     45
     46main();
     47
     48?>
     49