rule win_megumin_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.megumin."
        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.megumin"
        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 = { 7555 6a0f b9???????? e8???????? 8bc8 e8???????? 8bc8 }
            // n = 7, score = 200
            //   7555                 | jne                 0x57
            //   6a0f                 | push                0xf
            //   b9????????           |                     
            //   e8????????           |                     
            //   8bc8                 | mov                 ecx, eax
            //   e8????????           |                     
            //   8bc8                 | mov                 ecx, eax

        $sequence_1 = { e8???????? 8d55a0 c645fc07 8d4dd4 e8???????? 8d4da0 c645fc05 }
            // n = 7, score = 200
            //   e8????????           |                     
            //   8d55a0               | lea                 edx, [ebp - 0x60]
            //   c645fc07             | mov                 byte ptr [ebp - 4], 7
            //   8d4dd4               | lea                 ecx, [ebp - 0x2c]
            //   e8????????           |                     
            //   8d4da0               | lea                 ecx, [ebp - 0x60]
            //   c645fc05             | mov                 byte ptr [ebp - 4], 5

        $sequence_2 = { 3bd0 734e 2bc2 83f804 7247 83f823 7742 }
            // n = 7, score = 200
            //   3bd0                 | cmp                 edx, eax
            //   734e                 | jae                 0x50
            //   2bc2                 | sub                 eax, edx
            //   83f804               | cmp                 eax, 4
            //   7247                 | jb                  0x49
            //   83f823               | cmp                 eax, 0x23
            //   7742                 | ja                  0x44

        $sequence_3 = { 7202 8b00 50 8d8d58feffff e8???????? 8d8d3cfeffff e8???????? }
            // n = 7, score = 200
            //   7202                 | jb                  4
            //   8b00                 | mov                 eax, dword ptr [eax]
            //   50                   | push                eax
            //   8d8d58feffff         | lea                 ecx, [ebp - 0x1a8]
            //   e8????????           |                     
            //   8d8d3cfeffff         | lea                 ecx, [ebp - 0x1c4]
            //   e8????????           |                     

        $sequence_4 = { 8b5d10 3bce 7504 3bd7 7420 803b00 8b01 }
            // n = 7, score = 200
            //   8b5d10               | mov                 ebx, dword ptr [ebp + 0x10]
            //   3bce                 | cmp                 ecx, esi
            //   7504                 | jne                 6
            //   3bd7                 | cmp                 edx, edi
            //   7420                 | je                  0x22
            //   803b00               | cmp                 byte ptr [ebx], 0
            //   8b01                 | mov                 eax, dword ptr [ecx]

        $sequence_5 = { 53 56 8bf1 57 8b4608 2500010000 7414 }
            // n = 7, score = 200
            //   53                   | push                ebx
            //   56                   | push                esi
            //   8bf1                 | mov                 esi, ecx
            //   57                   | push                edi
            //   8b4608               | mov                 eax, dword ptr [esi + 8]
            //   2500010000           | and                 eax, 0x100
            //   7414                 | je                  0x16

        $sequence_6 = { 8b4a20 755f ff34c8 8b4208 8bce d1e8 2401 }
            // n = 7, score = 200
            //   8b4a20               | mov                 ecx, dword ptr [edx + 0x20]
            //   755f                 | jne                 0x61
            //   ff34c8               | push                dword ptr [eax + ecx*8]
            //   8b4208               | mov                 eax, dword ptr [edx + 8]
            //   8bce                 | mov                 ecx, esi
            //   d1e8                 | shr                 eax, 1
            //   2401                 | and                 al, 1

        $sequence_7 = { 51 57 8d4dbc e8???????? c745fc00000000 8d4dbc 8b7dd0 }
            // n = 7, score = 200
            //   51                   | push                ecx
            //   57                   | push                edi
            //   8d4dbc               | lea                 ecx, [ebp - 0x44]
            //   e8????????           |                     
            //   c745fc00000000       | mov                 dword ptr [ebp - 4], 0
            //   8d4dbc               | lea                 ecx, [ebp - 0x44]
            //   8b7dd0               | mov                 edi, dword ptr [ebp - 0x30]

        $sequence_8 = { ffd6 5e 5f 5b c3 57 8bf9 }
            // n = 7, score = 200
            //   ffd6                 | call                esi
            //   5e                   | pop                 esi
            //   5f                   | pop                 edi
            //   5b                   | pop                 ebx
            //   c3                   | ret                 
            //   57                   | push                edi
            //   8bf9                 | mov                 edi, ecx

        $sequence_9 = { 8b7dbc 0f99c1 884dc3 85ff 7447 83c8ff f00fc14708 }
            // n = 7, score = 200
            //   8b7dbc               | mov                 edi, dword ptr [ebp - 0x44]
            //   0f99c1               | setns               cl
            //   884dc3               | mov                 byte ptr [ebp - 0x3d], cl
            //   85ff                 | test                edi, edi
            //   7447                 | je                  0x49
            //   83c8ff               | or                  eax, 0xffffffff
            //   f00fc14708           | lock xadd           dword ptr [edi + 8], eax

    condition:
        7 of them and filesize < 1007616
}