{"id":797,"date":"2012-03-10T18:21:13","date_gmt":"2012-03-10T18:21:13","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=797"},"modified":"2012-04-04T14:41:44","modified_gmt":"2012-04-04T14:41:44","slug":"mz-file-format-flavours-malware","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2012\/03\/10\/mz-file-format-flavours-malware\/","title":{"rendered":"MZ File format flavors &#038; malware"},"content":{"rendered":"<p>Analyzing files starting with the &#8216;MZ&#8217; magic value can be called a \u201cdaily bread\u201d for reverse engineers. The reason for this is pretty simple \u2013 if you look at the top of your average executable file you will notice that majority of them start with these 2 magic letters. Since it\u2019s the most common file format that malware analysts work with, in this post I will have a deeper (but still high-level) look at files of this type.<\/p>\n<p>There are so many types of executables starting with &#8216;MZ&#8217; that looking at the first 2 bytes is often not enough. In fact, there are so many various flavors of MZ files, that it\u2019s pretty hard to list them all, but let\u2019s try anyway:<\/p>\n<ul>\n<li>16-bit, 32-bit and 64-bit executables<\/li>\n<li>PC and mobile executables<\/li>\n<li>x32, x64, IA64, AMD64, etc.<\/li>\n<li>.NET<\/li>\n<li>Executables for Windows 3.1 and Windows 9x\/NT ( &#8216;NE&#8217; vs. &#8216;PE&#8217;)<\/li>\n<li>Drivers for Windows 3.1\/Windows 9x and Windows NT ( &#8216;LE&#8217; vs. &#8216;PE&#8217;)<\/li>\n<li>GUI applications and console applications<\/li>\n<li>User mode executables (processes, services \u2013 usually saved as files with the .exe, .scr, .cpl extension) and Dynamically Loaded Libraries (saved as files with .dll extension; others are saved as .ocx, .vbx, etc.)<\/li>\n<li>User mode executables (processes) and services (service processes)<\/li>\n<li>Kernel mode drivers (.sys, .drv) and kernel mode libraries (also saved with a .sys file extension)<\/li>\n<li>Standard DLLs and COM DLLs (e.g. ActiveX, Browser Helper Objects)<\/li>\n<li>Standard DLLs and Service DLLs (loaded by svchost.exe)<\/li>\n<li>Dedicated DLL files (e.g. LSP, Shell extensions, deskbands, Plugins, MSGINA, windows hooks, etc.)<\/li>\n<li>Old-school standalone executables (&#8216;DOS type&#8217;)<\/li>\n<li>Files produced by various compilers: Microsoft Visual Studio, Borland Delphi, Visual Basic, mingw32, gcc and many more.<\/li>\n<li>Files produced by various script compilers e.g. perl2exe, py2exe, php2exe, AutoIt, WinBatch, etc.<\/li>\n<li>Installers e.g. Nullsoft, InnoSetup, Wise, Vyse, etc.,<\/li>\n<li>Resource-only files e.g. fonts<\/li>\n<li>Executables with overlays<\/li>\n<li>Executables with appended data<\/li>\n<li>&#8230;<\/li>\n<\/ul>\n<p>From malware analysis point of view, we have to also include another categorization as well, which is very much related to \u201cextra\u201d file properties often added by malware authors, including:<\/p>\n<ul>\n<li>compression (packing)<\/li>\n<li>encryption<\/li>\n<li>wrapping<\/li>\n<li>obfuscation<\/li>\n<li>protection<\/li>\n<li>corruption<\/li>\n<li>virtualization<\/li>\n<li>misleading information<\/li>\n<li>anti-techniques<\/li>\n<\/ul>\n<p>Finally, we can use as a classifier the presence and the content of the following metadata:<\/p>\n<ul>\n<li>Rich header<\/li>\n<li>Number of Sections<\/li>\n<li>Characteristics of Sections (writable, readable, executable, etc.)<\/li>\n<li>Characteristics of Import and export table<\/li>\n<li>Debugging information (including timestamps and paths to .PDB files)<\/li>\n<li>Resources information<\/li>\n<li>Digital signatures<\/li>\n<li>Appended data<\/li>\n<li>Compiler specific information e.g. debug information, or PACKAGEINFO for Delphi application<\/li>\n<\/ul>\n<p>It is super high-level, but as you may guess, analyzing any single executable listed on this list requires completely different approach.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Update #1:<\/strong><\/p>\n<p>fixed a mistake related to NE\/PE &#8211; NE files have been replaced by PE files on 32-bit Windows; thx to Imaginative (one of the best reversers I know) for picking it up \ud83d\ude42<\/p>\n<p><strong>Update #2:<\/strong><\/p>\n<p>Just to clarify: NE files still run on Win XP + this file format is being used to store .fon files (Thx Ange @ <a href=\"http:\/\/corkami.com\">corkami.com<\/a> &#8211; he is one of the best binary magicians out there!)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Analyzing files starting with the &#8216;MZ&#8217; magic value can be called a \u201cdaily bread\u201d for reverse engineers. The reason for this is pretty simple \u2013 if you look at the top of your average executable file you will notice that &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2012\/03\/10\/mz-file-format-flavours-malware\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/797"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=797"}],"version-history":[{"count":13,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":801,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/797\/revisions\/801"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}