spbctf_3_x86_64
spbctf_3_x86_64
Platform: CUSTOM | Category: Reversing | Type: Challenge | Difficulty: Easy | OS: N/A | **Author: XESXOR Techniques: objdump_disassembly, shuffle_algorithm_reversal, static_analysis, swap_operation_analysis
Summary
Walkthrough of the CUSTOM Reversing spbctf_3_x86_64. Task: ELF64 binary encodes strings using iterative swap operations with decreasing step sizes. Solution: Reverse the swap algorithm by applying same operations in reverse order (increasing steps 2-10)
Description
ELF64 binary that encodes a string given as command line argument using a series of swap operations. Given the encoded string
_A_m_aFneSuyn_w_IypvSr_ahIEwp_gitrnMhaetevT_so!, find the original string.
ELF64 binary that takes a string as command line argument and encodes it using a custom swap-based permutation algorithm. The goal is to reverse the encoding to recover the original flag.
Analysis
Disassembled the binary with objdump. Found two key functions:
-
swaper(string, step)- The core encoding function that iteratesifrom 0 tolen(s) - stepwith stepstep, swappings[i]withs[i + step - 1]at each iteration. -
main- Callsswaperwith decreasing step sizes: 10, 9, 8, 7, 6, 5, 4, 3, 2.
The encoding is a series of permutations applied to the string. Each call to swaper with a different step size performs a specific pattern of character swaps.
Solution
To reverse the encoding, apply the same swap operations in reverse order — using increasing step sizes from 2 to 10 instead of decreasing from 10 to 2.
python read-only • copy allowed#!/usr/bin/env python3 # Reverse the swaper encoding by applying swaps in reverse order encoded = '_A_m_aFneSuyn_w_IypvSr_ahIEwp_gitrnMhaetevT_so!' s = list(encoded) # Original encoding: steps 10, 9, 8, 7, 6, 5, 4, 3, 2 (decreasing) # To reverse: steps 2, 3, 4, 5, 6, 7, 8, 9, 10 (increasing) for step in range(2, 11): for i in range(0, len(s) - step, step): s[i], s[i + step - 1] = s[i + step - 1], s[i] print(''.join(s)) # REDACTED
The key insight is that swap operations are self-inverse — applying the same swap twice returns to the original state. However, when multiple swaps are chained, the order matters. To undo the sequence of operations, we must apply them in reverse order.
Key Takeaways / Lessons
- Mastering objdump_disassembly, shuffle_algorithm_reversal, static_analysis, swap_operation_analysis was key to this challenge.
- Always check for common misconfigurations and verify assumptions.
Crafted by XESXOR Research • 2026-03-25 • CUSTOM • spbctf_3_x86_64 • Difficulty: Easy