rule win_bagle_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.bagle."
        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.bagle"
        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 = { e8???????? 6804010000 68???????? 6a00 e8???????? }
            // n = 5, score = 300
            //   e8????????           |                     
            //   6804010000           | push                0x104
            //   68????????           |                     
            //   6a00                 | push                0
            //   e8????????           |                     

        $sequence_1 = { 5f 5e c9 c20c00 c1c206 }
            // n = 5, score = 300
            //   5f                   | pop                 edi
            //   5e                   | pop                 esi
            //   c9                   | leave               
            //   c20c00               | ret                 0xc
            //   c1c206               | rol                 edx, 6

        $sequence_2 = { 6a01 6a02 e8???????? 8bd8 ff7508 }
            // n = 5, score = 300
            //   6a01                 | push                1
            //   6a02                 | push                2
            //   e8????????           |                     
            //   8bd8                 | mov                 ebx, eax
            //   ff7508               | push                dword ptr [ebp + 8]

        $sequence_3 = { 6880000000 68???????? e8???????? 6a00 6a00 6a00 }
            // n = 6, score = 300
            //   6880000000           | push                0x80
            //   68????????           |                     
            //   e8????????           |                     
            //   6a00                 | push                0
            //   6a00                 | push                0
            //   6a00                 | push                0

        $sequence_4 = { fec0 75e2 c3 55 8bec }
            // n = 5, score = 300
            //   fec0                 | inc                 al
            //   75e2                 | jne                 0xffffffe4
            //   c3                   | ret                 
            //   55                   | push                ebp
            //   8bec                 | mov                 ebp, esp

        $sequence_5 = { 68???????? 68???????? e8???????? 6804010000 68???????? 6a00 }
            // n = 6, score = 300
            //   68????????           |                     
            //   68????????           |                     
            //   e8????????           |                     
            //   6804010000           | push                0x104
            //   68????????           |                     
            //   6a00                 | push                0

        $sequence_6 = { 33db 66b80d0a 66ab 83e903 79c6 }
            // n = 5, score = 300
            //   33db                 | xor                 ebx, ebx
            //   66b80d0a             | mov                 ax, 0xa0d
            //   66ab                 | stosw               word ptr es:[edi], ax
            //   83e903               | sub                 ecx, 3
            //   79c6                 | jns                 0xffffffc8

        $sequence_7 = { e8???????? e2f9 59 43 83fb12 }
            // n = 5, score = 300
            //   e8????????           |                     
            //   e2f9                 | loop                0xfffffffb
            //   59                   | pop                 ecx
            //   43                   | inc                 ebx
            //   83fb12               | cmp                 ebx, 0x12

        $sequence_8 = { 59 43 83fb12 7508 33db 66b80d0a }
            // n = 6, score = 300
            //   59                   | pop                 ecx
            //   43                   | inc                 ebx
            //   83fb12               | cmp                 ebx, 0x12
            //   7508                 | jne                 0xa
            //   33db                 | xor                 ebx, ebx
            //   66b80d0a             | mov                 ax, 0xa0d

        $sequence_9 = { e340 ac c1e010 83f901 740b ac 66c1e008 }
            // n = 7, score = 300
            //   e340                 | jecxz               0x42
            //   ac                   | lodsb               al, byte ptr [esi]
            //   c1e010               | shl                 eax, 0x10
            //   83f901               | cmp                 ecx, 1
            //   740b                 | je                  0xd
            //   ac                   | lodsb               al, byte ptr [esi]
            //   66c1e008             | shl                 ax, 8

    condition:
        7 of them and filesize < 245760
}