Diberikan sebuah website static yang hanya menampilkan sebuah text dengan format base64 yang selalu berubah setiap kali di refresh.

Diminta untuk melihat source codenya, dari judul sudah cukup jelas “git”. Dari sana saya mencoba untuk mengakses /.git tetapi error 403 Forbidden, lalu saya mencoba untuk mengakses /.git/config dan ternyata 200 Success. Maka dari itu saya mencoba dump .gitnya menggunakan GitTools.

Setelah itu, mari kita lihat git commit historynya di /.git/refs/heads/master
1 2 3 4 5 6 |
⚡ root@Bryan /mnt/z/!CTF-NEW/digitalOVerdose/gitcommitWEBCHALLENGE/.git/refs/heads git cat-file -p 2756250c7cd2188bdf8c4cdeddc92bcbe13f1755 tree c2c1d8bde15fa2174d6acd1284d7251579b8a1b4 author elliot <macuser@Macs-MacBook-Air.local> 1633254410 +0530 committer elliot <macuser@Macs-MacBook-Air.local> 1633254410 +0530 Committed security suicide |
Nah, disana ada hash dari tree yang bisa kita lihat file/folder apa yang telah di commit
1 2 3 4 5 6 7 8 9 |
✘ ⚡ root@Bryan /mnt/z/!CTF-NEW/digitalOVerdose/gitcommitWEBCHALLENGE/.git/refs/heads git cat-file -p c2c1d8bde15fa2174d6acd1284d7251579b8a1b4 040000 tree 4fbdfd5fda330754872764810dfa2c1ef46f1bb0 Crypt 040000 tree 4979a80a4c88cdbb529b51aa231caff61d9228a0 File 040000 tree 465e79b104f83169a4f95900a6a9f42b34e71892 Math 040000 tree 3a8a916693a0d0acf0320d287318d9ddd123cbe3 Net 040000 tree 072aad170b0a780723ef2c690a3fe4f5e3392830 System 100644 blob 95d5d6fbb14df57d143ec73df6dc00807f85b1db bootstrap.php 100644 blob 0d4096f89f4ea65a44c2a4038b6f931c95c5eba4 index.php 100644 blob 58a1261b18cc493ba5be1c4ef8f04d258716e419 openssl.cnf |
Ini adalah file yang berada di dalam tree tersebut. Untuk itu kita bisa melihat source codenya di index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
<?php /** * Simple sodium crypto class for PHP >= 7.2 * @author MRK */ class crypto { /** * * @return type */ static public function create_encryption_key() { return base64_encode(sodium_crypto_secretbox_keygen()); } /** * Encrypt a message * * @param string $message - message to encrypt * @param string $key - encryption key created using create_encryption_key() * @return string */ static function encrypt($message, $key) { $key_decoded = base64_decode($key); $nonce = random_bytes( SODIUM_CRYPTO_SECRETBOX_NONCEBYTES ); $cipher = base64_encode( $nonce . sodium_crypto_secretbox( $message, $nonce, $key_decoded ) ); sodium_memzero($message); sodium_memzero($key_decoded); return $cipher; } /** * Decrypt a message * @param string $encrypted - message encrypted with safeEncrypt() * @param string $key - key used for encryption * @return string */ static function decrypt($encrypted, $key) { $decoded = base64_decode($encrypted); $key_decoded = base64_decode($key); if ($decoded === false) { throw new Exception('Decryption error : the encoding failed'); } if (mb_strlen($decoded, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) { throw new Exception('Decryption error : the message was truncated'); } $nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); $ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); $plain = sodium_crypto_secretbox_open( $ciphertext, $nonce, $key_decoded ); if ($plain === false) { throw new Exception('Decryption error : the message was tampered with in transit'); } sodium_memzero($ciphertext); sodium_memzero($key_decoded); return $plain; } } $privatekey = "mRHpcEckKATdwDC/CwpRinDTiAYrn9lzWpTo277omKs="; $flag = file_get_contents('../flag.txt'); $enc = crypto::encrypt($flag, $privatekey); echo $enc; ?> <html> <br> Only if you could see the source code. </html># |
Jika dilihat, disini ada sebuah class crypto yang memiliki 2 function yaitu encrypt dan decrypt. Function encrypt bekerja untuk enkripsi sebuah text dengan SODIUM_CRYPTO_SECRET_BOX dengan random nonce serta private key lalu di encode dengan base64. Untungnya private key sudah disediakan, jadi kita tinggal memasukkan text yang ada di website tadi lalu panggil fungsi decrypt untuk mendapatkan flagnya.
1 2 3 4 5 6 7 8 9 |
.... [ Continued ] .... $privatekey = "mRHpcEckKATdwDC/CwpRinDTiAYrn9lzWpTo277omKs="; //$flag = file_get_contents('../flag.txt'); //$enc = crypto::encrypt($flag, $privatekey); $enc = "rPzvhG6NknoE25uTEOXH21ouVYknRPwSGZQ87EVGAGJyWYfCTQ5tZ1NwBM//ERHf1fKZ7o+hbCzZeHsBS2f8y6gFReKvCC/yBb2MShcS"; $flag = crypto::decrypt($enc, $privatekey); //echo $enc; echo $flag; |

Flag: DO{y0u_d1D_1t_19080128123&91823182)}