rule win_petya_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.petya."
        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.petya"
        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 = { 50 e8???????? 83c40c 8d5750 8bcf e8???????? 035c2410 }
            // n = 7, score = 600
            //   50                   | push                eax
            //   e8????????           |                     
            //   83c40c               | add                 esp, 0xc
            //   8d5750               | lea                 edx, [edi + 0x50]
            //   8bcf                 | mov                 ecx, edi
            //   e8????????           |                     
            //   035c2410             | add                 ebx, dword ptr [esp + 0x10]

        $sequence_1 = { 8bca 88442428 8bc6 c1e810 }
            // n = 4, score = 600
            //   8bca                 | mov                 ecx, edx
            //   88442428             | mov                 byte ptr [esp + 0x28], al
            //   8bc6                 | mov                 eax, esi
            //   c1e810               | shr                 eax, 0x10

        $sequence_2 = { 53 8b5d0c 33c9 56 8b7508 2bde 83c303 }
            // n = 7, score = 600
            //   53                   | push                ebx
            //   8b5d0c               | mov                 ebx, dword ptr [ebp + 0xc]
            //   33c9                 | xor                 ecx, ecx
            //   56                   | push                esi
            //   8b7508               | mov                 esi, dword ptr [ebp + 8]
            //   2bde                 | sub                 ebx, esi
            //   83c303               | add                 ebx, 3

        $sequence_3 = { 5f 5e e9???????? 4e }
            // n = 4, score = 600
            //   5f                   | pop                 edi
            //   5e                   | pop                 esi
            //   e9????????           |                     
            //   4e                   | dec                 esi

        $sequence_4 = { 56 6870020000 8bf1 6a00 56 e8???????? }
            // n = 6, score = 600
            //   56                   | push                esi
            //   6870020000           | push                0x270
            //   8bf1                 | mov                 esi, ecx
            //   6a00                 | push                0
            //   56                   | push                esi
            //   e8????????           |                     

        $sequence_5 = { 57 8bf9 8b7704 3bf2 }
            // n = 4, score = 600
            //   57                   | push                edi
            //   8bf9                 | mov                 edi, ecx
            //   8b7704               | mov                 esi, dword ptr [edi + 4]
            //   3bf2                 | cmp                 esi, edx

        $sequence_6 = { c1e017 33ff 0bf9 c1eb09 8b4c2424 }
            // n = 5, score = 600
            //   c1e017               | shl                 eax, 0x17
            //   33ff                 | xor                 edi, edi
            //   0bf9                 | or                  edi, ecx
            //   c1eb09               | shr                 ebx, 9
            //   8b4c2424             | mov                 ecx, dword ptr [esp + 0x24]

        $sequence_7 = { 33c9 57 33ff 8d0486 8bd8 2bde 83c303 }
            // n = 7, score = 600
            //   33c9                 | xor                 ecx, ecx
            //   57                   | push                edi
            //   33ff                 | xor                 edi, edi
            //   8d0486               | lea                 eax, [esi + eax*4]
            //   8bd8                 | mov                 ebx, eax
            //   2bde                 | sub                 ebx, esi
            //   83c303               | add                 ebx, 3

        $sequence_8 = { 33d2 0bd1 c1e01e 31542420 }
            // n = 4, score = 600
            //   33d2                 | xor                 edx, edx
            //   0bd1                 | or                  edx, ecx
            //   c1e01e               | shl                 eax, 0x1e
            //   31542420             | xor                 dword ptr [esp + 0x20], edx

        $sequence_9 = { 33ff 8d0486 8bd8 2bde }
            // n = 4, score = 600
            //   33ff                 | xor                 edi, edi
            //   8d0486               | lea                 eax, [esi + eax*4]
            //   8bd8                 | mov                 ebx, eax
            //   2bde                 | sub                 ebx, esi

    condition:
        7 of them and filesize < 229376
}