BOOK A DEMO

Common Anti-Debugging Techniques in The Malware Landscape

debugging

This is the first article in our new series, “The Malware D.Igest”, in which each time a malware expert of ours will cover another core topic in the world of malware analysis.

Introduction

Malware authors have always looked for new techniques to stay invisible. This includes, of course, being invisible on the compromised machine, but it is even more important to hide malicious indicators and behavior during analysis. Malware authors assume that once the malicious file is out in the wild, its lifetime clock is ticking and eventually it will be detected by researchers and thoroughly analyzed.

To make post-detection analysis more difficult, threat actors use various anti-analysis techniques, one of the more common ones is Anti-Debugging. In this blog post, I will present some examples of popular anti-debugging techniques. The techniques covered here constitute an exhaustive list of the main concepts and  are based on what the research team here at Deep Instinct encounters on a daily basis.

What is Anti-Debugging?

Debugging malware code enables a malware analyst to run the malware step by step, introduce changes to memory space, variable values, configurations and more. Therefore, if debugging is done successfully, it facilitates the understanding of the malware’s behavior, mechanisms and capabilities. For obvious reasons, this is something malware authors would want to prevent. Anti-Debugging techniques are meant to ensure that a program is not running under a debugger, and in the case that it is, to change its behavior correspondingly. In most cases, the Anti-Debugging process will slow down the process of reverse engineering, but will not prevent it.

PEB Structure

Process Environment Block (PEB) is a data structure which resides in the user space of each process, and contains data about the related process. It is designed to be accessed by the WinAPI modules, but access is not limited exclusively to them; one can access the PEB directly from memory, as we will see next:

BeingDebugged – The easiest implementation and obvious technique is to check the value of the BeingDebugged field at PEB structure. There are many API calls (documented and undocumented – isDebuggerPresent, CheckRemoteDebuggerPresent, NtQueryInformationProcess) to check this value. In order to enhance evasion, it also can be checked manually without a WinAPI call; PEB can be accessed by the fs segment register at fs:[30h] (This register points to TIB (Thread Information Block) in x86 machines).

ProcessHeap – a flag under PEB that shows if the first heap memory space of the process was created in debug mode. It can be accessed at offset 0x18 (at PEB).

Residue in the system

A machine that contains debugging functionalities can be identified without special efforts. Like any other software, a debugger will leave a trace over the machine.

Registry keys – besides the obvious registry locations that most applications write themselves, there is a registry key that is set to the debugger program that should run when an error occurs (“HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug”).

FindWindow – WinAPI function that can recognize the presence of a debugger program (e.g “ollydbg.exe”). The same result can be reached with OpenProcess for processes, or with FindFirstFile and FindNextFile for filesystem paths (for example in the %ProgramFiles% folder).

Identifying Breakpoints

A Breakpoint is probably the most important feature of a debugger; it enables the researcher to stop the execution of a program at a certain point of code.

Instructions scanning – A debugger’s breakpoint is implemented by inserting “0xCC” (“INT 3” in assembly) which means the software interrupt with the parameter ‘3’, A malware can scan itself to find this assembly instruction (for example with the assembly instruction “repne scasb”).

Calculate code checksum or hash – malware can calculate a checksum or hash of its code in run time to determine if it was patched or if a breakpoint was inserted (for instance, a value that was described before: ‘0xCC’), and therefore this can be used to identify debuggers as well.

The Debugger’s Environment

There are many techniques to identify running debugger’s context.

OutputDebugString is used to send a string to a debugger. If it fails, an error occurs. Malware can use SetLastError with a defined value, then run OutputDebugString (if it fails, it will overwrite the last error value), then check the last error with GetLastError.

Timing checks – when debugging in a single-step mode / setting a breakpoint, a lag occurs while running the executable. The malware can check for a timestamp and compare it to another one after a few malicious instructions, in order to check if there was a delay. The instruction rdtsc is used to get the number of ticks since the last system reboot and it rolls over after 49.7 days (will be placed as 64bit value in EDX:EAX 32bit registers). There is equivalent WinAPI functions for this test (GetTickCount / QueryPerformanceCounter).

Debugger vulnerabilities – a debugger is a program, and like any other program it may have vulnerabilities. For instance, a famous one would be: crashing OllyDbg 1.1 by calling OutputDebugString with the value “%s”.

Image File Execution Options (IFEO)

IFEO is a registry key that is intended to run a particular program under a local debugger.

Key:HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<particular_program>

Value: Debugger: <full-path to a local debugger> (REG_SZ)

A malware can check if there is any debugger configured manually on the machine, although debugging and Anti-Debugging is not the only use for this registry key. It is also easily implemented as a technique to launch malware, since Windows does not perform any check that the “debugger” is indeed a debugger. For this reason, a malware author can abuse it for running malware, for example, by just attaching to another process that is loaded by default with startup.

TLS Callback

TLS (Thread Local Storage) is a memory region that is local to a thread. It can be abused to run a function before the entry point of the PE (i.e in the initialization of a thread) – this technique is called TLS Callback. Mostly, debuggers start debugging from the entry point. This technique can be identified in the following manners: 

* Statically by .tls section existence
* IDA Pro supports running from all the entry points (including TLS Callback)
* Debuggers can be configured to set a breakpoint before running TLS Callback
* All TLS callback functions are labeled with “TlsCallback” prepended

To sum up, Anti-Debugging can be reached by essential features of the operating system or by the natural behavior of the debugger itself. Malware authors keep challenging researchers with new techniques in order to delay the reverse engineering process.

Stay tuned for more content from Deep Instinct’s malware experts.

New Call-to-action

Book a Demo

See the benchmarks for yourself!

To understand how you can thoroughly protect your organization against unknown and known threats, from any digital touchpoint, book your private demo with a Deep Instinct expert consultant.

Get an overview of how Deep Instinct’s security solution works, as well as an initial assessment of your specific security needs.

Start instinctively protecting your organization against all threats.

*
*
*
*
* We respect your privacy. Read our Privacy Policy
BOOK A DEMO TODAY

Terms of Use

Last updated: 20 September, 2015

THIS WEBSITE, www.Deep Instinct.com (the “Site”), is owned and operated by Deep Instinct Ltd. (“Deep Instinct”, “we”, “us” or “our”). Any use of this Site or the services available on the site from time to time (“Services”) is subject to and conditioned upon your consent to and compliance with, all of the terms and conditions in this terms of use agreement (the “Agreement”) which also incorporates our privacy policy [insert hyperlink to privacy policy]. By accessing and using the Site and/or any Services made available on it you hereby consent to be bound by this Agreement. If you do not agree with any of the terms and conditions of use, please cease any use or access to this Site and any use or access to the Services. We may amend this Agreement at any time by posting the amended terms on the Site. Your continued use of the Site or Services shall constitute your consent to any changes made. If you do not agree to the new or different terms, you should not use the Site or the Service. This Agreement may not be otherwise amended.

THE SITE AND THE SERVICES

We are engaged in the business of development, configuration, marketing, sales, integration and implementation of projects and solutions (including tactical verticals thereof) in the field of cyber security and our Site provides informative, educational and promotional information on our company, our products, and our services. We currently do not offer a direct download of our products from our site and provide our software directly to you subject to additional terms and conditions which are detailed in the end user license agreement accompanying each copy of our products.

ELIGIBILITY TO USE OUR SERVICES

This Site is aimed for use by individuals who are natural persons, who are at least 13 years old and who are of sufficient legal age and capability to form a binding agreement under the laws of their domicile. You may not use the Site and the Services and may not accept this Agreement if (a) you are not of legal age to form a binding contract with Deep Instinct (as determined in your domicile), or (b) you are a person barred from using the Site or the Services under the laws of the United States or Israel or other countries including the country in which you are domiciled or from which you access or use the Site and/or the Services. Subject to applicable law, Deep Instinct may, in its sole discretion, refuse to offer the Site and the Services to any person or entity and change its eligibility criteria at any time.

ELECTRONIC COMMUNICATIONS

When you contact us by sending emails to us, you are communicating with us electronically and you consent to receive communications from us electronically. We will communicate with you by email (if and to the extent you choose to provide with your e-mail address) or by posting notices on this Site. You agree that all agreements, notices, disclosures and other communications that we provide to you electronically satisfy any legal requirement that such communications be in writing.

PROPRIETARY RIGHTS

The Site, the Services and the content therein are proprietary to us and/or our licensors. Any and all intellectual property rights related to the Services and the Site are and shall remain our exclusive property or our licensors. Nothing in this Site grants any license or right to use any marks displayed on this Site without the written permission of the owner of the mark. Your misuse of the marks displayed on this Site or any other content on this Site is strictly prohibited. Without derogating from any of the provisions herein, you agree not to decompile, reverse-engineer, copy, transfer, assign, rent, resell, distribute or use the Site or the Services (or any part thereof, or any software underlying the Service), other than as expressly authorized by Deep Instinct. Any and all trademarks, service marks, product names, and trade names of Deep Instinct appearing on or through the Site and/or Service are exclusively owned by Deep Instinct. All other trademarks, service marks, product names, and logos appearing on or through the Service are the property of their respective owners. You may not use or display any trademark, service mark, product name, trade name, or logo appearing on or through the Service without the owner's prior written consent. Furthermore, the site is intended for use by natural persons. Any access or use of the Site by any automated means including but not limited to spiders, bots, scrapers and the like is prohibited. Any use of any information collected by such automated means constitutes a violation of this Agreement. Any use of the Site or any parts thereof or information therein for any commercial purposes is prohibited.

COMPLIANCE WITH LAWS

Access or use of the Internet or of certain websites may be prohibited in certain territories and/or certain restrictions may apply to you in such territories. Don’t access this Site if such access is prohibited under law applicable to you. You agree that your use of the Site and Services shall not violate any applicable local, national or international law, including but not limited to any regulations having the force of law.

LINKS TO OTHER WEBSITES

This Site may contain links and references to websites of others. We may, from time to time, at our sole discretion, add or remove links to other websites. These links are provided solely for informative purposes and as a convenience to you, and access to any such websites is at your own risk. We recommend that you review the information provided by third parties (such as, but not limited to, the terms of service and privacy policy of the relevant website) before accessing such websites. We do not review, approve, monitor, endorse, warrant, or make any representations with respect to such websites. In no event will we be responsible for the information contained in such websites, their practices or for your use of or inability to use such websites, or transmissions received from such sites. You expressly relieve us from any and all liability arising from your use of any third-party website. We encourage you to be aware when you leave the Site, and to read the terms and conditions and privacy policy of such other website/s that you visit.

NO WARRANTY

THE SITE, AND ANY SERVICES OFFERED THROUGH IT IS PROVIDED ON AN "AS IS" BASIS WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF TITLE OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. YOU EXPRESSLY AGREE THAT USE OF THE SITE IS AT YOUR SOLE RISK. NEITHER DEEP INSTINCT, ITS SUBSIDIARIES, ITS AFFILIATES NOR ANY OF THEIR RESPECTIVE EMPLOYEES, AGENTS, THIRD PARTY CONTENT PROVIDERS OR LICENSORS WARRANT THAT THE SITE WILL BE UNINTERRUPTED OR ERROR FREE; NOR DO THEY MAKE ANY WARRANTY AS TO THE RESULTS THAT MAY BE OBTAINED FROM USE OF THE SITE, OR AS TO THE ACCURACY, RELIABILITY OR CONTENT OF ANY INFORMATION, SERVICE, OR MERCHANDISE PROVIDED THROUGH THE SITE.

THE SITE OFFERS CERTAIN INFORMATION ABOUT THE COMPANY AND ITS PRODUCTS AND SERVICES, INCLUDING A KNOWLEDGE BASE IN WHICH THE COMPANY MAY UPLOAD CERTAIN DOCUMENTS OR PRESENTATIONS. SUCH INFORMATION IS DESIGNED FOR EDUCATIONAL AND INFORMATIONAL PURPOSES ONLY. THE INFORMATION CONTAINED ON THE SITE DOES NOT AND IS NOT INTENDED TO PROVIDE ANY REPRESENTATION OR WARRANTIES AS TO THE PRODUCTS, THEIR CAPABILITIES OR THEIR USE. ALL SUCH INFORMATION IS SPECIFICALLY PROVIDED IN THE DOCUMENTATION ACCOMPANYING THE COMPANY’S PRODUCTS AND SUCH DOCUMENTATION IS THE ONLY SOURCE OR REPRESENTATION AND WARRANTIES AS WITH RESPECT TO THE COMPANY’S PRODUCTS. YOU SHOULD NOT RELY ON THIS INFORMATION AS A SUBSTITUTE FOR, NOR DOES IT REPLACE THE COMPANY’S PRODUCTS’ DOCUMENTATION. DEEP INSTINCT IS NOT RESPONSIBLE FOR ANY ACTIONS OR INACTION ON YOUR PART BASED ON THE INFORMATION THAT IS PRESENTED IN THE SITE.

LIMITATION OF LIABILITY

IN NO EVENT SHALL WE, OUR SUBSIDIARIES, OFFICERS, DIRECTORS, EMPLOYEES OR OUR SUPPLIERS BE LIABLE FOR LOST PROFITS OR ANY SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH OUR SITE, OUR SERVICES OR THIS AGREEMENT, HOWEVER ARISING. IF YOU ARE DISSATISFIED WITH THE SITE OR THE SERVICES OR ANY MATERIALS THEREON, OR WITH THESE TERMS AND CONDITIONS, YOUR SOLE AND EXCLUSIVE REMEDY IS TO DISCONTINUE USING THE SITE AND SERVICES. WITHOUT DEROGATING FROM ANY OF THE FOREGOING, OUR TOTAL AGGREGATE LIABILITY UNDER THIS AGREEMENT, IF ANY, IN CONNECTION WITH THE SITE, THE SERVICES OR THE AGREEMENT WILL NOT EXCEED USD $100. THE FOREGOING LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY AND ARE FUNDAMENTAL ELEMENTS OF THE BARGAIN BETWEEN US AND YOU.

PRIVACY POLICY

Information that we collect and use about you is subject to our Privacy Policy located at http://www.dinstinct.com/privacy. By accessing this Site you consent to the collection and use of information as described in our Privacy Policy, as may be amended by us from time to time.

GOVERNING LAW; DISPUTE RESOLUTION

The laws of Israel will govern this Agreement, without regard to its conflict of law principles. Any and all legal claims, suits or actions that arise in connection with this Agreement and/or the Site or Services, claimed against us shall be brought exclusively in the courts located in Tel-Aviv, Israel. You agree that this Site shall be deemed a passive website that does not give rise to personal jurisdiction over Deep Instinct, either specific or general, in jurisdictions other than Israel.

LIMITATION OF CLAIMS

You agree that regardless of any statute or law to the contrary, any claim or cause of action arising out of or related to use of the Services or the Agreement must be filed within one (1) year after such claim or cause of action arose or be forever barred.

WAIVER AND SEVERABILITY

The failure of Deep Instinct to exercise or enforce any right or provision of this Agreement shall not constitute a waiver of such right or provision. If any of the provisions of this Agreement are held invalid, unenforceable, or void by a court or other tribunal of competent jurisdiction, the parties nevertheless agree that the court should endeavor to give effect to the parties' intentions as reflected in the provision, and the other provisions of the Agreement remain in full force and effect.

Deep Instinct Privacy Policy

Last updated: 20 September, 2015

This Privacy Policy ("Privacy Policy") describes the policies and practices of Deep Instinct Ltd. ("we," "us," or "Deep Instinct") and the choices you have in connection with the collection, use and disclosure of your personal information that you provide to us or that may be generated by your use of our website (the "Site"). Please review carefully this Privacy Policy before making any use of the Site. Each use of the Site by you constitutes your consent to the collection, transfer, storage, disclosure and other uses of your personal information as described in this Privacy Policy.

THE PRIVACY PHILOSOPHY OF DEEP INSTINCT

Your privacy is important to Deep Instinct. We follow generally accepted industry standards to protect the personal information submitted to us, both during transmission and once we receive it. However, due to the nature of Internet communications and evolving technologies, unauthorized entry or use, hardware or software failure, and other factors, the security of user information may be compromised at any time. No method of transmission over the Internet, or method of electronic storage, is 100% secure.

COLLECTION OF PERSONAL INFORMATION

We do not actively collect personal identifiable information. When you visit our Site you remain anonymous. Some areas of our Site may however require you to provide us with certain information, such as a user's name, email address, contact information and other personally-identifiable information ("Personal Information") may be collected from you and stored in our databases, request support, enter into a sales promotion or otherwise interact with us (for example through the "contact us" option). When you submit or make available your Personal Information through the Service, you are giving your consent to the collection, use and disclosure of such information pursuant to this Privacy Policy. If you do not wish us to collect any Personal Information from you, please do not provide us with any such information. However if you will not provide us with the required information we may not be able to provide you with the information/services requested by you.

COLLECTION OF NON-PERSONALLY IDENTIFIABLE INFORMATION

Our servers automatically collect data about your Internet Protocol address when you visit us. We collect non-identifiable information about your access to our site and your visit to it. We may also collect technical non identifiable information about the type of web browser, computer, platform, related software and settings you are using; any search terms you have entered on our Site or a referral website; and other web usage activity and data logged by our web servers. When you use the Site, we may employ clear gifs (also known as web beacons) which are used to track the online usage patterns of our users anonymously. In addition, we may also use clear gifs in HTML-based emails sent to our users to track which emails are opened by recipients. The information is used to enable more accurate reporting, improve the effectiveness of our marketing, and make Deep Instinct better for our users.

We may use "cookies" on or in connection with our Site to maintain non personally identifiable information about you. A cookie is a very small text document, which often includes an anonymous unique identifier. Deep Instinct may use both "session" cookies and "persistent" cookies. A persistent cookie remains on your hard drive after you close your browser. Persistent cookies may be used by your browser on subsequent visits to the Site. Persistent cookies can be removed by following your web browser’s directions. A session cookie is temporary and disappears after you close your browser. When you visit our Site, our computer may ask your computer for permission to employ the use of a session or persistent cookie. Our Site will then send a cookie to your browser if your browser’s preferences allow it, but (to protect your privacy) your browser only permits our Site to access the cookies it has already sent to you and not the cookies sent to you by other websites. Most web browsers can be adjusted to inform you when a cookie has been sent to you and provide you with the opportunity to refuse that cookie. However, refusing a cookie may, in some cases, preclude you from using, or negatively impact the display or function of, our Site or certain areas or features of our Site.

HOW WE USE INFORMATION

The personal information you provide to us may be used for a variety of purposes such as provide you with support, sales promotion or other interaction with us (for example through the "contact us" option). Any such use will be made only following your affirmative express consent through our Site. Your information may also be used by us, in aggregate manner for internal purposes to improve our site, content, customize advertising and content. We may also use information we collect for internal analytical purposes.

Deep Instinct uses "cookies", web beacons, log file information and other non-personally identifiable information for purposes such as to: (a) collect website users' usage data to enable easy access to the Site and otherwise improve the Site; (b) provide custom, personalized content and information; (c) monitor the effectiveness of the Site; (d) monitor aggregate metrics such as total number of visitors and pages viewed; and (e) track your entries and submissions to the Site.

HOW WE SHARE YOUR PERSONAL INFORMATION

Deep Instinct will not rent or sell your Personal Information to others.

OPT-OUT OPTIONS AND UNSUBSCRIBING

Deep Instinct may send you, from time to time, email communications, with news and updates about the Service or other products, as well as other marketing communications and promotional offers. If, you wish to stop receiving such promotional information you can opt-out by clicking the “unsubscribe” link available at the bottom part of each email sent from Deep Instinct which will remove your email address from any such mailing lists.

LINKS

The Site may contain links to third parties' web sites. While we attempt to provide links to sites that value your privacy, we cannot be responsible for the content or privacy policies of such sites. We encourage you to carefully review the privacy policies of such third parties' Web sites linked or provided through the Site prior to any use of such Web sites.

BUSINESS TRANSFERS

In the conduct of our business, we may sell some of our assets. Information collected from users of the Site, including personal information, could be transferred as part of such transaction. By submitting your personal information through the Site, you agree that your information may be transferred to third parties under such or similar circumstances.

CHANGES TO THIS PRIVACY POLICY

Deep Instinct may occasionally revise this Privacy Policy to reflect changes in its Site and other practices. Therefore, you should review Deep Instinct's Privacy Policy prior to each use of the Site, particularly each time before you submit your personal information through the Service, so you could be informed of any changes in our privacy practices. At all times, the most current version of our privacy policy will supersede any other versions of our privacy policy. You can determine when the Privacy Policy was last modified by checking the "Last updated" legend at the top of the Privacy Policy. If the policies described in our Privacy Policy change in any material respect, we will notify you by posting the revised policy on our Site, by email, or by other means that we may choose and as required by applicable law. We may apply changes to information previously collected by us, to the extent permitted by law. If you do not agree to be bound by the terms of the new or modified Privacy Policy, you agree to immediately notify us that your personal information should be deleted. Your continued use of the Site after such changes become effective constitutes your acceptance of any such changes.

HOW TO CONTACT US

If you have any questions or comments regarding this Privacy Policy, you can contact us by email at: Contact@dinstinct.com. GENERAL

This Privacy Policy replaces all previous disclosures we may have provided to you about our privacy practices associated with the Site. The examples contained in this Privacy Policy are illustrations only and are not intended to be exhaustive.