T1560.002 Elastic Security · Elastic

Detect Archive via Library in Elastic Security

Adversaries may compress or encrypt collected data prior to exfiltration using third-party or built-in programming libraries rather than standalone archival utilities. Libraries such as Python's zlib, bzip2, gzip, zipfile, and rarfile modules; .NET's System.IO.Compression (GZipStream, DeflateStream, ZipArchive); C libraries libzip and zlib; and platform-native libraries enable adversaries to compress and encrypt data programmatically within a running process. Because no separate archival utility process (7-Zip, WinRAR, tar) is spawned, this technique evades detections focused on command-line archivers. Malware families including TajMahal, LunarWeb, SeaDuke, BBSRAT, InvisiMole, and Denis have all used library-based compression to stage and exfiltrate collected data.

MITRE ATT&CK

Tactic
Collection
Technique
T1560 Archive Collected Data
Sub-technique
T1560.002 Archive via Library
Canonical reference
https://attack.mitre.org/techniques/T1560/002/

Elastic Detection Query

Elastic Security (Elastic)
eql
any where
  (
    event.category == "library" and
    dll.name in~ ("zlib.dll", "zlib1.dll", "zlibwapi.dll", "bzip2.dll", "libbzip2.dll", "libzip.dll", "minizip.dll") and
    not dll.path like~ "*System32*" and not dll.path like~ "*SysWOW64*" and
    not dll.path like~ "*7-Zip*" and not dll.path like~ "*WinRAR*" and
    not process.name in~ ("7z.exe", "7zG.exe", "WinRAR.exe", "msiexec.exe")
  ) or
  (
    event.category == "process" and event.type == "start" and
    process.name in~ ("powershell.exe", "pwsh.exe") and
    (
      process.command_line like~ "*IO.Compression*" or process.command_line like~ "*GZipStream*" or
      process.command_line like~ "*DeflateStream*" or process.command_line like~ "*ZipFile*" or
      process.command_line like~ "*ZipArchive*" or process.command_line like~ "*ICSharpCode*" or
      process.command_line like~ "*DotNetZip*"
    )
  ) or
  (
    event.category == "process" and event.type == "start" and
    process.name in~ ("python.exe", "python3.exe") and
    (
      process.command_line like~ "*import zlib*" or process.command_line like~ "*import bz2*" or
      process.command_line like~ "*import gzip*" or process.command_line like~ "*import zipfile*" or
      process.command_line like~ "*import rarfile*" or process.command_line like~ "*zlib.compress*" or
      process.command_line like~ "*import lzma*" or process.command_line like~ "*import tarfile*"
    )
  ) or
  (
    event.category == "file" and event.type == "creation" and
    (file.name like~ "*.gz" or file.name like~ "*.bz2" or file.name like~ "*.zlib" or
     file.name like~ "*.lzma" or file.name like~ "*.xz" or file.name like~ "*.lz") and
    (file.path like~ "*\\Temp\\*" or file.path like~ "*\\AppData\\*" or
     file.path like~ "*\\ProgramData\\*" or file.path like~ "*\\Users\\Public\\*") and
    process.name in~ ("python.exe", "python3.exe", "ruby.exe", "perl.exe", "node.exe",
                      "java.exe", "javaw.exe", "wscript.exe", "cscript.exe", "mshta.exe")
  )
high severity medium confidence

Detects T1560.002 Archive via Library across four behavioral branches using Elastic ECS event categories: compression DLL loads outside trusted paths by non-archiver processes; PowerShell invoking .NET System.IO.Compression or SharpZipLib classes; Python importing compression modules visible in command-line arguments; scripting interpreter creation of compressed archives in staging paths. Compatible with Elastic Endpoint 7.16+ and Sysmon via Winlogbeat with ECS normalization.

Data Sources

Elastic Endpoint Security (7.16+)Sysmon via Winlogbeat with ECS mappingAuditbeat (Linux coverage)

Required Tables

logs-endpoint.events.library-*logs-endpoint.events.process-*logs-endpoint.events.file-*winlogbeat-*

False Positives & Tuning

  • Python-based build tools (pip, setuptools, conda) that import zlib or gzip during dependency installation with imports visible in process command-line arguments passed to interpreter scripts
  • PowerShell deployment automation used by IT administrators that invokes System.IO.Compression to package software bundles or configuration payloads before staging on endpoints
  • Electron or Java desktop applications that ship bundled compression DLLs (zlib.dll, libbzip2.dll) in application-local directories outside System32 and load them during normal startup
Download portable Sigma rule (.yml)

Other platforms for T1560.002


Testing Methodology

Validate this detection against 4 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.

  1. Test 1Python zlib Compression of Sensitive File Collection

    Expected signal: Sysmon Event ID 1: Process Create with Image=python.exe, CommandLine containing 'import zlib' and 'zlib.compress'. Sysmon Event ID 11: File Create for %TEMP%\stage_df00.zlib. DeviceFileEvents: FileCreated action for the .zlib output file. DeviceFileEvents: FileRead action for the hosts file.

  2. Test 2PowerShell GZipStream Compression via System.IO.Compression

    Expected signal: Sysmon Event ID 1: Process Create with Image=powershell.exe, CommandLine containing 'IO.Compression', 'GZipStream', 'MemoryStream', and 'CompressionMode'. Sysmon Event ID 11: File Create for %TEMP%\stage_df00.gz. PowerShell ScriptBlock Log Event ID 4104 with full .NET compression code.

  3. Test 3Python bzip2 Multi-File Collection and Compression

    Expected signal: Syslog/auditd: python3 process execution with command line containing 'import bz2', 'tarfile', and output path in /tmp. File creation event for /tmp/stage_df00.tar.bz2. Auditd syscall events: openat for source files, write for output file. Linux process accounting: python3 with suspicious file access pattern.

  4. Test 4Python rarfile Library Compression (Third-Party Library)

    Expected signal: Sysmon Event ID 1: python.exe with CommandLine containing 'import zipfile', 'ZIP_DEFLATED', and temp path. Sysmon Event ID 11: File Create for %TEMP%\stage_df00_lib.zip. Potential child process for pip install subprocess. DeviceFileEvents shows file read of hosts file and write of .zip artifact.

Unlock Pro Content

Get the full detection package for T1560.002 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections