Websec

Websec.fr Level 17
The code for level17 is here. <?php include "flag.php"; function sleep_rand() { /* I wish php5 had random_int() */ $range = 100000; $bytes = (int) (log($range, 2) / 8) + 1; do { /* Side effect: more random cpu cycles wasted ;) */ $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes))); } while ($rnd >= $range); usleep($rnd); } ?> <!DOCTYPE html> <html> ....... <?php if (isset ($_POST['flag'])): sleep_rand(); /* This makes timing-attack impractical. */ ?
websec
Websec.fr Level 08
The source code of level8 is here. <?php $uploadedFile = sprintf('%1$s/%2$s', '/uploads', sha1($_FILES['fileToUpload']['name']) . '.gif'); if (file_exists ($uploadedFile)) { unlink ($uploadedFile); } if ($_FILES['fileToUpload']['size'] <= 50000) { if (getimagesize ($_FILES['fileToUpload']['tmp_name']) !== false) { if (exif_imagetype($_FILES['fileToUpload']['tmp_name']) === IMAGETYPE_GIF) { move_uploaded_file ($_FILES['fileToUpload']['tmp_name'], $uploadedFile); echo '<p class="lead">Dump of <a href="/level08' . $uploadedFile . '">'. htmlentities($_FILES['fileToUpload']['name']) . '</a>:</p>'; echo '<pre>'; include_once($uploadedFile); echo '</pre>'; unlink($uploadedFile); } else { echo '<p class="text-danger">The file is not a GIF</p>'; } } else { echo '<p class="text-danger">The file is not an image</p>'; } } else { echo '<p class="text-danger">The file is too big</p>'; } ?
websec file-upload
Websec.fr Level 04
For the Level Four challenge, there are two sources: here and here. Only the PHP code is shown here because the HTML is not important. source1.php <?php include 'connect.php'; $sql = new SQL(); $sql->connect(); $sql->query = 'SELECT username FROM users WHERE id='; if (isset ($_COOKIE['leet_hax0r'])) { $sess_data = unserialize (base64 _decode ($_COOKIE['leet_hax0r'])); try { if (is_array($sess_data) && $sess_data['ip'] != $_SERVER['REMOTE_ADDR']) { die('CANT HACK US!!!'); } } catch(Exception $e) { echo $e; } } else { $cookie = base64_encode (serialize (array ( 'ip' => $_SERVER['REMOTE_ADDR']))) ; setcookie ('leet_hax0r', $cookie, time () + (86400 * 30)); } if (isset ($_REQUEST['id']) && is_numeric ($_REQUEST['id'])) { try { $sql->query .
websec insecure-deserialization
Websec.fr Level 02
The source code for level2 is here. <?php ini_set('display_errors', 'on'); class LevelTwo { public function doQuery($injection) { $pdo = new SQLite3('leveltwo.db', SQLITE3_OPEN_READONLY); $searchWords = implode (['union', 'order', 'select', 'from', 'group', 'by'], '|'); $injection = preg_replace ('/' . $searchWords . '/i', '', $injection); $query = 'SELECT id,username FROM users WHERE id=' . $injection . ' LIMIT 1'; $getUsers = $pdo->query ($query); $users = $getUsers->fetchArray (SQLITE3_ASSOC); if ($users) { return $users; } return false; } } if (isset ($_POST['submit']) && isset ($_POST['user_id'])) { $lt = new LevelTwo (); $userDetails = $lt->doQuery ($_POST['user_id']); } ?
websec sqli
Websec.fr Level 01
Websec.fr Level 1 level01 - 1 point - 2564 solves The source code for level1 is shown here. Only the PHP code is included because the vulnerability is only in the PHP code. <?php session_start (); ini_set('display_errors', 'on'); ini_set('error_reporting', E_ALL); include 'anti_csrf.php'; init_token (); class LevelOne { public function doQuery($injection) { $pdo = new SQLite3('database.db', SQLITE3_OPEN_READONLY); $query = 'SELECT id,username FROM users WHERE id=' . $injection . ' LIMIT 1'; $getUsers = $pdo->query($query); $users = $getUsers->fetchArray(SQLITE3_ASSOC); if ($users) { return $users; } return false; } } if (isset ($_POST['submit']) && isset ($_POST['user_id'])) { check_and_refresh_token(); $lo = new LevelOne (); $userDetails = $lo->doQuery ($_POST['user_id']); } ?
websec sqli

Tedsig42

Another infosec enthusiast blog