rule win_blackenergy_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-05-04"
        version = "1"
        description = "Detects win.blackenergy."
        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.blackenergy"
        malpedia_rule_date = "20260422"
        malpedia_hash = "a182e35da64e6d71cb55f125c4d4225196523f14"
        malpedia_version = "20260504"
        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 = { 75df 8b5d0c 3bde 0f84c2000000 8b44240c 53 ff742418 }
            // n = 7, score = 200
            //   75df                 | jne                 0xffffffe1
            //   8b5d0c               | mov                 ebx, dword ptr [ebp + 0xc]
            //   3bde                 | cmp                 ebx, esi
            //   0f84c2000000         | je                  0xc8
            //   8b44240c             | mov                 eax, dword ptr [esp + 0xc]
            //   53                   | push                ebx
            //   ff742418             | push                dword ptr [esp + 0x18]

        $sequence_1 = { 57 57 68000000c0 ff7314 ff15???????? 894318 8b4318 }
            // n = 7, score = 200
            //   57                   | push                edi
            //   57                   | push                edi
            //   68000000c0           | push                0xc0000000
            //   ff7314               | push                dword ptr [ebx + 0x14]
            //   ff15????????         |                     
            //   894318               | mov                 dword ptr [ebx + 0x18], eax
            //   8b4318               | mov                 eax, dword ptr [ebx + 0x18]

        $sequence_2 = { 85c0 7512 56 e8???????? ff35???????? }
            // n = 5, score = 200
            //   85c0                 | test                eax, eax
            //   7512                 | jne                 0x14
            //   56                   | push                esi
            //   e8????????           |                     
            //   ff35????????         |                     

        $sequence_3 = { ff15???????? 897b18 8b5b14 3bdf 7407 53 ff15???????? }
            // n = 7, score = 200
            //   ff15????????         |                     
            //   897b18               | mov                 dword ptr [ebx + 0x18], edi
            //   8b5b14               | mov                 ebx, dword ptr [ebx + 0x14]
            //   3bdf                 | cmp                 ebx, edi
            //   7407                 | je                  9
            //   53                   | push                ebx
            //   ff15????????         |                     

        $sequence_4 = { 49 8bc3 2bc1 40 5b 5f 8bd0 }
            // n = 7, score = 200
            //   49                   | dec                 ecx
            //   8bc3                 | mov                 eax, ebx
            //   2bc1                 | sub                 eax, ecx
            //   40                   | inc                 eax
            //   5b                   | pop                 ebx
            //   5f                   | pop                 edi
            //   8bd0                 | mov                 edx, eax

        $sequence_5 = { ffd0 5e 5b c9 c3 0fb6c9 }
            // n = 6, score = 200
            //   ffd0                 | call                eax
            //   5e                   | pop                 esi
            //   5b                   | pop                 ebx
            //   c9                   | leave               
            //   c3                   | ret                 
            //   0fb6c9               | movzx               ecx, cl

        $sequence_6 = { 83ff02 7510 689704811d 53 e8???????? 8d4dcc }
            // n = 6, score = 200
            //   83ff02               | cmp                 edi, 2
            //   7510                 | jne                 0x12
            //   689704811d           | push                0x1d810497
            //   53                   | push                ebx
            //   e8????????           |                     
            //   8d4dcc               | lea                 ecx, [ebp - 0x34]

        $sequence_7 = { 8d45fc 50 8d45f0 50 8d45bc }
            // n = 5, score = 200
            //   8d45fc               | lea                 eax, [ebp - 4]
            //   50                   | push                eax
            //   8d45f0               | lea                 eax, [ebp - 0x10]
            //   50                   | push                eax
            //   8d45bc               | lea                 eax, [ebp - 0x44]

        $sequence_8 = { 8b4710 2b45fc 8b0e 890c30 83c604 }
            // n = 5, score = 200
            //   8b4710               | mov                 eax, dword ptr [edi + 0x10]
            //   2b45fc               | sub                 eax, dword ptr [ebp - 4]
            //   8b0e                 | mov                 ecx, dword ptr [esi]
            //   890c30               | mov                 dword ptr [eax + esi], ecx
            //   83c604               | add                 esi, 4

        $sequence_9 = { 74da 8b45fc 8b5818 53 6a40 895df4 }
            // n = 6, score = 200
            //   74da                 | je                  0xffffffdc
            //   8b45fc               | mov                 eax, dword ptr [ebp - 4]
            //   8b5818               | mov                 ebx, dword ptr [eax + 0x18]
            //   53                   | push                ebx
            //   6a40                 | push                0x40
            //   895df4               | mov                 dword ptr [ebp - 0xc], ebx

    condition:
        7 of them and filesize < 98304
}