Climbing the Hacking /mnt/ain

Anthony Schneiter, Miro Haller

Swiss Cyber Storm 2021 · Day 1 · Scenario_1

Overview

This talk, "Climbing the Hacking /mnt/ain," delivered by Miro Haller and Simon Kinhauser at Swiss Cyber Storm, provides a comprehensive look into the journey of the Swiss National Team for Cyber Security Hacking. It details their rigorous selection process, intensive training regimen, and performance at the European Cyber Security Challenge (ECSC) 2021. Beyond the organizational aspects, the presentation delves into the intricate technical details of a real-world Capture The Flag (CTF) challenge, showcasing the advanced skills required to compete at an international level.

Watch on YouTube · Slides

Visual summary for Climbing the Hacking /mnt/ain by Anthony Schneiter, Miro Haller
Visual summary for Climbing the Hacking /mnt/ain by Anthony Schneiter, Miro Haller

Key moments

  1. 1:40 Explaining the European Cyber Security Challenge (ECSC)
  2. 6:00 Intensive CTF training and impressive ranking climb
  3. 9:00 Swiss team's ECSC performance and close competition
  4. 10:00 Simon introduces a binary exploitation challenge walkthrough
  5. 20:00 Exploiting an off-by-one error in heap metadata
  6. 22:00 Leveraging arbitrary write to achieve shell execution

Climbing the Hacking /mnt/ain

Speakers: Miro Haller, Member of Swiss National Team for Cyber Security Hacking; Simon Kinhauser, Member of Swiss National Team for Cyber Security Hacking

Conference: Swiss Cyber Storm

YouTube: https://www.youtube.com/watch?v=WNRhSsbjhy4

Overview

This talk, "Climbing the Hacking /mnt/ain," delivered by Miro Haller and Simon Kinhauser at Swiss Cyber Storm, provides a comprehensive look into the journey of the Swiss National Team for Cyber Security Hacking. It details their rigorous selection process, intensive training regimen, and performance at the European Cyber Security Challenge (ECSC) 2021. Beyond the organizational aspects, the presentation delves into the intricate technical details of a real-world Capture The Flag (CTF) challenge, showcasing the advanced skills required to compete at an international level.

The talk serves a dual purpose: to highlight the importance of nurturing young cybersecurity talent and to demonstrate the practical application of complex exploitation techniques. Miro Haller outlines the structure of the Swiss Hacking Challenge (SHC), the national qualifier for the ECSC, emphasizing the blend of individual skill and crucial teamwork. Simon Kinhauser, stepping in at the last minute, then expertly dissects a challenging binary exploitation scenario involving heap exploitation, providing a deep dive into an off-by-one vulnerability that leads to arbitrary code execution. This presentation is vital for anyone interested in competitive cybersecurity, talent development, or advanced vulnerability exploitation, offering insights into both the strategic and tactical elements of the field.

Background

▶ Watch: Explaining the European Cyber Security Challenge (ECSC) (1:40)

The genesis of this talk lies in the European Cyber Security Challenge (ECSC), an annual international competition designed to promote young cybersecurity talent. With over 20 participating countries, each sending a team of 10 young individuals, the ECSC aims to foster interest and skill development in the cybersecurity industry. In Switzerland, the national selection process is managed by the Swiss Hacking Challenge (SHC), an initiative under the broader umbrella of Swiss Cyber Storm.

The SHC's selection process is multi-phased and designed to identify the most promising young hackers. It begins with an online qualifier in March, hosted as a Capture The Flag (CTF) competition. This initial stage featured 21 diverse challenges across categories such as web security, cryptography, reverse engineering, and Android security. Over 200 individuals registered, with more than 200 successfully solving at least one challenge. From this pool, the top 16 participants, meeting specific age and score criteria, advanced to the second phase.

The second phase emphasized teamwork, grouping the top 16 into teams of four. This decision stemmed from the understanding that success in competitions like the ECSC requires not only individual brilliance but also strong collaborative skills. During this preparation phase, each participant was tasked with developing their own CTF challenge, a crucial learning experience that often reveals unintended solutions and deepens understanding of vulnerability design. The phase culminated in an onsite final, where teams competed against each other in various challenges, including a hardware challenge requiring creative physical solutions and a Bluetooth client development task. The final team of 20 members was selected not solely based on winning teams, but on individual performance, skill diversity (ensuring representation from areas like reverse engineering and pwn), and overall potential.

Following selection, the team underwent an intensive two-month training period. This training primarily involved participating in numerous international CTF competitions online, with some onsite gatherings. This rigorous schedule proved highly effective, propelling the Swiss team to an impressive 3rd place in the Swiss CTF rankings and 86th worldwide within just three months, competing against some of the best teams globally. Beyond the competitive hacking, the team also engaged in team-building activities, including visits to Europa Park and an escape room challenge, to prepare for similar elements within the ECSC.

The ECSC itself spanned five days, with two dedicated to the CTF competition and the remaining days focused on networking and engagement among young cybersecurity enthusiasts. The 2021 edition, held in Prague with 19 participating countries (some impacted by COVID-19), featured an elaborate science fiction theme, complete with a detailed storyline and immersive designs. The Swiss team demonstrated strong initial performance, reaching 4th place six hours before the end, ultimately finishing 11th. This final position, just one challenge away from 7th place, underscored the intense competition and the narrow margins separating top-tier teams.

Key Findings

▶ Watch: Swiss team's ECSC performance and close competition (9:00)

The presentation highlights several significant findings, both in the realm of competitive cybersecurity and the technical intricacies of modern exploitation:

Firstly, the talk underscores the effectiveness of a structured national program like the Swiss Hacking Challenge in identifying, nurturing, and preparing young cybersecurity talent for international competition. The multi-stage selection process, emphasizing both individual skill and crucial teamwork, proved instrumental in assembling a highly capable team. The intensive two-month training, primarily through participation in global CTFs, directly translated into a rapid ascent in international rankings, demonstrating the power of consistent, high-level practice.

Secondly, the performance of the Swiss team at the ECSC, securing 11th place out of 19 countries, while initially strong (4th place for much of the competition), revealed the fiercely competitive nature of elite cybersecurity challenges. The narrow point margins between teams—where solving just one additional challenge could have elevated them significantly—illustrates the high stakes and the demanding technical proficiency required to succeed at this level. This finding emphasizes that even highly trained teams face immense pressure and complex problems that push the boundaries of their skills.

Thirdly, the technical deep dive into the heap exploitation challenge revealed the critical impact of seemingly minor vulnerabilities, specifically an off-by-one error, when combined with a deep understanding of underlying system architectures. The ability to leverage a single byte overwrite to corrupt fundamental heap metadata (prev_size, prev_inuse) and subsequently achieve arbitrary read and write capabilities is a testament to the sophisticated thinking required for advanced exploitation. This demonstrates that robust security requires attention to even the smallest coding flaws.

Finally, the demonstration of the exploitation chain for the binary challenge showcased how modern exploit mitigations like NX enabled (No-Execute) and PIE enabled (Position Independent Executables, a form of ASLR) necessitate multi-stage exploitation. Attackers cannot simply inject and execute shellcode directly. Instead, they must first perform an information leak (e.g., to find the base address of libc), then achieve arbitrary read/write to manipulate control flow, and finally utilize existing code snippets (like a one_gadget) to gain a shell. This highlights the ongoing arms race between defenders implementing mitigations and attackers devising increasingly complex bypass techniques.

Technical Deep Dive

▶ Watch: Simon introduces a binary exploitation challenge walkthrough (10:00)

Simon Kinhauser's segment provided a detailed walkthrough of a binary exploitation challenge, specifically focusing on heap exploitation, which the Swiss team encountered during their training. The challenge involved a console application simulating a CTF environment, allowing users to create, patch, deploy, and take down virtual challenges. The goal was to exploit a vulnerability in this binary to gain shell access and retrieve a flag.

The initial phase of analysis involved static analysis of the provided ELF binary. Tools like checksec were used to identify key security features. The binary was found to be NX enabled, meaning data segments (like the stack and heap) are non-executable, preventing direct shellcode injection. Crucially, it was also PIE enabled, indicating Address Space Layout Randomization (ASLR) was active, randomizing the base addresses of the binary, stack, and heap, thus requiring an information leak to bypass. The binary was also linked against a specific libc version, which is critical for identifying potential gadgets.

For dynamic analysis and deeper inspection, tools like Ghidra (for disassembling and decompiling) and GDB (the GNU Debugger, particularly useful for its heap statistics, showing bins and chunks) were employed. A brief recap of the heap was provided: it's a region of memory for dynamic allocation via malloc and deallocation via free, managed manually without a garbage collector. Mismanagement of these functions is a common source of vulnerabilities. Key heap structures mentioned were the main arena (containing metadata about the heap) and bins (containers for freed chunks of specific sizes, used to speed up reallocation).

The application's interface exposed several functions that manipulated heap memory:

  • make_challenge: Allocates a 60-byte chunk on the heap for a new challenge, storing its category, name, description, and points. Importantly, the description itself is stored at a separate address on the heap, with a pointer to it within the main challenge chunk. This pointer control becomes central to the exploit.
  • patch_challenge: Allows modification of the challenge's description. If an attacker can control the description pointer, this function becomes an arbitrary write primitive.
  • deploy_challenge: Prints the challenge's description. Similarly, if the description pointer is controlled, this becomes an arbitrary read primitive.
  • take_down_challenge: Calls free on a challenge chunk, potentially leading to double-free exploits if not handled carefully.
  • The application also featured a counter that decremented with each action, eventually causing the program to exit, which would later be leveraged for exploit triggering.

The core vulnerability identified was an off-by-one error in the name field during challenge creation. This allowed writing one byte beyond the allocated buffer for the name. While seemingly minor, on the heap, this is critical because heap metadata is often located directly after user-controlled data. Specifically, the overflow allowed overwriting one byte of the subsequent chunk's metadata, including the prev_size and prev_inuse flag.

The exploitation chain unfolded as follows:

  1. Heap Metadata Corruption: The off-by-one error was used to corrupt the prev_size and prev_inuse flag of an adjacent heap chunk. This manipulation tricks the heap allocator into believing that a chunk is free when it is still in use, or that it has a different size than its actual allocation.
  2. Corrupting the Heap Layout: By strategically freeing chunks after metadata corruption, the attacker could trigger a malformed heap state. This leads to an overlapping chunk scenario, where two or more logical chunks occupy the same physical memory region.
  3. Achieving Arbitrary Read/Write via Use-After-Free (UAF): The corrupted heap layout, combined with a use-after-free (UAF) condition (where a freed chunk is reallocated), allowed the attacker to regain control over a previously allocated chunk's memory. By reallocating the freed chunk with a new structure, the attacker could overwrite the description pointer within one of the challenge structures. This effectively transformed the patch_challenge and deploy_challenge functions into arbitrary write and arbitrary read primitives, respectively.
  4. Information Leak: With arbitrary read, the first step was to leak a libc address. This is crucial for bypassing ASLR/PIE. By reading from known offsets within the heap's main arena metadata, which contains pointers to libc functions, the attacker could determine the base address of the loaded libc library.
  5. Identifying Gadgets: Once the libc base address was known, the next step was to find suitable gadgets—short sequences of instructions ending with a ret instruction—that could lead to shell execution. The talk specifically mentioned one_gadget, a powerful tool that, when executed, can directly provide a shell under specific libc states.
  6. Overwriting the Exit Hook: The target for control flow hijacking was the exit hook (specifically dl_tls_tld_unlock_recursive was mentioned, though __free_hook or __malloc_hook are more common targets for libc function pointers). This is a function pointer that gets executed just before the application exits. Using the arbitrary write primitive, the attacker overwrote this pointer with the address of the identified one_gadget.
  7. Triggering Shell Execution: Finally, the attacker triggered the program's exit mechanism (e.g., by decrementing the action counter to a negative value). When the program attempted to exit, it called the now-hijacked exit hook, executing the one_gadget and resulting in immediate shell access. From there, the flag could be catted, completing the challenge.

This detailed breakdown illustrates the multi-stage, sophisticated nature of modern binary exploitation, where understanding memory management, security mitigations, and specific library internals is paramount.

Demo / Proof of Concept

▶ Watch: Exploiting an off-by-one error in heap metadata (20:00)

The entire technical section of the talk, presented by Simon Kinhauser, served as a comprehensive demonstration and proof of concept for solving the described heap exploitation challenge. Rather than a live, interactive demo, the presentation meticulously walked the audience through each step of the exploit, providing visual aids and logical explanations.

The "demo" began with the initial reconnaissance, showing the output of checksec to confirm the presence of NX and PIE mitigations. It then moved to static analysis, illustrating how tools like Ghidra are used to disassemble the binary and understand its functions, such as make_challenge, patch_challenge, deploy_challenge, and take_down_challenge. Screenshots of GDB's heap statistics were shown to explain the concept of bins and chunks and how they appear in memory.

Simon explained the precise mechanism of the off-by-one error in the name field and how it could be used to corrupt the heap metadata of an adjacent chunk, specifically manipulating prev_size and prev_inuse flags. He then detailed how this corruption, combined with subsequent free operations, leads to a corrupted heap layout and the creation of overlapping chunks.

The presentation then elucidated how this heap state enabled a use-after-free (UAF) vulnerability, allowing the attacker to reallocate a previously freed chunk and gain control over the description pointer. This control was then shown to be the key to achieving arbitrary read and write capabilities. The "script" section of the talk highlighted how a Python wrapper could abstract away the tedious console input, simplifying the exploit development process.

Finally, the demonstration culminated in explaining how these primitives were used: first, to perform an information leak by reading from libc addresses on the heap to bypass ASLR/PIE; second, to locate a suitable one_gadget within the leaked libc base; and third, to use the arbitrary write to overwrite the exit hook with the one_gadget's address. The presentation concluded by describing how triggering the program's exit would then execute the one_gadget, granting a shell and allowing the retrieval of the flag. This structured, step-by-step technical explanation effectively served as a detailed proof of concept for the heap exploitation technique.

Defensive Implications

▶ Watch: Leveraging arbitrary write to achieve shell execution (22:00)

The insights from this talk offer several critical lessons for defenders striving to secure systems against advanced threats, particularly those involving binary exploitation and heap manipulation.

Firstly, the core vulnerability, an off-by-one error, highlights the paramount importance of secure coding practices. Developers must be meticulously careful with buffer handling, ensuring that all input is properly validated and that writes never exceed allocated buffer boundaries. This includes using safe string functions (e.g., strncpy with explicit size limits), performing bounds checking on array accesses, and being acutely aware of how even a single byte overflow can have catastrophic consequences, especially in memory-intensive contexts like the heap where metadata is tightly packed. Automated static and dynamic analysis tools can help identify such subtle errors, but manual code review remains invaluable.

Secondly, the talk underscores the ongoing arms race between attackers and defenders concerning exploit mitigations. While NX enabled and ASLR/PIE are standard defenses, they are not impenetrable. Defenders must ensure these mitigations are universally applied and up-to-date across their software stacks. Furthermore, they must recognize that attackers will always seek ways to bypass them, necessitating multi-stage exploitation techniques involving information leaks and arbitrary read/write primitives. This implies that relying solely on these high-level mitigations is insufficient; a layered defense strategy is crucial.

Thirdly, understanding heap exploitation techniques, as demonstrated, is vital for incident response and vulnerability assessment teams. Knowledge of how heap allocators like ptmalloc (used in glibc) work, including concepts like bins, chunks, and metadata, helps in identifying potential attack vectors and understanding exploit primitives like use-after-free (UAF) and heap feng shui. While modern glibc versions have implemented various protections against common heap attacks (e.g., safe unlinking, tcache poisoning checks), new bypasses are continually discovered. Defenders should stay informed about the latest research in heap exploitation and apply relevant patches and updates promptly.

Fourthly, the use of CTF challenges as a training ground for offensive skills also serves as an excellent training ground for defensive professionals. Engaging in or studying solutions to complex CTF problems helps defenders understand attacker methodologies, thought processes, and the specific technical details of vulnerabilities. This hands-on experience can significantly enhance their ability to anticipate attacks, design more robust defenses, and effectively analyze compromises. Organizations should consider incorporating CTF-style training for their security teams to sharpen both offensive and defensive skills.

Finally, the talk implicitly advocates for proactive security measures beyond just patching. This includes adopting memory-safe languages where feasible, implementing sandboxing and privilege separation to limit the impact of successful exploits, and deploying advanced endpoint detection and response (EDR) solutions that can identify anomalous process behavior (e.g., a legitimate application unexpectedly spawning a shell or attempting to modify critical system hooks) that might indicate an ongoing exploitation attempt. Continuous monitoring and threat intelligence are essential to detect and respond to the sophisticated, multi-stage attacks showcased in this presentation.

Key Takeaways

  • The European Cyber Security Challenge (ECSC) and Swiss Hacking Challenge (SHC) are crucial platforms for identifying, training, and promoting young cybersecurity talent, fostering both individual skill and essential teamwork.
  • Competitive Capture The Flag (CTF) events demand a high level of technical proficiency and strategic thinking, where even minor point differences can significantly impact international rankings.
  • Heap exploitation remains a critical vulnerability class, requiring a deep understanding of memory management, allocator internals, and the precise manipulation of heap metadata.
  • Seemingly small vulnerabilities, such as an off-by-one error, can be leveraged to achieve powerful primitives like arbitrary read and write when combined with knowledge of memory layout.
  • Modern exploit mitigations like NX enabled and ASLR/PIE necessitate multi-stage exploitation techniques, including information leaks (e.g., of libc addresses) and the use of gadgets (like one_gadget) to achieve code execution.
  • Defenders must adopt a layered security approach, combining secure coding practices, up-to-date exploit mitigations, continuous vulnerability research, and practical training (including CTFs) to counter sophisticated binary exploitation techniques.

About the Speaker(s)

Miro Haller is a member of the Swiss National Team for Cyber Security Hacking. He presented the first portion of the talk, outlining the Swiss Hacking Challenge's selection, training, and performance at the European Cyber Security Challenge.

Simon Kinhauser is also a member of the Swiss National Team for Cyber Security Hacking. He stepped in at the last minute to deliver the technical deep dive into the heap exploitation challenge, demonstrating his expertise in binary exploitation.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

This is a live CTF write-up glued to a recruitment pitch for the Swiss national hacking team. It's perfectly competent for what it is, but nobody is going to rewrite their threat model because of it. If you want to know how ECSC teams train, or you need a refresher on textbook ptmalloc overlapping chunks, it'll fill an hour just fine.

Heather Calloway (CISO) — SOLID

A detailed walk-through of competitive CTF team building and a deep dive into bypassing ASLR/NX via heap exploitation. While the exploit mechanics are for researchers, the talk serves as a stark reminder of why legacy C and C++ code remains an unmitigated enterprise risk.

→ Top-rated talks at Swiss Cyber Storm 2021

All talks from Swiss Cyber Storm 2021