rule win_lemonduck_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.lemonduck."
        info = "autogenerated rule brought to you by yara-signator"
        tool = "yara-signator v0.6.0"
        signator_config = "callsandjumps;datarefs;binvalue"
        malpedia_reference = "https://malpedia.caad.fkie.fraunhofer.de/details/win.lemonduck"
        malpedia_rule_date = "20260916"
        malpedia_hash = "53a643781c18e08f4a50949af60172d837a0b6f6"
        malpedia_version = "20260917"
        malpedia_license = "CC BY-SA 4.0"
        malpedia_sharing = "TLP:WHITE"

    /* DISCLAIMER
     * The strings used in this rule have been automatically selected from the
     * disassembly of memory dumps and unpacked files, using YARA-Signator.
     * The code and documentation is published here:
     * https://github.com/fxb-cocacoding/yara-signator
     * As Malpedia is used as data source, please note that for a given
     * number of families, only single samples are documented.
     * This likely impacts the degree of generalization these rules will offer.
     * Take the described generation method also into consideration when you
     * apply the rules in your use cases and assign them confidence levels.
     */


    strings:
        $sequence_0 = { 751c e8???????? 85c0 7405 4c8bc5 eb0e 4c8d05ebf21800 }
            // n = 7, score = 100
            //   751c                 | sub                 ecx, 1
            //   e8????????           |                     
            //   85c0                 | je                  0xd7
            //   7405                 | cmp                 ecx, 1
            //   4c8bc5               | jne                 0xee
            //   eb0e                 | je                  0xf6
            //   4c8d05ebf21800       | cmp                 ecx, 0xe

        $sequence_1 = { f6c101 746f 483b7b18 7458 488b47f0 4885c0 743e }
            // n = 7, score = 100
            //   f6c101               | dec                 eax
            //   746f                 | cmp                 eax, ebx
            //   483b7b18             | je                  0x32e
            //   7458                 | dec                 eax
            //   488b47f0             | mov                 ecx, edi
            //   4885c0               | dec                 eax
            //   743e                 | sub                 ecx, eax

        $sequence_2 = { e8???????? 4c8d0d81550200 b915000000 4c8d056d550200 488d156e550200 e8???????? 4c8d0d82550200 }
            // n = 7, score = 100
            //   e8????????           |                     
            //   4c8d0d81550200       | mov                 ecx, esi
            //   b915000000           | dec                 eax
            //   4c8d056d550200       | mov                 esi, eax
            //   488d156e550200       | dec                 eax
            //   e8????????           |                     
            //   4c8d0d82550200       | lea                 edx, [ecx + ecx*2]

        $sequence_3 = { eb02 32c0 84c0 0f85d8000000 b918000000 e8???????? 488bd8 }
            // n = 7, score = 100
            //   eb02                 | movd                ecx, mm0
            //   32c0                 | dec                 esp
            //   84c0                 | mov                 ebp, edi
            //   0f85d8000000         | movq                qword ptr [ebp - 8], xmm0
            //   b918000000           | movdqa              xmm0, xmmword ptr [esp + 0x50]
            //   e8????????           |                     
            //   488bd8               | movdqa              xmm0, xmmword ptr [esp + 0x40]

        $sequence_4 = { 664c0f6ec8 488b4650 48334640 66440f6cc8 66480f6ec1 660f7f7580 488d8df0100000 }
            // n = 7, score = 100
            //   664c0f6ec8           | movd                mm1, edx
            //   488b4650             | punpckldq           xmm2, xmm1
            //   48334640             | mov                 ecx, dword ptr [edx + ecx*4 + 0x169d50]
            //   66440f6cc8           | xor                 ecx, dword ptr [edx + esi*4 + 0x169d50]
            //   66480f6ec1           | inc                 ecx
            //   660f7f7580           | xor                 ecx, esp
            //   488d8df0100000       | movd                xmm3, ecx

        $sequence_5 = { eb03 41311b 410fb6819a000000 418b1c82 410fb68199000000 4d8d1c82 410fb68198000000 }
            // n = 7, score = 100
            //   eb03                 | dec                 eax
            //   41311b               | mov                 ecx, ebx
            //   410fb6819a000000     | mov                 dword ptr [ebx + 0x3c], 1
            //   418b1c82             | or                  dword ptr [ebx + 0x58], 0x10000
            //   410fb68199000000     | inc                 dword ptr [ebx + 0x78]
            //   4d8d1c82             | dec                 eax
            //   410fb68198000000     | mov                 ebx, dword ptr [esp + 0x40]

        $sequence_6 = { 4d8bef 89942488000000 eb5c 488d15229b1500 498bcd 48c1e105 8b441108 }
            // n = 7, score = 100
            //   4d8bef               | mov                 eax, dword ptr [esp + 0x58]
            //   89942488000000       | dec                 ecx
            //   eb5c                 | mov                 edx, ebp
            //   488d15229b1500       | dec                 eax
            //   498bcd               | mov                 dword ptr [esp + 0x30], eax
            //   48c1e105             | dec                 eax
            //   8b441108             | mov                 ecx, esi

        $sequence_7 = { eb51 418b813c010000 03c3 410103 eb43 41291b eb3e }
            // n = 7, score = 100
            //   eb51                 | dec                 eax
            //   418b813c010000       | lea                 ecx, [esp + 0x38]
            //   03c3                 | int3                
            //   410103               | dec                 eax
            //   eb43                 | lea                 edx, [0x6c3df]
            //   41291b               | dec                 eax
            //   eb3e                 | lea                 ecx, [esp + 0x20]

        $sequence_8 = { 7426 0f1f4000 0f1f840000000000 498b0cd2 488b4128 80780c00 7509 }
            // n = 7, score = 100
            //   7426                 | ja                  0xd37
            //   0f1f4000             | jb                  0x5f5
            //   0f1f840000000000     | dec                 eax
            //   498b0cd2             | add                 edx, 0x27
            //   488b4128             | dec                 ebp
            //   80780c00             | mov                 edi, dword ptr [edi - 8]
            //   7509                 | dec                 ecx

        $sequence_9 = { 83f802 0f86b6000000 83f90b 0f84ad000000 8d82fcf3ffff a9fdffffff 0f849c000000 }
            // n = 7, score = 100
            //   83f802               | mov                 dword ptr [ebx + 0x18], eax
            //   0f86b6000000         | jge                 0x245
            //   83f90b               | dec                 eax
            //   0f84ad000000         | mov                 ecx, edi
            //   8d82fcf3ffff         | dec                 eax
            //   a9fdffffff           | mov                 ecx, dword ptr [edi + 0x18]
            //   0f849c000000         | dec                 eax

    condition:
        7 of them and filesize < 10011648
}