Designing Robust API Monitoring Solutions

Designing Robust API Monitoring Solutions

1 Designing Robust API Monitoring Solutions Daniele Cono D’Elia, Simone Nicchi, Matteo Mariani, Matteo Marini, and Federico Palmaro Abstract—Tracing the sequence of library and system calls that a program makes is very helpful in the characterization of its interactions with the surrounding environment and ultimately of its semantics. Due to entanglements of real-world software stacks, accomplishing this task can be surprisingly challenging as we take accuracy, reliability, and transparency into the equation. To manage these dimensions effectively, we identify six challenges that API monitoring solutions should overcome and outline actionable design points for them, reporting insights from our experience in building API tracers for software security research. We detail two implementation variants, based on hardware-assisted virtualization (realizing the first general-purpose user-space tracer of this kind) and on dynamic binary translation, that achieve API monitoring robustly. We share our SNIPER system as open source. Index Terms—API monitoring, API hooking, call interposition, binary instrumentation, hardware virtualization, malware. F 1 INTRODUCTION ing solutions that trace also library APIs in order to under- A modern operating system (OS) typically comes with stand how a sample achieves some functionality. Consider large, heterogeneous software components that developers a code fragment using an HTTP-related API: intercepting can build on when writing a software program. Operating a packet transmission down in the software stack is not as systems expose their functionalities through Application informative as logging the API that originated it. Also, there Programming Interfaces (APIs) that compiled code accesses are APIs whose uses cannot be directly inferred from the through well-defined prototypes and calling conventions. sole observation of one or more system calls. The sequence of APIs that a piece of code may invoke Tracing high-level facts is in general valuable for many during its execution characterizes its externally observable monitoring, troubleshooting, and reverse engineering tasks. behavior and ultimately its semantics. Hence, monitoring Notwithstanding the relevance and the many applications API calls is a popular practice in dynamic analysis scenarios. of API monitoring, we note that prior literature touches only This operation is useful, for instance, in malware analysis slightly the design space and the accuracy, reliability, and and code reverse engineering activities in order to track how transparency dimensions behind this task in the general case. an untrusted piece of software interacts with the surround- This is possibly reflected in how mainstream API mon- ing environment [1]. It is similarly valuable in dependability itoring systems available today fall short in one or more research for run-time monitoring [2] and troubleshooting [3] of these respects. Common flaws that we observed in our of programs, among others. experience are incomplete argument tracing, missed calls As the monitoring process requires an interposition to APIs that a program solves dynamically, and hooking mechanism for API calls, it also goes under the colloquial artifacts that adversaries routinely identify. Also, most sys- name of API hooking. Researchers and practitioners may also tems overwhelm users with calls that originate within the resort to specialized forms of API monitoring, tailoring their implementation of a high-level API: their logging does not implementations to different contexts. bring users any actionable information, but only describes For instance, a malware sandbox monitors interactions how the operating system realizes some functionality. with the operating system to sketch the high-level behavior In the first part of this article we identify six key arXiv:2005.00323v2 [cs.CR] 11 Mar 2021 of a sample under analysis. Sandboxes prevalently interpose challenges towards accurate, reliable, and transparent API on system calls [4] so as to collect in a single spot events of monitoring. We analyze the design space for a general- interest originating from high-level APIs. This rationale is purpose API tracing system that can address them and work mainly justified by the desire not to miss behaviors exercised over different instrumentation technologies, with special via unaccounted-for APIs, since to accomplish some task attention to implications from security uses. malware authors may sometimes draw from many alterna- We then present two implementations of our design, tive library APIs and use them in unexpected ways. detailing common traits and distinctive features of both. Conversely, when moving to the manual dissection stage One builds on dynamic binary instrumentation and can for notable samples [5], malware analysts resort to monitor- operate standalone or as a support library for existing dynamic analysis systems based on this popular abstraction. • D.C. D’Elia, S. Nicchi, M. Mariani, and M. Marini are with Sapienza The other builds on CPU virtualization extensions for more University of Rome, 00185 Roma, Italy (e-mail: [email protected]). efficient and transparent instrumentation, and represents • F. Palmaro is with Prisma, 00142 Roma, Italy. the first open solution of this kind. Following an extensive This work has been submitted to the IEEE for possible publication. validation, we experimentally analyze their capabilities in Copyright may be transferred without notice, after which this version tracing real-world programs and complex malware. may no longer be accessible. (Corresponding author: D.C. D’Elia.) Our implementations target the Windows platform, cov- Digital Object Identifier: none available at the moment ering a large collection of libraries and system calls, and can 2 be extended to other systems. Although general-purpose, input (IN) or an output (OUT) value, or both (INOUT) [8]. we incubated them as part of our malware analysis research: An output argument is usually a pointer to a region where the tricky patterns found in this realm combined with quirks the API can write output data. Alongside prototype infor- of Windows internals have been a tough training ground for mation, headers introduce a large number of type aliases their development. and structure declarations. We make the code of our API tracing system SNIPER System calls, or syscalls for short, operate in a differ- available at https://github.com/dcdelia/sniper. ent way. Classic programs access them through user-space wrappers available as exports of ntdll.dll that set the syscall ordinal in register EAX and trigger a software in- 2 BACKGROUND terrupt. Adversaries can elude monitoring strategies that This section covers the main traits and underpinnings of the check such wrappers by extracting from ntdll.dll the API handling process for Windows programs and libraries, ordinals for the current Windows version and triggering the and compares instrumentation technologies available to interrupt with own code, realizing a so-called direct syscall. date for implementing an API monitoring system. Experienced writers may also use undocumented syscalls to complicate the analysis: prototypes for them may only be found in reverse engineering forums. 2.1 Windows API Resolution and Internals Windows programs can access functionalities of the sur- 2.2 Instrumentation Technologies rounding environment by loading functions from dynamic- link library (DLL) modules. In order to locate addresses for As we will see throughout this article, the type of instru- external function symbols, the Portable Executable format mentation a system uses to interpose on API calls affects provides for an .idata section for their listing. This section several dimensions of the overall monitoring efficacy. contains an array called import address table (IAT) that the A possible avenue is to patch an IAT entry so as to point Windows loader populates at run-time with pointers to the to a tracing stub that logs the call and in turn invokes the desired functions, importing them from known DLLs. intended API. This approach is known as IAT hooking and DLL modules come with an analogous .edata section unfortunately misses calls to APIs made without the IAT for their public functions and storage, known as exports. (§2.1). A better alternative that covers also those is to place Each entry of the export address table (EAT) is a relative instrumentation inside API code, modifying the prologue virtual address (RVA) that is the offset of the export from the of monitored functions with the insertion of a trampoline to base address of the module. For an executable importing a a tracing stub. Mainstream commercial tracers follow either function from a DLL, the loader will typically populate the approach; a major weakness of both is that an adversary can involved IAT entry by looking up the RVA of the export in clearly recognize the modifications they introduce. the EAT of the DLL and adding it to the base address that Instrumentation artifacts are a well-known problem for the system chose for the DLL when loading it. dynamic analyses that operate through binary patching: for However, there are alternative methods to locate API ad- this reason, other technologies have gained popularity in dresses. A program may manually load a DLL and retrieve security research [9]. its exports using the GetProcAddress Windows API that Dynamic binary translation (DBT) systems can trap exe- does not touch the IAT. Furthermore, regardless of how cution at arbitrary instructions based on their type

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us