{"id":25999,"date":"2026-08-10T18:37:44","date_gmt":"2026-08-10T14:37:44","guid":{"rendered":"https:\/\/me-en.kaspersky.com\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/25999\/"},"modified":"2026-08-10T18:37:44","modified_gmt":"2026-08-10T14:37:44","slug":"polyglot-file-formats-attack-examples-detection-prevention-advice","status":"publish","type":"post","link":"https:\/\/me-en.kaspersky.com\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/25999\/","title":{"rendered":"A dangerous matryoshka: everything needed to be known about polyglot malware files"},"content":{"rendered":"<p>Files built with the polyglot technique have been showing up more and more in cyberattacks in recent years. They let attackers slip malware past email filters and file scanners, deceive victims in phishing attacks, and complicate incident investigations. To pull this off, attackers deliberately construct a file that a system can interpret as different formats depending on which application opens it.\u00a0 A classic example is a file that can be handled as a PNG image or a ZIP archive. All it takes is changing the file\u2019s extension, or simply using one or another application to open it.<\/p>\n<p>Let\u2019s take a look at why it\u2019s even possible to create files like this, which format combinations have turned up in real-world attacks, and how organizations can protect themselves from this threat.<\/p>\n<h2>Why polyglot files are possible<\/h2>\n<p>The data formats behind polyglot files are seldom exotic. It all comes down to a clever combination of common formats that happen to be structurally compatible. Polyglots exploit at least one of the following quirks in certain file formats:<\/p>\n<ul>\n<li>Most file formats need decoding from the very first byte, but some require to read them from the end. The clearest example is a ZIP archive: a corrupted or missing beginning doesn\u2019t stop applications from reading the file, because all the needed headers actually sit at the end. This lets attackers simply glue two files together\u00a0\u2014 in the example above, a PNG and a ZIP. The beginning reads as a valid PNG image, while the end reads as a valid ZIP archive.<\/li>\n<li>Many formats work like Russian <em>matryoshka<\/em> nesting dolls: despite outwardly having a specific extension matching its intended usage, inside the file is essentially a ZIP archive containing the necessary data. This group includes modern office documents (DOCX\/XLSX\/PPTX), Android installation packages (APK), Java library files (JAR), and many others.<\/li>\n<li>Some formats have no strict structural requirements\u00a0\u2014 or their requirements are loose enough that the application that\u2019s processing the file can locate the fragment it needs even when that fragment isn\u2019t at the beginning.<\/li>\n<\/ul>\n<p>The <a href=\"https:\/\/github.com\/Polydet\/polyglot-database\" target=\"_blank\" rel=\"noopener nofollow\">Polydet<\/a> GitHub repository describes numerous examples of possible file combinations for building a polyglot. Under the MITRE classification, this technique falls under the Masquerading category (<a href=\"https:\/\/attack.mitre.org\/techniques\/T1036\/008\/\" target=\"_blank\" rel=\"noopener nofollow\">T1036.008<\/a>, Masquerade File Type).<\/p>\n<h2>Examples of polyglot files in known cyberattacks<\/h2>\n<p>Publicly available malware campaign analyses reveal all kinds of polyglots. Attackers adapt the entire attack scenario to fit a specific file type combination.<\/p>\n<p>The Head Mare group delivered the <a href=\"https:\/\/securelist.ru\/head-mare-attacks-with-phantompyramid\/112164\/\" target=\"_blank\" rel=\"noopener\">PhantomPyramid<\/a> malware as a ZIP attachment. The file consisted of Windows executable code (EXE) with a small ZIP archive glued onto the end. When the victim opened the archive, it contained a file with the extension PDF.LNK, which would then launch that same polyglot attachment\u00a0\u2014 this time as an executable file.<\/p>\n<p>In the attack <a href=\"https:\/\/blogs.jpcert.or.jp\/en\/2023\/08\/maldocinpdf.html\" target=\"_blank\" rel=\"noopener nofollow\">documented by JPCERT<\/a>, attackers created a file that started as a PDF and was detected as a PDF by most scanners but carried a DOC extension and opened in Office applications as a valid DOC file containing malicious macros.<\/p>\n<p>The attacks spreading the <a href=\"https:\/\/www.deepinstinct.com\/blog\/malicious-jars-and-polyglot-files-who-do-you-think-you-jar\" target=\"_blank\" rel=\"noopener nofollow\">StrRAT and Ratty<\/a> Trojans used a polyglot built from a signed Windows installer package (MSI) with malicious Java code (JAR) tacked onto the end.<\/p>\n<p>The <a href=\"https:\/\/medium.com\/%40DCSO_CyTec\/shortandmalicious-strelastealer-aims-for-mail-credentials-a4c3e78c8abc\" target=\"_blank\" rel=\"noopener nofollow\">StrelaStealer attacks<\/a> used a polyglot with an HTML extension: a Windows library (DLL) with a decoy HTML document glued onto the end. A shortcut in the archive launched the file twice: once via the start command (the equivalent of a double-click, which opened a browser showing the HTML document), and once via rundll32 (which launched the malicious DLL).<\/p>\n<p>In a simulated but elegant attack, researchers <a href=\"https:\/\/www.bleepingcomputer.com\/news\/security\/hackers-now-use-zip-file-concatenation-to-evade-detection\/\" target=\"_blank\" rel=\"noopener nofollow\">joined two ordinary ZIP files together<\/a> and found that different popular archive tools displayed the combined file differently: some showed only the first archive, some only the second, and some showed both at once as if it were a single archive with shared contents. If the attacker is familiar with the victim\u2019s infrastructure and knows what software they\u2019ve installed, they can use this combination to show security tools one file while showing the victim another.<\/p>\n<p>Attackers deployed a complex malware matryoshka in a <a href=\"https:\/\/unit42.paloaltonetworks.com\/polyglot-file-icedid-payload\/\" target=\"_blank\" rel=\"noopener nofollow\">campaign that distributed the IcedID infostealer<\/a>. They attached a ZIP archive to phishing emails; unpacking it produced an ISO file. That ISO, in turn, unpacked into a CHM (Windows Help) file built with the polyglot technique. When the victim opened it with the standard Windows Help tool, the file ran a JavaScript script embedded in the help content, which launched the standard <em>mshta<\/em> application (Microsoft HTML Application host) and pointed it at that same CHM file. The campaign\u2019s authors packed an HTA application inside the CHM file in such a way that its presence wouldn\u2019t interfere with reading the file as an innocuous help document. The HTA handler, for its part, obligingly skips over all the junk at the start of the file until it finds the HTA script.<\/p>\n<h2>How security tools handle polyglot files<\/h2>\n<p>The examples above make it clear how this double reading trick lets attackers deploy malware on a victim\u2019s computer. But what do email filters and EDR systems actually make of files like these? The answer depends entirely on the specific solution, so it needs to be checked \u2014 either by reviewing the vendor\u2019s technical documentation or by running a controlled test in corporate infrastructure with all due precautions in place.\u00a0 Speaking generally, only two points hold true across the board:<\/p>\n<ul>\n<li>Most security solutions don\u2019t trust a file\u2019s stated extension; instead, they check its beginning to determine the file\u2019s actual structure. That\u2019s why, in the attack described above, the PDF file with a DOC extension got analyzed as a harmless PDF, while the malicious macro sat in the glued-on DOC portion.<\/li>\n<li>If a file starts out as something harmless (for example, an image) and its extension matches, more sophisticated analysis probably won\u2019t be applied to it. Attackers can exploit this: instructions accompanying the file might tell the victim to rename it so that the system behavior ends up tied to the second payload rather than to the image.<\/li>\n<\/ul>\n<h2>How to protect an organization from polyglot file attacks<\/h2>\n<p>Defending against polyglots doesn\u2019t require complex technical or organizational solutions\u00a0\u2014 what it does require is solid, consistent security hygiene across the organization:<\/p>\n<ul>\n<li>Use closed allowlists of applications permitted to run on employee workstations. Exclude outdated Windows applications, unused Microsoft administrative tools, remote-access and file-transfer software, and whatever else is deemed potentially dangerous or obsolete.<\/li>\n<li>Use advanced <a href=\"https:\/\/www.kaspersky.com\/small-to-medium-business-security\/mail-server?icid=me-en_kdailyplacehold_acq_ona_smm__onl_b2b_kasperskydaily_wpplaceholder____ksms___\" target=\"_blank\" rel=\"noopener nofollow\">email security solutions<\/a> equipped with CDR (Content Disarm and Reconstruction technology, which disarms suspicious attachments and rebuilds them into safer versions) and detonation technology (running suspicious attachments in the isolated environment for analysis). Configure deep analysis for attachments that show outward signs of being polyglots: all archive and office files, files with nonstandard extensions, and so on.<\/li>\n<li>Likewise, configure the EDR solution to perform deep analysis of potential polyglots, too.<\/li>\n<li>Create monitoring rules that alert to unusual combinations of a process and the files handed to it for processing\u00a0\u2014 like a CHM file launched through <em>mshta<\/em>, or an HTML file launched through <em>rundll32<\/em>, as in the examples above.<\/li>\n<li>Add basic information about polyglots to employed security awareness program so users stay alert when instructed to change a file\u2019s extension or otherwise handle the file in an unusual way\u00a0\u2014 for example, open it in a specific application.<\/li>\n<\/ul>\n<input type=\"hidden\" class=\"category_for_banner\" value=\"kesb-trial\"><input type=\"hidden\" class=\"placeholder_for_banner\" data-cat_id=\"kesb-trial\" value=\"15341\">\n","protected":false},"excerpt":{"rendered":"<p>Attackers are crafting files that devices can read as two different document types at once, and using these &#8220;nesting dolls&#8221; to smuggle in malware. How to detect and neutralize these two-faced files?<\/p>\n","protected":false},"author":2722,"featured_media":26000,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1318,1916,1917],"tags":[2824,36,76,321,521,131,268],"class_list":["post-25999","post","type-post","status-publish","format-standard","has-post-thumbnail","category-business","category-enterprise","category-smb","tag-archives","tag-malware-2","tag-phishing","tag-technology","tag-threats","tag-tips","tag-vulnerabilities"],"hreflang":[{"hreflang":"en-ae","url":"https:\/\/me-en.kaspersky.com\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/25999\/"},{"hreflang":"en-in","url":"https:\/\/www.kaspersky.co.in\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/30971\/"},{"hreflang":"en-gb","url":"https:\/\/www.kaspersky.co.uk\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/30801\/"},{"hreflang":"ru","url":"https:\/\/www.kaspersky.ru\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/42481\/"},{"hreflang":"x-default","url":"https:\/\/www.kaspersky.com\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/56253\/"},{"hreflang":"ru-kz","url":"https:\/\/blog.kaspersky.kz\/polyglot-file-formats-attack-examples-detection-prevention-advice\/30936\/"},{"hreflang":"en-au","url":"https:\/\/www.kaspersky.com.au\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/36465\/"},{"hreflang":"en-za","url":"https:\/\/www.kaspersky.co.za\/blog\/polyglot-file-formats-attack-examples-detection-prevention-advice\/36380\/"}],"acf":[],"banners":"","maintag":{"url":"https:\/\/me-en.kaspersky.com\/blog\/tag\/malware-2\/","name":"malware"},"_links":{"self":[{"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/posts\/25999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/users\/2722"}],"replies":[{"embeddable":true,"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/comments?post=25999"}],"version-history":[{"count":0,"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/posts\/25999\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/media\/26000"}],"wp:attachment":[{"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/media?parent=25999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/categories?post=25999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/me-en.kaspersky.com\/blog\/wp-json\/wp\/v2\/tags?post=25999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}