Reverse Engineering Sherlock Holmes Style: Obfuscated APIs & The Art of Deduction.

Katie Deakin-Sharpe (Malware Analyst · Australian Cyber Security Center)

BSides Canberra VIII (2025) · Day 2 · Main Track

Overview

In "Reverse Engineering Sherlock Holmes Style: Obfuscated APIs & The Art of Deduction," Katie Deakin-Sharpe, a malware analyst at the Australian Cyber Security Center (ACSC), guides the audience through her methodical process of dissecting a particularly challenging malware sample dubbed "TCP Listener." This talk delves into a novel API obfuscation technique that prevented traditional static and dynamic analysis, forcing a creative, deduction-based approach to uncover its full functionality.

Watch on YouTube

Visual summary for Reverse Engineering Sherlock Holmes Style: Obfuscated APIs & The Art of Deduction. by Katie Deakin-Sharpe
Visual summary for Reverse Engineering Sherlock Holmes Style: Obfuscated APIs & The Art of Deduction. by Katie Deakin-Sharpe

Key moments

  1. 0:00 Introduction to TCP listener and unique API obfuscation
  2. 4:30 The core problem: C2 sends obfuscated API names
  3. 6:15 Applying Sherlock Holmes' deduction to reverse engineer APIs
  4. 27:50 Using Yara to search MSDN for APIs by parameter count
  5. 32:50 Resolving the last API and finding a developer's mistake
  6. 44:50 Q&A: What data would have most helped the analysis
  7. 51:50 Q&A: Why generative AI failed for API lookup

Reverse Engineering Sherlock Holmes Style: Obfuscated APIs & The Art of Deduction.

Speakers: Katie Deakin-Sharpe, Malware Analyst, Australian Cyber Security Center

Conference: BSides Canberra

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

Overview

In "Reverse Engineering Sherlock Holmes Style: Obfuscated APIs & The Art of Deduction," Katie Deakin-Sharpe, a malware analyst at the Australian Cyber Security Center (ACSC), guides the audience through her methodical process of dissecting a particularly challenging malware sample dubbed "TCP Listener." This talk delves into a novel API obfuscation technique that prevented traditional static and dynamic analysis, forcing a creative, deduction-based approach to uncover its full functionality.

The core of the challenge lay in the fact that the malware did not embed the names of the Windows APIs it intended to use within its binary. Instead, these obfuscated API names were dynamically delivered by the Command and Control (C2) server as part of its tasking payloads. This presentation is a masterclass in persistent, analytical reverse engineering, demonstrating how to unravel complex malware when conventional tools and techniques fall short, emphasizing the critical role of human ingenuity and deep technical understanding in the face of advanced threats.

Deakin-Sharpe's work is crucial for defending Australian critical infrastructure, industry, and government. By sharing her "Sherlock Holmes style" methodology, she provides valuable insights into overcoming sophisticated obfuscation, ultimately enabling incident response teams to better understand and mitigate the impact of such compromises. The talk underscores the ongoing cat-and-mouse game between malware developers and analysts, highlighting the constant need for adaptable and innovative defensive strategies.

Background

▶ Watch: Introduction to TCP listener and unique API obfuscation (0:00)

Malware analysis at the Australian Cyber Security Center (ACSC), part of the Australian Signals Directorate (ASD), focuses on several key objectives. Analysts like Katie Deakin-Sharpe aim to identify if a sample belongs to a known malware family or is entirely new, ascertain its full functionality on a compromised network, understand its communication mechanisms, extract intelligence such as C2 server addresses and passwords, and develop future detection capabilities.

The "TCP Listener" sample initially presented as a standard PE file designed to run on Windows. Early analysis revealed an easily extractable configuration block, XOR-encoded, that, once decoded at runtime, would set up firewall rules to permit inbound TCP connections. The malware would then await commands, communicating over its network channels using two layers of AES encryption. However, the true challenge emerged from its sophisticated API obfuscation.

All Windows programs, including malware, rely on native Windows APIs (Application Programming Interfaces) to perform tasks. For instance, reading a file involves calling APIs like CreateFile, ReadFile, and CloseHandle. Malware developers actively obscure these calls to hinder analysis and evade detection. Common obfuscation techniques include:

  • Dynamic Loading: Instead of listing APIs in the Import Address Table (IAT), malware calls LoadLibrary to load a DLL and GetProcAddress to obtain an API's address at runtime. While this removes APIs from the IAT, their names might still appear in plain text within the binary's strings or disassembly.
  • Encoded API Names: To further obscure, malware can XOR-encode or encrypt API names. This removes them from plain strings, making static analysis harder, though a decryption script can often be developed to annotate tools like IDA Pro. TCP Listener initially employed this technique for its setup phase.
  • Hashed API Names: Malware might walk a DLL's export table on startup, hashing each API name until it finds a match for a pre-computed hash. This offers similar protection to encoding but requires a bit more effort to script for static resolution.

The novel and most perplexing aspect of TCP Listener was that beyond the setup phase, for its command processing, the malware developers had completely removed even the obfuscated API names from the binary. Instead, the C2 server would transmit a list of XOR-encoded API names required for a specific command directly within the C2 payload. For example, a "read file" command would include the encoded names of CreateFile, ReadFile, and CloseHandle, followed by the target filename. This design rendered traditional static analysis (no strings to find, no hashes to reverse) and even dynamic analysis (the implant would simply wait for C2 input) ineffective without access to the actual C2 server or prior network traffic captures, neither of which were available to Deakin-Sharpe. This critical missing information created the "Sherlock Holmes style" mystery that formed the core of her analysis.

Key Findings

▶ Watch: Applying Sherlock Holmes' deduction to reverse engineer APIs (6:15)

The primary finding of this analysis is the development and successful application of a systematic, "Sherlock Holmes style" deduction methodology to reconstruct the functionality of the "TCP Listener" malware. Faced with a binary devoid of API names for its core command-and-control operations, Katie Deakin-Sharpe meticulously leveraged available clues to deduce 31 API names and 1 DLL name across nine distinct commands.

The key aspects of her deduction methodology include:

  • Leveraging Unique Constants: Distinctive numerical values, such as f00f (deduced as FILE_MAP_ALL_ACCESS) and HEX 217 (identified as ERROR_PIPE_CONNECTED), served as crucial starting points for searching Microsoft documentation.
  • Analyzing Strings: Specific strings found in the binary, like GLOBAL\ (indicating a global namespace for objects) or \\pipe\fd0 (suggesting named pipes), provided direct hints about API usage.
  • Matching Function Prototypes: Careful examination of the number and types of arguments passed to unresolved API calls, considering how 0 can represent various values (literal, boolean, size, null, or optional parameters), allowed for comparison against known API signatures in documentation.
  • Contextual Analysis and Shared Variables: Understanding the logical flow of operations within a command, and identifying variables shared between different commands, provided critical context. Successfully identifying one or two APIs often led to the rapid deduction of others within the same functional block.
  • Extensive Documentation and Example Code Review: The process heavily relied on thorough examination of Microsoft's official documentation (MSDN) and publicly available example code, which often illustrates common API usage patterns.
  • Pattern Recognition: Identifying recurring code patterns, such as sequences of calls related to CreateThread, VirtualAlloc, VirtualProtect, and memcpy, strongly indicated shellcode execution.
  • Creative Application of Tools: A notable innovation was the use of YARA rules to search through a local repository of MSDN documentation (parsed into markdown files). This allowed for efficient filtering of APIs based on DLL affiliation and parameter count, a capability not natively available in standard documentation search.
  • Sanity Checks: Constantly evaluating whether the hypothesized API usage and overall command functionality made logical sense for a piece of malware.

Through this rigorous process, Deakin-Sharpe successfully mapped the nine obfuscated commands to specific functionalities:

  • Command E: Mapping and reading from a memory-mapped file.
  • Command 5: Initializing a pair of named pipes and reading from the read pipe in a loop, sending output to the C2.
  • Command 6 & 7: Closing named pipes.
  • Command 3: Writing to a named pipe (WriteFile, FlushFileBuffers).
  • Command C & H: Executing shellcode, potentially communicating via named pipes or other means.
  • Command F: Killing processes by their Process ID (PID).
  • Command HEX 11: Enumerating processes and looking up additional account information for each.

A fascinating ancillary finding was the identification of a potential developer mistake within the malware. During the analysis of Command 5, a value of 5 was passed to SetNamedPipeHandleState as a pipe mode, which is an invalid flag combination for that API. Closer inspection revealed that while 5 is invalid for SetNamedPipeHandleState, it is a valid mode for CreateNamedPipe when considering the PIPE_TYPE_MESSAGE flag. This suggested the developers might have reused a variable intended for CreateNamedPipe without fully validating it for SetNamedPipeHandleState, indicating that even sophisticated malware authors can err.

Ultimately, this "Sherlock Holmes style" deduction not only revealed the full operational capabilities of the TCP Listener implant but also provided a robust methodology for tackling similar advanced obfuscation techniques in future malware analysis.

Technical Deep Dive

▶ Watch: Using Yara to search MSDN for APIs by parameter count (27:50)

The "Sherlock Holmes style" methodology employed by Katie Deakin-Sharpe involved a meticulous, step-by-step deduction process, often starting with the strongest available clues. The following sections detail the analysis of several key commands, illustrating this approach.

Command E: Memory-Mapped Files

Command E was tackled first due to its relatively clear clues. The initial snippet of assembly showed a constant, f00f, being passed as the first parameter to the first function. This distinct hex value was the primary starting point.

  1. Clue 1: f00f Constant. Using IDA Pro's "use standard symbolic constant" feature, f00f was identified as FILE_MAP_ALL_ACCESS.
  2. Clue 2: Documentation Search. Searching Google for FILE_MAP_ALL_ACCESS led to the documentation for MapViewOfFile. MapViewOfFile takes desired access as its second parameter, which matched the observed use of f00f as the second parameter for the second function call in the command (let's call it Function 2). MapViewOfFile also requires a handle to a file mapping object as its first parameter.
  3. Clue 3: Function Prototype Matching. MapViewOfFile has five parameters, which matched Function 2. The documentation indicated that the file mapping object handle is returned by CreateFileMapping or OpenFileMapping.
  4. Clue 4: Identifying Function 1. Examining CreateFileMapping and OpenFileMapping, CreateFileMapping had too many parameters. OpenFileMapping had three parameters, matching Function 1, and its first parameter was desired access (again, f00f), and its third parameter was a pointer to a string for the name.
  5. Clue 5: GLOBAL\ String. The code for Function 1 also showed a GLOBAL\ string being built on the stack and appended to the third parameter if the initial call failed. The OpenFileMapping documentation confirmed that the name parameter can indeed have a GLOBAL\ prefix.
  6. Clue 6: Tidy Up Functions. With OpenFileMappingA and MapViewOfFile identified, the subsequent functions (Function 3 and Function 4) were typically cleanup operations. Consulting example code for memory-mapped files often showed UnmapViewOfFile (taking the result of MapViewOfFile) and CloseHandle (taking the result of OpenFileMappingA). These matched the parameter counts and types.

Conclusion: Command E was responsible for mapping and reading from a memory-mapped file. The identified APIs were OpenFileMappingA, MapViewOfFile, UnmapViewOfFile, and CloseHandle.

Command 5: Named Pipes and Threads

Command 5 was more complex, involving 11 APIs and multiple threads.

  1. Clue 1: Function Address as Argument. The presence of a function address being pushed as an argument strongly suggested thread creation. Comparing CreateThread, CreateRemoteThread, and CreateRemoteThreadEx, only CreateThread matched the number and types of parameters (including zeros for optional values).
  2. Clue 2: Security Descriptor String. Inside the new thread's function, a unique string was observed: "D:(A;;GA;;;WD)(A;;GA;;;AN)(A;;GA;;;BA)(A;;GA;;;SY)(A;;GA;;;LS)(A;;GA;;;NS)". Googling this string, along with the DLL name (ADVAPI32.DLL), led directly to Microsoft documentation on string security descriptors and the function ConvertStringSecurityDescriptorToSecurityDescriptorA. This API takes the string as its first parameter and an empty byte buffer (created just above) as its third parameter, which is an output parameter for the resulting security descriptor.
  3. Clue 3: Pipe Strings and Error Code. Later in the command, strings like \\pipe\fd0 and \\pipe\fd1 were built, with a 32-byte value appended from the C2 server. A function (Function 3) was then called on the result of a previous function (Function 2), and its return value was checked. If it failed, GetLastError was called, and the error code was compared to HEX 217.
  4. Clue 4: Error Code Deduction. Using IDA's "use standard symbolic constant" on HEX 217 revealed ERROR_PIPE_CONNECTED. Searching for this error code led to the documentation for ConnectNamedPipe. This function takes a handle to a named pipe as its first parameter.
  5. Clue 5: Identifying Function 2. The handle for ConnectNamedPipe is returned by CreateNamedPipe. CreateNamedPipe takes a string name (matching \\pipe\fd0 and \\pipe\fd1), an open mode (indicating write permissions for the first pipe, read for the second), and crucially, a SECURITY_ATTRIBUTES structure as its last parameter. The second member of this structure is a pointer to the security descriptor created earlier. This confirmed CreateNamedPipe as Function 2.

Conclusion: Command 5 involved creating and connecting to named pipes in a multi-threaded server architecture. The identified APIs included CreateThread, ConvertStringSecurityDescriptorToSecurityDescriptorA, CreateNamedPipe, and ConnectNamedPipe. The remaining seven APIs were deduced by thoroughly reviewing documentation on pipe functions and multi-threaded pipe servers. Command 5 initializes a pair of named pipes and reads from the read pipe, sending output to the C2. Commands 6 and 7 were found to be related to closing these pipes.

Command 3: Writing to Pipes

Command 3 leveraged shared variables. It accessed a shared structure containing the handle to the write pipe initialized by Command 5. This handle was then passed to Function 1, along with C2-supplied input buffers. Function 2 was then called with just the handle. Given a pipe with write permissions, the logical actions are to write data and then ensure it's flushed.

Conclusion: WriteFile was identified as Function 1 (taking the handle, buffers, and other parameters), and FlushFileBuffers was Function 2 (taking just the handle). Command 3 was writing to the named pipe.

Commands C and H: Shellcode Execution

These commands relied on pattern recognition.

  1. CreateThread Pattern: Both commands started with a function address being pushed as an argument, identical to the CreateThread call seen in Command 5.
  2. Memory Protection Constants: Inside the new thread's function, parameters like HEX 40 and HEX 1000 were pushed to subsequent functions. These are frequently seen memory protection constants, suggesting VirtualAlloc or VirtualProtect.
  3. memcpy and Call: The sequence of allocating/protecting memory, followed by a memcpy into that memory region, and then a call to the allocated memory, is a classic shellcode execution pattern.

Conclusion: Commands C and H were executing shellcode. Command H executed shellcode that communicated via the named pipes, while Command C executed shellcode that presumably used other communication means, which were not visible to the analyst.

Command F: Killing Processes by PID

Command F was one of the harder ones, lacking strong initial clues like strings or unique constants. The code iterated through an input list of dwords (4-byte values), passing each into Function 1, then taking the result and passing it to Function 2 along with a 0. Crucially, there was no output returned to the C2.

  1. Hypothesis Generation: Without clear clues, Deakin-Sharpe brainstormed common malware functionalities: enumerating, reading, scraping, writing, or manipulating processes. The lack of output ruled out enumeration, reading, and scraping. The input of dwords was too small for writing files.
  2. Process Manipulation: This led to the hypothesis of process manipulation. Given the input was dwords and no output, killing processes seemed plausible.
  3. API Deduction: The input dwords were hypothesized to be Process IDs (PIDs). To kill a process by PID, one typically first calls OpenProcess to get a handle, then TerminateProcess with that handle and an exit code (often 0 to appear benign). This sequence perfectly matched the observed structure: Function 1 (OpenProcess) taking the PID, and Function 2 (TerminateProcess) taking the handle from Function 1 and a 0 (for the exit code).

Conclusion: Command F was killing processes by PID using OpenProcess and TerminateProcess.

Command HEX 11: Enumerating Processes

This command introduced the "mystery DLL" mentioned at the start.

  1. Function Prototypes: Function 1 (mystery DLL) had five parameters. Function 2 (ADVAPI32.DLL) had seven parameters and was called in a loop. Function 3 (mystery DLL) had one parameter.
  2. YARA for Documentation Search: To overcome the inability to search MSDN by parameter count, Deakin-Sharpe used a novel technique. She downloaded MSDN documentation as markdown files and then wrote YARA rules to search them. For Function 2, a rule searched for ADVAPI32.DLL and exactly seven parameter strings. This yielded a manageable number of results, all related to looking up accounts by name or SID.
  3. Refining Function 1 Clues: Function 1's fourth parameter was an empty byte buffer, suggesting an output parameter. This output was then iterated through, accessing an offset of HEX 10 within each item, which was then passed as the second parameter to the lookup account APIs (Function 2). This strongly suggested a list of structures, where one member (at offset HEX 10) was an account SID or name.
  4. Narrowing Down Function 1: Function 1 was likely "getting a list of something." Using YARA to search for APIs in non-excluded DLLs with five parameters, and keywords like list, net, group, or enumerate, eventually led to WTSAPI32.DLL and WTSEnumerateProcessesA. This API returns a list of WTS_PROCESS_INFO structures, where the pUserSid member is indeed at offset HEX 10.
  5. Final Deduction: With WTSEnumerateProcessesA (Function 1) and LookupAccountSid (Function 2) identified, Function 3 (one parameter, from WTSAPI32.DLL) was likely a cleanup function for memory allocated by WTSEnumerateProcessesA, leading to WTSFreeMemory.

Conclusion: Command HEX 11 was enumerating processes using WTSEnumerateProcessesA, LookupAccountSid (or LookupAccountSidW), and WTSFreeMemory, revealing the mystery DLL as WTSAPI32.DLL.

The Developer Mistake: SetNamedPipeHandleState

During the analysis of Command 5, Function 4 took the handle to the right pipe, a pointer to a dword with the value 5, and two zeros. Through YARA searches for kernel32.dll APIs with four parameters, SetNamedPipeHandleState was identified as a strong candidate. However, the value 5 is not a valid pipe mode for this API.

Further investigation into the documentation for SetNamedPipeHandleState revealed that its pipe mode parameter is a combination of two flags: a wait mode (zero for wait, one for no wait) and a read mode (zero for byte, one for message). This limits valid values to 0 through 3. The value 5 would imply a third bit set, which doesn't correspond to any flag for this API.

However, when examining the CreateNamedPipe function, its pipe mode parameter includes a third flag: PIPE_TYPE (byte or message). With this additional flag, a value of 5 becomes valid. The malware initially created the pipe with a mode of 4 (wait, byte read mode, message type) and then attempted to change it to 5 (no wait, byte read mode, message type). This meant flipping the wait flag from "wait" to "no wait" after ConnectNamedPipe had returned.

Conclusion: The developers likely made a mistake, reusing a pipe mode variable intended for CreateNamedPipe when calling SetNamedPipeHandleState without validating the flags specific to the latter API. This suggests that even sophisticated malware can contain minor operational flaws.

Demo / Proof of Concept

▶ Watch: Q&A: What data would have most helped the analysis (44:50)

While the talk did not feature a live demonstration of the malware itself, Katie Deakin-Sharpe confirmed that the deduced functionalities were verified by running the sample in a controlled environment. The ability of the implant to terminate processes by PID, communicate via named pipes, and execute shellcode was successfully observed, validating the accuracy of her reverse engineering efforts.

Defensive Implications

▶ Watch: Q&A: Why generative AI failed for API lookup (51:50)

The "TCP Listener" malware's novel API obfuscation technique presents significant challenges for traditional defensive strategies and highlights the evolving sophistication of adversaries. Understanding these implications is crucial for enhancing cyber resilience.

  1. Limitations of Static Analysis and Signature-Based Detection: By dynamically loading API names from the C2 server, the malware completely bypasses static analysis tools that rely on the Import Address Table (IAT) or string matching. Traditional antivirus signatures, often based on embedded API calls or literal strings, would struggle to detect this variant. Defenders must recognize that the absence of obvious indicators in a binary does not equate to benign behavior.
  2. Increased Reliance on Network Monitoring and Packet Capture: This specific obfuscation technique could have been circumvented if network packet captures from the initial compromise were available. The C2 communication containing the encoded API names was the missing link. This underscores the critical importance of robust network monitoring, full packet capture (PCAP), and C2 traffic analysis capabilities within an organization's security architecture. Detecting and decrypting C2 communications (if keys are known or extracted) is paramount for uncovering dynamic behaviors.
  3. Emphasis on Behavioral Detection: Since static indicators are absent, defenses must shift towards behavioral analysis. Endpoint Detection and Response (EDR) solutions, User and Entity Behavior Analytics (UEBA), and Security Information and Event Management (SIEM) systems should focus on flagging suspicious sequences of API calls (e.g., CreateThread followed by VirtualAlloc, VirtualProtect, and memcpy into the allocated region, then executing that memory, indicating shellcode), even if the individual API names are dynamically resolved. Anomalous process creation, inter-process communication (like named pipes), or unusual network traffic patterns should trigger alerts.
  4. Importance of Deep OS Knowledge for Incident Responders: The success of this analysis hinged on a deep understanding of Windows internals, API functions, and common malware patterns. Incident response teams and malware analysts need to possess advanced skills in reverse engineering, system programming, and memory forensics to effectively dissect such implants. Relying solely on automated tools will prove insufficient against bespoke and highly obfuscated threats.
  5. Threat Intelligence Sharing: Novel obfuscation techniques like this need to be documented and shared within the cybersecurity community. This allows other organizations and security vendors to anticipate and develop countermeasures more rapidly. The ACSC's role in disseminating such findings is vital for collective defense.
  6. Supply Chain Security and Software Integrity: The talk also implicitly touches on the broader challenge of supply chain attacks, where legitimate software can be laced with shellcode or malicious modules. While not explicitly discussed for TCP Listener's initial infection vector, the ability to dynamically load and execute code highlights the need for rigorous software integrity checks and application whitelisting to prevent unauthorized code execution.

In essence, defending against malware like TCP Listener requires a holistic approach that integrates advanced network and endpoint visibility with highly skilled analysts capable of creative problem-solving and in-depth technical deduction.

Key Takeaways

  • Malware Obfuscation is Evolving: Adversaries are constantly developing new ways to evade detection and analysis, moving beyond traditional methods like IAT manipulation and simple encoding to dynamically deliver API names from C2 servers.
  • The Power of Deduction: Even without direct indicators, a systematic, "Sherlock Holmes style" approach leveraging all available clues—unique constants, strings, function prototypes, context, and documentation—can successfully unravel complex malware functionality.
  • Creative Tool Application: Tools like YARA, typically used for malware identification, can be innovatively repurposed for tasks like documentation search, demonstrating the value of flexible problem-solving.
  • Comprehensive Documentation is Key: Extensive knowledge of Microsoft API documentation (MSDN) and example code is an invaluable resource for reverse engineers, often providing the missing pieces of the puzzle.
  • Even Adversaries Make Mistakes: Highly sophisticated malware can still contain minor operational flaws or developer errors, such as the incorrect pipe mode value for SetNamedPipeHandleState, which can sometimes serve as additional clues.
  • Persistence and Creativity are Paramount: Successful malware analysis, especially against novel techniques, demands significant persistence, deep technical knowledge, and the ability to think creatively when conventional methods fail.

About the Speaker(s)

Katie Deakin-Sharpe is a Malware Analyst at the Australian Cyber Security Center (ACSC), which operates as part of the Australian Signals Directorate (ASD). In her role, she is responsible for reverse engineering malware samples collected during cyber incidents impacting Australia's critical infrastructure, industry, and government sectors at local, state, and federal levels. Katie's background includes experience as a software developer, a foundation that she has adeptly transitioned into the specialized field of malware reverse engineering. Her work focuses on identifying malware families, understanding their functionality, communication methods, and extracting vital intelligence for incident response and future detection.

Reviews

→ Top-rated talks at BSides Canberra VIII (2025)

All talks from BSides Canberra VIII (2025)