rule win_graftor_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.graftor."
        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.graftor"
        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 = { ff15???????? 85c0 0f8446020000 ffb574d7ffff 8d85f0d7ffff 50 8db548d7ffff }
            // n = 7, score = 100
            //   ff15????????         |                     
            //   85c0                 | test                eax, eax
            //   0f8446020000         | je                  0x24c
            //   ffb574d7ffff         | push                dword ptr [ebp - 0x288c]
            //   8d85f0d7ffff         | lea                 eax, [ebp - 0x2810]
            //   50                   | push                eax
            //   8db548d7ffff         | lea                 esi, [ebp - 0x28b8]

        $sequence_1 = { 8db4246c010000 c684245803000075 e8???????? e8???????? 399c2424010000 }
            // n = 5, score = 100
            //   8db4246c010000       | lea                 esi, [esp + 0x16c]
            //   c684245803000075     | mov                 byte ptr [esp + 0x358], 0x75
            //   e8????????           |                     
            //   e8????????           |                     
            //   399c2424010000       | cmp                 dword ptr [esp + 0x124], ebx

        $sequence_2 = { 897c2414 895c2410 395e14 7511 687ce14c00 e8???????? 8bc7 }
            // n = 7, score = 100
            //   897c2414             | mov                 dword ptr [esp + 0x14], edi
            //   895c2410             | mov                 dword ptr [esp + 0x10], ebx
            //   395e14               | cmp                 dword ptr [esi + 0x14], ebx
            //   7511                 | jne                 0x13
            //   687ce14c00           | push                0x4ce17c
            //   e8????????           |                     
            //   8bc7                 | mov                 eax, edi

        $sequence_3 = { e8???????? 393d???????? 7513 83ec1c 8bf4 89642444 }
            // n = 6, score = 100
            //   e8????????           |                     
            //   393d????????         |                     
            //   7513                 | jne                 0x15
            //   83ec1c               | sub                 esp, 0x1c
            //   8bf4                 | mov                 esi, esp
            //   89642444             | mov                 dword ptr [esp + 0x44], esp

        $sequence_4 = { 8d8578ffffff 50 8d85d4feffff 68c8aa4d00 50 c645fc0a e8???????? }
            // n = 7, score = 100
            //   8d8578ffffff         | lea                 eax, [ebp - 0x88]
            //   50                   | push                eax
            //   8d85d4feffff         | lea                 eax, [ebp - 0x12c]
            //   68c8aa4d00           | push                0x4daac8
            //   50                   | push                eax
            //   c645fc0a             | mov                 byte ptr [ebp - 4], 0xa
            //   e8????????           |                     

        $sequence_5 = { ff15???????? ff75fc 8b35???????? ffd6 8d45fc 50 ff75ec }
            // n = 7, score = 100
            //   ff15????????         |                     
            //   ff75fc               | push                dword ptr [ebp - 4]
            //   8b35????????         |                     
            //   ffd6                 | call                esi
            //   8d45fc               | lea                 eax, [ebp - 4]
            //   50                   | push                eax
            //   ff75ec               | push                dword ptr [ebp - 0x14]

        $sequence_6 = { 50 51 c645fc03 e8???????? 8b0d???????? 83c40c e8???????? }
            // n = 7, score = 100
            //   50                   | push                eax
            //   51                   | push                ecx
            //   c645fc03             | mov                 byte ptr [ebp - 4], 3
            //   e8????????           |                     
            //   8b0d????????         |                     
            //   83c40c               | add                 esp, 0xc
            //   e8????????           |                     

        $sequence_7 = { 85c0 7c23 8b7dec 240f c0e304 0ac3 0fb6c0 }
            // n = 7, score = 100
            //   85c0                 | test                eax, eax
            //   7c23                 | jl                  0x25
            //   8b7dec               | mov                 edi, dword ptr [ebp - 0x14]
            //   240f                 | and                 al, 0xf
            //   c0e304               | shl                 bl, 4
            //   0ac3                 | or                  al, bl
            //   0fb6c0               | movzx               eax, al

        $sequence_8 = { ff5144 85c0 0f8cd5f8ffff 8b857cffffff 8d956cffffff 52 }
            // n = 6, score = 100
            //   ff5144               | call                dword ptr [ecx + 0x44]
            //   85c0                 | test                eax, eax
            //   0f8cd5f8ffff         | jl                  0xfffff8db
            //   8b857cffffff         | mov                 eax, dword ptr [ebp - 0x84]
            //   8d956cffffff         | lea                 edx, [ebp - 0x94]
            //   52                   | push                edx

        $sequence_9 = { a1???????? 33c5 8945fc 8b4508 83a5f4dfffff00 83781808 }
            // n = 6, score = 100
            //   a1????????           |                     
            //   33c5                 | xor                 eax, ebp
            //   8945fc               | mov                 dword ptr [ebp - 4], eax
            //   8b4508               | mov                 eax, dword ptr [ebp + 8]
            //   83a5f4dfffff00       | and                 dword ptr [ebp - 0x200c], 0
            //   83781808             | cmp                 dword ptr [eax + 0x18], 8

    condition:
        7 of them and filesize < 294912
}