rule win_stuxnet_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-05-04"
        version = "1"
        description = "Detects win.stuxnet."
        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.stuxnet"
        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 = { e8???????? bef4030000 03c6 e8???????? 8845ef 834dfcff 8d45e8 }
            // n = 7, score = 200
            //   e8????????           |                     
            //   bef4030000           | mov                 esi, 0x3f4
            //   03c6                 | add                 eax, esi
            //   e8????????           |                     
            //   8845ef               | mov                 byte ptr [ebp - 0x11], al
            //   834dfcff             | or                  dword ptr [ebp - 4], 0xffffffff
            //   8d45e8               | lea                 eax, [ebp - 0x18]

        $sequence_1 = { c3 55 8bec 83ec44 56 6a44 8d45bc }
            // n = 7, score = 200
            //   c3                   | ret                 
            //   55                   | push                ebp
            //   8bec                 | mov                 ebp, esp
            //   83ec44               | sub                 esp, 0x44
            //   56                   | push                esi
            //   6a44                 | push                0x44
            //   8d45bc               | lea                 eax, [ebp - 0x44]

        $sequence_2 = { b8???????? e8???????? 81ecc8010000 53 56 57 8965f0 }
            // n = 7, score = 200
            //   b8????????           |                     
            //   e8????????           |                     
            //   81ecc8010000         | sub                 esp, 0x1c8
            //   53                   | push                ebx
            //   56                   | push                esi
            //   57                   | push                edi
            //   8965f0               | mov                 dword ptr [ebp - 0x10], esp

        $sequence_3 = { 53 e8???????? 8d45d8 50 56 e8???????? 8365fc00 }
            // n = 7, score = 200
            //   53                   | push                ebx
            //   e8????????           |                     
            //   8d45d8               | lea                 eax, [ebp - 0x28]
            //   50                   | push                eax
            //   56                   | push                esi
            //   e8????????           |                     
            //   8365fc00             | and                 dword ptr [ebp - 4], 0

        $sequence_4 = { ff75e8 ff15???????? 85c0 0f85defeffff eb1a 8d45ac 50 }
            // n = 7, score = 200
            //   ff75e8               | push                dword ptr [ebp - 0x18]
            //   ff15????????         |                     
            //   85c0                 | test                eax, eax
            //   0f85defeffff         | jne                 0xfffffee4
            //   eb1a                 | jmp                 0x1c
            //   8d45ac               | lea                 eax, [ebp - 0x54]
            //   50                   | push                eax

        $sequence_5 = { c645fc05 8d45f0 50 e8???????? c645fc04 8b75e8 3bf3 }
            // n = 7, score = 200
            //   c645fc05             | mov                 byte ptr [ebp - 4], 5
            //   8d45f0               | lea                 eax, [ebp - 0x10]
            //   50                   | push                eax
            //   e8????????           |                     
            //   c645fc04             | mov                 byte ptr [ebp - 4], 4
            //   8b75e8               | mov                 esi, dword ptr [ebp - 0x18]
            //   3bf3                 | cmp                 esi, ebx

        $sequence_6 = { e8???????? 50 8d470c 50 ff15???????? 83670800 8d8714020000 }
            // n = 7, score = 200
            //   e8????????           |                     
            //   50                   | push                eax
            //   8d470c               | lea                 eax, [edi + 0xc]
            //   50                   | push                eax
            //   ff15????????         |                     
            //   83670800             | and                 dword ptr [edi + 8], 0
            //   8d8714020000         | lea                 eax, [edi + 0x214]

        $sequence_7 = { 8b5d08 56 6880000000 8bc3 e8???????? 8bf0 59 }
            // n = 7, score = 200
            //   8b5d08               | mov                 ebx, dword ptr [ebp + 8]
            //   56                   | push                esi
            //   6880000000           | push                0x80
            //   8bc3                 | mov                 eax, ebx
            //   e8????????           |                     
            //   8bf0                 | mov                 esi, eax
            //   59                   | pop                 ecx

        $sequence_8 = { e8???????? 8b4c2410 8988b4000000 8b4c2414 8988b8000000 834c2424ff 8d44240c }
            // n = 7, score = 200
            //   e8????????           |                     
            //   8b4c2410             | mov                 ecx, dword ptr [esp + 0x10]
            //   8988b4000000         | mov                 dword ptr [eax + 0xb4], ecx
            //   8b4c2414             | mov                 ecx, dword ptr [esp + 0x14]
            //   8988b8000000         | mov                 dword ptr [eax + 0xb8], ecx
            //   834c2424ff           | or                  dword ptr [esp + 0x24], 0xffffffff
            //   8d44240c             | lea                 eax, [esp + 0xc]

        $sequence_9 = { c645fc03 8d462c 50 895e24 895e28 e8???????? 59 }
            // n = 7, score = 200
            //   c645fc03             | mov                 byte ptr [ebp - 4], 3
            //   8d462c               | lea                 eax, [esi + 0x2c]
            //   50                   | push                eax
            //   895e24               | mov                 dword ptr [esi + 0x24], ebx
            //   895e28               | mov                 dword ptr [esi + 0x28], ebx
            //   e8????????           |                     
            //   59                   | pop                 ecx

    condition:
        7 of them and filesize < 2495488
}