cover image for post 'The DGA of Tengu'

The DGA of Tengu

Advent of DGAs - Day 5

Today I am looking into Nozomi Networks’ write-up on Tengu, a Mirai-derived Linux botnet. The report mentions a domain generation algorithm but does not describe how it works: there is no seed, no character set and no list of top-level domains. This post reverse engineers the PowerPC build listed in that report to fill the gap:

FieldValue
MD5d0ffc06381cf9abde735956050751268
SHA1b249800066433c0a8bf23edae719133465247abc
SHA2563be83d3cefef01d421f2d02136b8e949b3b216239a9a0ada5394ffb55862005b
File size263916 bytes
FormatELF, 32-bit, big-endian
ArchitecturePowerPC
LanguageC
Runtimemusl libc, statically linked
VirusTotalView sample on VirusTotal

Tengu is a Mirai-derived Linux botnet. No DNS queries were supplied for this sample, so the interesting question is where its domains would come from.

The sample carries a real domain generation algorithm, but it never runs in this build, because the command-and-control (C2) address is a hardcoded IPv4 address. The DGA sits behind it as a fallback that only activates if the first candidate fails to resolve, which of course never happens for if the C2 is a straight IP.

The Hardcoded Endpoint

The sample is not packed, so there is no unpacking section: the code that selects the C2 is in the file as shipped.

Just before every connect() to the C2, the main loop calls a resolver routine through a function pointer. That routine, which I renamed select_c2_endpoint, overwrites the C2 socket address in place on each attempt. It assembles three candidate hostnames and tries them in order. The first is the configured endpoint string. The second is the same string with its first two dot-separated labels swapped, which looks like a sibling-name trick for hostnames and produces a second numeric address when applied to an IP. The third is the day’s DGA name.

The configured endpoint is not stored in clear. A short routine decodes eleven bytes with a stream keyed by a 32-bit linear congruential generator, using the glibc multiplier and increment, a fixed seed, and a position-dependent term. The output is 64.89.163[.]8. A second, independent copy of the same address is built in the main routine by XOR-ing four stack bytes with 0x22; this is the encoding Nozomi describes [1]. By my reading of the PowerPC code, that second copy is assembled in little-endian order and would give a byte-swapped address on this big-endian target, but it is overwritten before it is ever used, so the C2 is always 64.89.163[.]8 on port 9931.

// Decodes the 11-byte C2 endpoint (64.89.163.8)
void decode_c2_endpoint()
{
  int idx; // r9
  unsigned int lcg_state; // r8
  int i; // ctr

  idx = 0;
  lcg_state = 0x4DB8A1C2;
  for ( i = 11; i != 0; --i )
  {
    lcg_state = 0x41C64E6D * lcg_state + 12345;
    c2_endpoint_buf[idx] = ~(HIWORD(lcg_state) ^ c2_endpoint_enc[idx] ^ (idx * (idx + 29)));
    ++idx;
  }
  c2_endpoint_nul = 0;
  c2_endpoint_decoded = 1;
}

Each candidate goes through a replacement for gethostbyname: It calls inet_addr first and only falls back to a real DNS query when the string is not a dotted quad.

In the analysed sample, the first candidate is an IP, so the call succeeds immediately, an address is stored and the loop ends. No DNS packet is ever sent, and the generated DGA domain is never built into a query. The DGA is therefore live code but dormant configuration: it would take over only if a build decoded a hostname instead of an address and that hostname failed to resolve.

The DGA

The DGA is very sipmle. The seed is the current UTC date written as a decimal number, YYYYMMDD, computed from the gmtime fields of the current time. The PRNG is the classic LCG with multiplier 1103515245 and increment 12345 on an unsigned 32-bit state. Twelve iterations each yield one lowercase letter, taken from the upper 16 bits of the state modulo 26. One more iteration selects the top-level domain from a table of five, again from the upper 16 bits, modulo 5: .space, .online, .site, .xyz and .top. The result is a 12-letter second level domain under one of those TLDs.

Exactly one domain is produced per UTC day. For example, for 2026-12-04 the seed is 20261204, and the twelve letter steps give ukcbjbvulibv, the thirteenth step selects .site, and the domain is ukcbjbvulibv[.]site.

// Builds 3 C2 candidates: 
// - endpoint
// - endpoint with first two labels swapped
// - date-seeded DGA name
void select_c2_endpoint()
{
  char *c2_endpoint; // r29
  int label_count; // r27
  _BYTE *scan_ptr; // r9
  int ch; // r10
  _DWORD *tm; // r3
  int letter_idx; // r8
  unsigned int lcg_state; // r9
  int i; // ctr
  int cand_idx; // r28
  int candidate; // r27
  int *hostent; // r3
  int addr_list; // r26
  unsigned int addr_count; // r31
  unsigned int rnd; // r3
  int resolved_ip; // r9
  __int16 port_net; // r3
  _BYTE *label_slot; // r10
  int label_idx; // r26
  int label; // r4
  int *hostent_retry; // r3
  int *addr_ptr; // r10
  _BYTE work_buf[256]; // [sp+8h] [-368h] BYREF
  _BYTE swapped_candidate[256]; // [sp+108h] [-268h] BYREF
  _BYTE endpoint_candidate[256]; // [sp+208h] [-168h] BYREF
  char *label_tld_ptrs; // [sp+308h] [-68h] BYREF
  char *label_tld_ptrs_1; // [sp+30Ch] [-64h]
  char *label_tld_ptrs_2; // [sp+310h] [-60h]
  char *label_tld_ptrs_3; // [sp+314h] [-5Ch]
  char *label_tld_ptrs_4; // [sp+318h] [-58h]
  _DWORD candidates[4]; // [sp+328h] [-48h] BYREF
  __int64 now_utc; // [sp+338h] [-38h] BYREF

  c2_endpoint = get_c2_endpoint();
  strcpy_ret_len(a1: endpoint_candidate, a2: c2_endpoint);
  label_count = 1;
  strcpy_ret_len(a1: swapped_candidate, a2: endpoint_candidate);
  strcpy_ret_len(a1: work_buf, a2: swapped_candidate);
  scan_ptr = work_buf;
  while ( 1 )
  {
    ch = *scan_ptr;
    if ( *scan_ptr == 0 )
      break;
    ++scan_ptr;
    if ( ch == 46 )
    {
      *(scan_ptr - 1) = 0;
      if ( label_count <= 7 )
      {
        label_slot = &work_buf[4 * label_count++];
        *(label_slot + 192) = scan_ptr;
      }
    }
  }
  if ( label_count > 2 )
  {
    memset_zero(a1: swapped_candidate, a2: 256);
    label_idx = 3;
    strcpy_ret_len(a1: swapped_candidate, a2: label_tld_ptrs_1);
    strcat_ret_len(a1: swapped_candidate, a2: ".");
    strcat_ret_len(a1: swapped_candidate, a2: work_buf);
    strcat_ret_len(a1: swapped_candidate, a2: ".");
    strcat_ret_len(a1: swapped_candidate, a2: label_tld_ptrs_2);
    while ( label_count != label_idx )
    {
      strcat_ret_len(a1: swapped_candidate, a2: ".");
      label = (&label_tld_ptrs)[label_idx++];
      strcat_ret_len(a1: swapped_candidate, a2: label);
    }
  }
  candidates[0] = endpoint_candidate;
  candidates[1] = swapped_candidate;
  now_utc = _time64(a1: 0);
  tm = gmtime_utc(a1: &now_utc);
  letter_idx = 0;
  lcg_state = tm[3] + 19000000 + 10000 * tm[5] + 100 * (tm[4] + 1);
  for ( i = 12; i != 0; --i )
  {
    lcg_state = 1103515245 * lcg_state + 12345;
    work_buf[letter_idx++] = BYTE1(lcg_state) - 26 * (lcg_state / 0x1A0000) + 97;
  }
  cand_idx = 0;
  label_tld_ptrs = dga_tld_table[0];
  label_tld_ptrs_4 = off_501C8;
  label_tld_ptrs_1 = off_501BC[0];
  label_tld_ptrs_2 = off_501C0[0];
  label_tld_ptrs_3 = off_501C4[0];
  work_buf[12] = 0;
  strcat_ret_len(a1: work_buf, a2: (&label_tld_ptrs)[((1103515245 * lcg_state + 12345) >> 16) % 5]);
  candidates[2] = work_buf;
  do
  {
    candidate = candidates[cand_idx];
    hostent = resolve_host(a1: candidate);
    if ( hostent != nullptr && hostent[2] == 2 )
    {
      addr_list = hostent[4];
      for ( addr_count = 0; *(addr_list + 4 * addr_count) != 0; ++addr_count )
        ;
      if ( addr_count != 0 )
      {
        rnd = xorshift128_rand();
        memcpy_bytes(result: &label_tld_ptrs, a2: *(addr_list + 4 * (rnd % addr_count)), a3: 4);
        resolved_ip = label_tld_ptrs;
LABEL_13:
        c2_addr_in_addr = resolved_ip;
        goto LABEL_14;
      }
    }
    resolved_ip = inet_addr(a1: candidate);
    if ( resolved_ip == -1 )
    {
      hostent_retry = resolve_host(a1: candidate);
      resolved_ip = 0;
      if ( hostent_retry != nullptr )
      {
        addr_ptr = *hostent_retry[4];
        if ( addr_ptr != nullptr )
          resolved_ip = *addr_ptr;
      }
    }
    if ( (resolved_ip - 1) <= 0xFFFFFFFD )
      goto LABEL_13;
    ++cand_idx;
  }
  while ( cand_idx != 3 );
  c2_addr_in_addr = inet_addr(a1: c2_endpoint);
LABEL_14:
  htons_nop_be();
  c2_addr_port = port_net;
}

If a hostname did reach the resolver, a minimal UDP query for an A record goes to a hardcoded public resolver at 8.8.8.8, with a three-second wait and the first A record taken from the answer. When the resolver returns several addresses, one is picked at random.

Python Reimplementation

The script generates the single daily domain. -d takes an optional date:

#!/usr/bin/env python3
import argparse
import re
from datetime import date, datetime, timezone

TLDS = (".space", ".online", ".site", ".xyz", ".top")
MULT = 1103515245
INC = 12345


def parse_date(value):
    if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", value):
        raise argparse.ArgumentTypeError("expected YYYY-MM-DD")
    try:
        return date.fromisoformat(value)
    except ValueError as exc:
        raise argparse.ArgumentTypeError(str(exc))


def lcg(state):
    return (MULT * state + INC) & 0xFFFFFFFF


def seed_from_date(d):
    return d.year * 10000 + d.month * 100 + d.day


def generate(seed):
    state = seed & 0xFFFFFFFF
    letters = []
    for _ in range(12):
        state = lcg(state)
        letters.append(chr(ord("a") + (state >> 16) % 26))
    state = lcg(state)
    return "".join(letters) + TLDS[(state >> 16) % len(TLDS)]


def main():
    ap = argparse.ArgumentParser(description="Tengu daily DGA (offline)")
    ap.add_argument("-d", "--date", type=parse_date,
                    default=datetime.now(timezone.utc).date())
    args = ap.parse_args()
    seed = seed_from_date(args.date) 
    print(generate(seed))


if __name__ == "__main__":
    main()

Characteristics

propertyvalue
typeTDD-A-N
seedingtime-dependent (UTC date)
generation schemearithmetic (LCG)
seedcurrent date as YYYYMMDD
domain change frequencyevery day
unique domains (per day)1
sequencesingle domain, no sequence
wait time between domainsnone between candidates; 10 s sleep after a failed connect
top level domains.space, .online, .site, .xyz, .top
second level characterslowercase a–z only
regex^[a-z]{12}\.(space|online|site|xyz|top)$
second level domain length12

Closing Thoughts

Tengu has a DGA, but because the operator hardcoded an IP, it is dead weight. It would give the C2 a day-by-day fallback if the endpoint were ever swapped for a hostname.

Indicators of Compromise

TypeValueClassification
IPv4:port64.89.163[.]8:9931Extracted (C2)
IPv4:port64.89.163[.]8:8080Extracted (IPFS gateway)
Domainukcbjbvulibv[.]siteDerived, 2026-12-04, not observed
Path/dev/shm/.journalExtracted
Path/etc/init.d/tenguExtracted
MD5d0ffc06381cf9abde735956050751268Analysed sample
SHA1b249800066433c0a8bf23edae719133465247abcAnalysed sample
SHA2563be83d3cefef01d421f2d02136b8e949b3b216239a9a0ada5394ffb55862005bAnalysed sample

References

  1. Nozomi Networks Labs, “Tengu: A Modernized Mirai That Doesn’t Want to Leave”, 27 July 2026.
  2. FortiGuard Labs, “Multi-Functional Linux Botnet ‘Evooo1Bot’”, 13 August 2026 (compared and ruled out).
  3. Sample on VirusTotal.
  4. Accompanying files: analysis-notes.md, dga.py, extract_domains.py, rule.yar, hashes.csv, iocs.csv.

About this post

Table of Contents
Advent of DGAs

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.

Disclaimer

These are just unpolished notes. The content likely lacks clarity and structure; and the results might not be adequately verified and/or incomplete.