cscg24-adventure

CSCG 2024 Challenge 'Choose Your Own Adventure'
git clone https://git.sinitax.com/sinitax/cscg24-adventure
Log | Files | Refs | sfeed.txt

run.sh (4362B)


      1#!/usr/bin/env zsh
      2
      3echo "Welcome to the Mystical Coin CTF Adventure!"
      4echo "In your bag, you carry a special coin, known for always bring you luck. You've been throwing it repeatedly, lost in thought."
      5echo "After $RANDOM throws, you finally get your most precious sequence:"
      6sleep 1
      7echo ""
      8
      9PASSKEY=""
     10
     11function mystical_coin_flip {
     12    echo "An ancient coin lands in your hand. Will it be heads (H) or tails (T)?"
     13    read "?Your call: " user_call
     14
     15    # Validate input
     16    if ! [[ "$user_call" =~ ^[HhTt]$ ]]; then
     17        echo "Invalid call. Please choose heads (H) or tails (T)."
     18        exit 1
     19    fi
     20
     21    # Simulate a coin flip
     22	VAL=$RANDOM
     23    if (( $VAL % 2 )); then
     24        coin_result="H"
     25    else
     26        coin_result="T"
     27    fi
     28    PASSKEY+=$coin_result
     29    echo "The coin lands on $coin_result."
     30
     31    if [[ ${user_call:u} == ${coin_result:u} ]]; then
     32        echo "Fortune smiles upon you!"
     33        echo ""
     34        return 0
     35    else
     36        echo "Oh no! The coin has other plans..."
     37        echo ""
     38        return 1
     39    fi
     40}
     41
     42mystical_coin_flip
     43mystical_coin_flip
     44mystical_coin_flip
     45mystical_coin_flip
     46mystical_coin_flip
     47
     48echo "Distracted by this particular sequence of flips, you suddenly find yourself at the entrance of an ancient and mystical land."
     49echo "Your destiny in this realm is mysteriously linked to this coin."
     50sleep 1
     51echo ""
     52
     53echo "You stand at a mystical crossroads, with two paths forward: the Portal of Fate (P) or the Oracle's Den (O)."
     54read "?Choose P for the Portal of Fate or O for the Oracle's Den: " choice
     55
     56
     57if [[ $choice == [Pp]* ]]; then
     58    echo "You approach the Portal of Fate, shimmering with ancient energy."
     59    if mystical_coin_flip; then
     60        echo "As the portal swirls open, a radiant light envelops you, transporting you to a realm beyond imagination."
     61        echo "In this realm, you navigate a labyrinth of stars, solve riddles whispered by ancient trees, and unlock a celestial puzzle that aligns the constellations."
     62        echo "At the heart of the realm, you find a crystal dais. Etched upon it in shimmering light is the flag part: 'PART2}'."
     63        echo "A voice, as old as time, echoes around you, 'The journey through the stars is a reflection of the journey within. You have navigated both with wisdom.'"
     64        echo "With a flash of light, you're back at the portal, holding a token from the starry realm as a memento of your adventure."
     65    else
     66        echo "The portal catapults you into space, where you become a human comet, blazing through the cosmos!"
     67        echo "It's a breathtaking sight, but alas, a comet can't collect flag parts."
     68    fi
     69else
     70    echo "You tread cautiously towards the Oracle's Den. The coin is soaring through the air, heading back to your hand."
     71    if mystical_coin_flip; then
     72        echo "The Oracle guides you to a hidden library, a sanctuary of ancient secrets."
     73        echo "Within its silent walls, you discover a curious scroll sealed with a mystic symbol."
     74
     75        for ((i=1; i<=32; i++))
     76        do
     77            PASSKEY=$(echo $PASSKEY$RANDOM | md5sum)
     78			echo "$PASSKEY"
     79        done
     80        export PASSKEY=$PASSKEY
     81		echo "$PASSKEY"
     82        echo "Unfurling the scroll reveals a series of enigmatic symbols and a cryptic cipher:"
     83
     84        echo "CSCG{FLAG_PART_1_" | openssl enc -aes-256-cbc -e -pass env:PASSKEY 2>/dev/null | hexdump -C
     85
     86        echo "The Oracle hints that it's a hexadecimal code, part of a larger puzzle."
     87        echo "She whispers that understanding its meaning requires knowledge found only in the distant lands of your quest."
     88        echo "This cipher, a fragment of your flag, ignites a deeper curiosity, leading you to seek the wisdom needed to unlock its secrets."
     89    else
     90        echo "The Oracle laughs so heartily at your coin call that a gust of wind from her chuckle sweeps you off your feet."
     91        echo "You find yourself blown into a painting, transforming into a permanent, smiling figure in an idyllic landscape within the frame."
     92        echo "As you adjust to your new painted existence, surrounded by serene hills and a peaceful river, you realize that while this painted world is beautiful, it holds no flag parts for your quest."
     93        echo "You become a cherished character in the Oracle's gallery, admired by all who pass by, but your journey for the flag ends in this artistic realm."
     94    fi
     95fi