rule win_formbook_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.formbook."
        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.formbook"
        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 = { 5b 03f1 5f c6040600 }
            // n = 4, score = 2200
            //   5b                   | pop                 ebx
            //   03f1                 | add                 esi, ecx
            //   5f                   | pop                 edi
            //   c6040600             | mov                 byte ptr [esi + eax], 0

        $sequence_1 = { 8b10 8d4d0c 51 52 50 e8???????? 83c418 }
            // n = 7, score = 2200
            //   8b10                 | mov                 edx, dword ptr [eax]
            //   8d4d0c               | lea                 ecx, [ebp + 0xc]
            //   51                   | push                ecx
            //   52                   | push                edx
            //   50                   | push                eax
            //   e8????????           |                     
            //   83c418               | add                 esp, 0x18

        $sequence_2 = { 85c0 7458 56 33f6 803b00 7413 46 }
            // n = 7, score = 2200
            //   85c0                 | test                eax, eax
            //   7458                 | je                  0x5a
            //   56                   | push                esi
            //   33f6                 | xor                 esi, esi
            //   803b00               | cmp                 byte ptr [ebx], 0
            //   7413                 | je                  0x15
            //   46                   | inc                 esi

        $sequence_3 = { e8???????? 53 8d55ec 52 8b16 8d85d8fcffff 50 }
            // n = 7, score = 2200
            //   e8????????           |                     
            //   53                   | push                ebx
            //   8d55ec               | lea                 edx, [ebp - 0x14]
            //   52                   | push                edx
            //   8b16                 | mov                 edx, dword ptr [esi]
            //   8d85d8fcffff         | lea                 eax, [ebp - 0x328]
            //   50                   | push                eax

        $sequence_4 = { e8???????? 8b45fc 50 57 e8???????? 8d8d50ffffff 8bd1 }
            // n = 7, score = 2200
            //   e8????????           |                     
            //   8b45fc               | mov                 eax, dword ptr [ebp - 4]
            //   50                   | push                eax
            //   57                   | push                edi
            //   e8????????           |                     
            //   8d8d50ffffff         | lea                 ecx, [ebp - 0xb0]
            //   8bd1                 | mov                 edx, ecx

        $sequence_5 = { 7439 8b4514 8d4814 51 8d908c020000 52 8d8820020000 }
            // n = 7, score = 2200
            //   7439                 | je                  0x3b
            //   8b4514               | mov                 eax, dword ptr [ebp + 0x14]
            //   8d4814               | lea                 ecx, [eax + 0x14]
            //   51                   | push                ecx
            //   8d908c020000         | lea                 edx, [eax + 0x28c]
            //   52                   | push                edx
            //   8d8820020000         | lea                 ecx, [eax + 0x220]

        $sequence_6 = { 894df8 e8???????? 830702 83c40c 830603 8b06 8a4c1801 }
            // n = 7, score = 2200
            //   894df8               | mov                 dword ptr [ebp - 8], ecx
            //   e8????????           |                     
            //   830702               | add                 dword ptr [edi], 2
            //   83c40c               | add                 esp, 0xc
            //   830603               | add                 dword ptr [esi], 3
            //   8b06                 | mov                 eax, dword ptr [esi]
            //   8a4c1801             | mov                 cl, byte ptr [eax + ebx + 1]

        $sequence_7 = { 83c404 3bfe 72ef 8b45fc 8b7d10 8b8f40020000 8b5514 }
            // n = 7, score = 2200
            //   83c404               | add                 esp, 4
            //   3bfe                 | cmp                 edi, esi
            //   72ef                 | jb                  0xfffffff1
            //   8b45fc               | mov                 eax, dword ptr [ebp - 4]
            //   8b7d10               | mov                 edi, dword ptr [ebp + 0x10]
            //   8b8f40020000         | mov                 ecx, dword ptr [edi + 0x240]
            //   8b5514               | mov                 edx, dword ptr [ebp + 0x14]

        $sequence_8 = { 813b50450000 7408 5f 33c0 5b }
            // n = 5, score = 2200
            //   813b50450000         | cmp                 dword ptr [ebx], 0x4550
            //   7408                 | je                  0xa
            //   5f                   | pop                 edi
            //   33c0                 | xor                 eax, eax
            //   5b                   | pop                 ebx

        $sequence_9 = { 89948db8feffff 0fb65007 c1e208 0bd7 0fb67809 c1e208 0bd7 }
            // n = 7, score = 2200
            //   89948db8feffff       | mov                 dword ptr [ebp + ecx*4 - 0x148], edx
            //   0fb65007             | movzx               edx, byte ptr [eax + 7]
            //   c1e208               | shl                 edx, 8
            //   0bd7                 | or                  edx, edi
            //   0fb67809             | movzx               edi, byte ptr [eax + 9]
            //   c1e208               | shl                 edx, 8
            //   0bd7                 | or                  edx, edi

    condition:
        7 of them and filesize < 371712
}