The DGA of NeksMiner
Advent of DGAs - Day 1- Unpacking
- Source of the Domains
- The domain generation algorithm
- Seeding
- Validation
- Number of Domains
- Python Reimplementation
- Characteristics
- Closing Thoughts
- References
This blog post is part of the Advent of DGAs series where I publish one post daily about a sample that looks like it uses a Domain Generation Algorithm.
I don't expect any sample to be relevant anymore and spend very little time on each sample, so don't expect the quality to be amazing.
Of course I'm also using AI to assist with the analysis and unpacking of the malware samples.
These are just unpolished notes. The content likely lacks clarity and structure; and the results might not be adequately verified and/or incomplete.
The DGA in this blog post has been implemented by the DGArchive project.
For more information about the malware in this blog post see the Malpedia entry on MyKings Spreader.
To kick off the Advent of DGAs, I’m investigating the following malware sample:
| Field | Value |
|---|---|
| MD5 | 35a2f6a984e3d3453cc9777927018898 |
| SHA1 | 55bf92d9223f239f9864c6065e8fa8a15c713315 |
| SHA256 | 32a7a218e9bdd36180df61d848e188db5bfe3a110f6ecefbce81ab7acbf3915a |
| File size | 45,601 bytes |
| Format | PE32 executable (GUI), Nullsoft Install System 2.46 installer |
| Architecture | x86 (32-bit) |
| Language | NSIS script (C installer stub) |
| Runtime | Not applicable |
| VirusTotal | View sample on VirusTotal |
It produces domains like these
4b7bd56df0[.]pwcc742fedae[.]pwcc62f84af7[.]pwdd33d82e35[.]pwcc968b6e88[.]pwd777cd4961[.]pwdc26a3abdb[.]pwd84a1c4368[.]pw
The sample is the first link in a six-stage delivery chain. Its only job is to download the next installer from a hardcoded host. Two stages later, a password-protected WinRAR SFX delivers a payload called dhelper.exe, which comes in two pieces and is reassembled on disk. dhelper.exe is protected with VMProtect. Once unpacked, it turns out to be a program built with HiAsm, a Russian visual programming environment that compiles drag-and-drop component graphs to Delphi/KOL. The final payload derives its command-and-control (C2) domains with a monthly, MD5-based DGA whose names consist of ten hexadecimal characters followed by .pw. All eight domains above come from that DGA.
What makes this case unusual is not the algorithm but how it is expressed. The DGA is a wiring diagram of roughly forty HiAsm components (a clock, a counter, several string concatenators, MD5 “Hashsum” blocks, “Copy” and “StrCase” blocks) whose event and data links are compiled into thousands of mov instructions that store method pointers in object fields. On top of that, the payload’s main form instantiates more than 2,600 components, most of them inert OpenGL primitives, which hide the handful of functional sub-graphs. Recovering the algorithm means rebuilding the graph from those stores and then checking the semantics of each component in the HiAsm runtime, where a couple of quirks change the result. The screenshot below shows the HiAsm development environment:

On the family question, the downloaders and the SFX match public reporting closely. Trend Micro documents the same file names (VID001.exe in a TempoRX folder, buff2.exe, dhelper.exe, jar2.exe, jare.7z1, temps.7z1), the same SFX passwords (-pBuff2jre_set7z, -pJavajre_set7z) and the same u.f…y.com download URLs under the names Worm.Win32.MALXMR.B and Worm.Win32.MALXMR.TIAOODFX. It lists Microsoft’s Worm:Win32/NeksMiner and Kaspersky’s Worm.NSIS.BitMin as aliases (Trend Micro, MALXMR.B; Trend Micro, MALXMR.TIAOODFX). A Triage run of our stage-2 (same SHA256) shows the full process tree. dhelper.exe -pJavajre_set7z spawns Javatemp\jar2.exe, which copies jare.7z1 + temps.7z1 into %APPDATA%\dhelper.exe and sets the Winlogon Shell value. In the same run, sibling payloads start an XMRig-style miner against nanopool (Triage 200309-2aee732m2a). Dr.Web tracks related droppers as Trojan.MulDrop8.11248 (Dr.Web). The download host f321y.com also appears as a download host in Kaspersky’s analysis of a Windows-based Mirai spreader (Securelist).
None of the public reports I found documents the DGA.
Unpacking
Each of the six layers hides the next one in a different way, and only the last one involves real cryptography. The figure below shows all stages on a single linear byte scale. The installers are tiny next to the two-megabyte SFX and payload:

The original sample (stage-0) and stage-2 share the same unmodified NSIS 2.46 stub. Everything interesting sits in the overlay: a 28-byte NSIS first header, a raw-deflate-compressed script header, and one data block holding the Inetc plug-in (stage-1, byte-identical in both installers). Inflating the script header shows how short the logic is. The script checks whether %APPDATA%\TempoRX\VID001.exe already exists, downloads f321y.com/vids.dat to %TEMP%\vids.exe with Inetc, and launches it with the argument -pJavajre_set7z. That argument is a WinRAR SFX password, so vids.dat is expected to be an SFX archive. Stage-2 is a larger version of the same script. It kills lsm.exe and pulls four payloads (buff2.dat, VID.dat, dhelper.dat, oneplus.dat) from u.f321y.com, each with its own password where needed.
Stage-3 is the file stage-2 saves as dhelper.exe (served as dhelper.dat). It is a stock WinRAR SFX module followed by a small SFX settings block and a RAR archive whose headers and data are encrypted. In the RAR 2.9 format this means AES-128 with a password-derived key, which is why the archive cannot even be listed without the password. Javajre_set7z opens it. The archive holds four entries: jar2.exe, an empty ini.jwd, a 100-byte jare.7z1 and a 2.1 MB temps.7z1. Neither .7z1 file is a 7-Zip archive or a valid PE on its own. jare.7z1 holds only the first 100 bytes of the final executable, its DOS and PE header, and temps.7z1 holds everything after that.
jar2.exe (stage-4) is an NSIS 3.01 installer with a solid bzip2 overlay. NSIS uses a modified bzip2 without the stream header, CRCs or randomisation bit, so standard tools reject it. I rebuilt a conforming stream around the original bits and read libbzip2’s output before it aborted on the fake checksum. The recovered script runs copy /b jare.7z1 + temps.7z1 %APPDATA%\dhelper.exe. It also copies the empty ini.jwd to cppredistx86.exe, sets the Winlogon Shell value to explorer.exe, %APPDATA%\dhelper.exe, and restarts the new binary. The concatenation is byte-identical to stage-5.
Stage-5 is VMProtect-packed. All code and data sections are virtual-only, the single raw section is high-entropy, and the resource directory contains nothing but icons. Stage-6 is a dump of the unpacked process image: the original Delphi sections are present in their virtual layout, but there is no import table, and every API thunk calls into VMProtect’s runtime section, which is absent from the dump.
| Stage | Size (bytes) | SHA256 |
|---|---|---|
| sample-0.bin | 45,601 | 32a7a218e9bdd36180df61d848e188db5bfe3a110f6ecefbce81ab7acbf3915a |
| stage-1.bin (inetc.dll) | 22,016 | 67eff17c53a78c8ec9a28f392b9bb93df3e74f96f6ecd87a333a482c36546b3e |
| stage-2.bin | 45,939 | 91d24ecf0751ba667efd17f9cff562882b08ea5d929f5b25ed17c9b581354b34 |
| stage-3.bin (dhelper.dat SFX) | 2,135,466 | 59044ddb0176647230470a213ad97f4385ae92d527d7a12f2f107bdc74c6ba06 |
| stage-4.bin (jar2.exe) | 39,222 | c0540983c65310c18c1070e9ba1b874307aa667147f382bf047a1e810e840cc3 |
| stage-5.bin (dhelper.exe) | 2,179,584 | 6864f1e5a0492e69eebfeab9e2ebd712363141d46102a96bfce02924081c7762 |
| stage-6.bin (unpacked dump) | 601,600 | d3d5f35e1082a84e218125297c2f2beb97136e5d3efbb21511a0d3cb17eff974 |
Source of the Domains
The domain generation algorithm
The DGA container is small once the HiAsm graph is drawn. A Time component formats the current date with the pattern M-Y. A StrCat prepends a seed supplied by the parent. A second StrCat appends the value of a Counter that runs from 0 to 999,999. The result goes into an MD5 Hashsum block. A Copy block cuts a prefix from the hex digest, a third StrCat appends the property string .pw, and after a case conversion the result is stored in a Memory component that the beacon reads as the domain. All that is completly unreadable when viewing the Delphi dissassembly:

The corresponding graph is much more accesible:

Two runtime details are interesting.
- First, the date formatter replaces each of the letters
Y M W D h m swith the matching field of aSYSTEMTIME, zero-padding values below ten, soM-YbecomesMM-YYYY, for example02-2018. The hex conversion usesIntToHex, so the digest is uppercase. - Second, the
Copycomponent is configured with Position 0 and Count 11, which looks like an eleven-character slice. HiAsm’s implementation, however, treats a non-positive position as an underflow. It addsPosition − 1to the count and clamps the position to 1, so the component actually returns the first ten characters. See lines 31 to 35 below:

The resulting domain generation algorithm is very simple:
domain(i) = UpperHex(MD5(seed + "MM-YYYY" + str(i)))[0:10] + ".pw"
A second branch of the same container chains six more MD5 operations over the domain, the date and intermediate values, and cuts a four-character token from the final digest. The beacon embeds this token in the URL and also uses it to compute the response it expects from the server.
Seeding
The parent supplies the seed from the configuration container renamed. That container loads a resource of type 100 named Str1 into a string list, decrypts each line with HiAsm’s RC6Cipher component keyed from the embedded string guremffffffffffff2323ffffkureguergnhj. The seed in the analysed sample is 0023abc1423:

Validation
The beacon does not simply take the first domain that resolves. After building the URL, it computes an expected response by chaining MD5 over the token, configuration entries and the hardware ID. It converts the HTTP body and compares the two. Only an exact match counts as success, which triggers a system-information report (GPU and CPU details sent to the same domain) and hands control to the payload’s command interpreter. A researcher who registers a predicted domain therefore receives requests, but cannot make the bot accept the domain without the configuration secrets.
Number of Domains
Iteration is driven by a Timer with a 4,000 ms interval. The first domain is generated with counter value 0 when the payload starts. Each tick advances the DGA counter, generates the next domain and makes one request. A second counter tracks the ticks. At 80 it resets the DGA counter, and the next tick continues with index 1, so index 0 is used only once. After three such rounds without a valid response, the beacon fires the same event used on success, sending control to the command interpreter, which has a local offline.txt path. So 81 candidate domains are generated per calendar month, requested at most one every four seconds.
Python Reimplementation
The implementation below follows the component graph exactly. It uses the seed 0023abc1423 as its default (overridable with --seed) and produces the 81 domains that one month allows.
#!/usr/bin/env python3
"""
Offline reference implementation of the domain generation algorithm
of NeksMiner
"""
import argparse
import datetime
import hashlib
SEED = "0023abc1423"
TLD = ".pw"
MAX_INDEX = 80 # counter values 0..80 are reachable before reset
PREFIX_LEN = 10 # Copy(pos=0, count=11) -> 10 characters
def generate(date, seed):
period = "{:02d}-{:d}".format(date.month, date.year)
for i in range(MAX_INDEX + 1):
data = (seed + period + str(i)).encode("latin-1")
digest = hashlib.md5(data).hexdigest().upper()
yield digest[:PREFIX_LEN].lower() + TLD
def main():
ap = argparse.ArgumentParser(description="dhelper.exe (.pw) DGA - offline reference")
ap.add_argument("-d", "--date", help="date as YYYY-MM-DD (default: today)")
ap.add_argument("-s", "--seed", default=SEED,
help="configuration seed (default: %(default)s)")
args = ap.parse_args()
date = (datetime.datetime.strptime(args.date, "%Y-%m-%d").date()
if args.date else datetime.date.today())
for domain in generate(date, args.seed):
print(domain)
if __name__ == "__main__":
main()
Take the first domain from the list at the top, 4b7bd56df0[.]pw, seen in June 2021. The bot concatenates the seed, the formatted month and the counter into 0023abc142306-20210 (seed 0023abc1423, period 06-2021, counter 0). The MD5 of that string starts with 4B7BD56DF0. The Copy component keeps those ten characters, the StrCat appends .pw, and the result is 4b7bd56df0[.]pw.
Characteristics
| property | value |
|---|---|
| type | TDD-H (time-dependent deterministic, hash-based) |
| seeding | time-dependent (month and year) plus a static configuration seed |
| generation scheme | hashing (MD5 of seed, date and counter, hex digest truncated) |
| seed | configuration string 0023abc1423 (line 43 of the RC6-encrypted Str1 resource) |
| domain change frequency | monthly |
| unique domains (per month) | 81 (counter values 0–80) |
| sequence | sequential (counter 0, then 1–80, repeating 1–80) |
| wait time between domains | 4 seconds (timer); fallback to the command interpreter after 3 rounds of 80 |
| top level domains | .pw |
| second level characters | hexadecimal 0-9a-f (MD5 digest) |
| regex | ^[0-9a-f]{10}\.pw$ |
| second level domain length | 10 |
Closing Thoughts
This is about as simple as a hash-based DGA gets, and so is the visual programming tool used to build it. Yet the resulting component graph logic is hard to follow, and VMProtect made the seed hard to recover. Together, they made a few lines’ worth of logic difficult enough to reverse that the algorithm remained undocumented for years.
References
- VirusTotal: sample-0.bin
- Trend Micro: Worm.Win32.MALXMR.B
- Trend Micro: Worm.Win32.MALXMR.TIAOODFX
- Triage 200309-2aee732m2a (stage-2.bin)
- ANY.RUN d2e8b77f… (dhelper.exe, 2018-07-17)
- MalwareURL name-server listing (8a66446ab5.pw)
- Guardicore Threat Intelligence (now redirects; content seen via search index)
- Dr.Web: Trojan.MulDrop8.11248
- Securelist: New(ish) Mirai Spreader Poses New Risks
