rule win_petrwrap_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.petrwrap."
        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.petrwrap"
        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 = { 897014 8b07 f76518 03c8 33f6 3bc8 7301 }
            // n = 7, score = 100
            //   897014               | mov                 dword ptr [eax + 0x14], esi
            //   8b07                 | mov                 eax, dword ptr [edi]
            //   f76518               | mul                 dword ptr [ebp + 0x18]
            //   03c8                 | add                 ecx, eax
            //   33f6                 | xor                 esi, esi
            //   3bc8                 | cmp                 ecx, eax
            //   7301                 | jae                 3

        $sequence_1 = { 1394c48c000000 8b442464 0108 8b4c2414 8be9 115004 8b442424 }
            // n = 7, score = 100
            //   1394c48c000000       | adc                 edx, dword ptr [esp + eax*8 + 0x8c]
            //   8b442464             | mov                 eax, dword ptr [esp + 0x64]
            //   0108                 | add                 dword ptr [eax], ecx
            //   8b4c2414             | mov                 ecx, dword ptr [esp + 0x14]
            //   8be9                 | mov                 ebp, ecx
            //   115004               | adc                 dword ptr [eax + 4], edx
            //   8b442424             | mov                 eax, dword ptr [esp + 0x24]

        $sequence_2 = { 33fb 237c243c 23cb 33f9 8b4c2418 33d0 }
            // n = 6, score = 100
            //   33fb                 | xor                 edi, ebx
            //   237c243c             | and                 edi, dword ptr [esp + 0x3c]
            //   23cb                 | and                 ecx, ebx
            //   33f9                 | xor                 edi, ecx
            //   8b4c2418             | mov                 ecx, dword ptr [esp + 0x18]
            //   33d0                 | xor                 edx, eax

        $sequence_3 = { 237c2430 f7d2 23542454 8bc6 2344243c 33f9 33d0 }
            // n = 7, score = 100
            //   237c2430             | and                 edi, dword ptr [esp + 0x30]
            //   f7d2                 | not                 edx
            //   23542454             | and                 edx, dword ptr [esp + 0x54]
            //   8bc6                 | mov                 eax, esi
            //   2344243c             | and                 eax, dword ptr [esp + 0x3c]
            //   33f9                 | xor                 edi, ecx
            //   33d0                 | xor                 edx, eax

        $sequence_4 = { 8bd8 8b148d80db4600 83e31f c1e306 894df4 8a441a04 895ddc }
            // n = 7, score = 100
            //   8bd8                 | mov                 ebx, eax
            //   8b148d80db4600       | mov                 edx, dword ptr [ecx*4 + 0x46db80]
            //   83e31f               | and                 ebx, 0x1f
            //   c1e306               | shl                 ebx, 6
            //   894df4               | mov                 dword ptr [ebp - 0xc], ecx
            //   8a441a04             | mov                 al, byte ptr [edx + ebx + 4]
            //   895ddc               | mov                 dword ptr [ebp - 0x24], ebx

        $sequence_5 = { 6800000040 ff7508 ff15???????? 6a00 8bf0 8d45fc 50 }
            // n = 7, score = 100
            //   6800000040           | push                0x40000000
            //   ff7508               | push                dword ptr [ebp + 8]
            //   ff15????????         |                     
            //   6a00                 | push                0
            //   8bf0                 | mov                 esi, eax
            //   8d45fc               | lea                 eax, [ebp - 4]
            //   50                   | push                eax

        $sequence_6 = { e8???????? 83c420 85c0 752f 68eb020000 68???????? }
            // n = 6, score = 100
            //   e8????????           |                     
            //   83c420               | add                 esp, 0x20
            //   85c0                 | test                eax, eax
            //   752f                 | jne                 0x31
            //   68eb020000           | push                0x2eb
            //   68????????           |                     

        $sequence_7 = { 85c0 752a 39442420 7515 57 55 53 }
            // n = 7, score = 100
            //   85c0                 | test                eax, eax
            //   752a                 | jne                 0x2c
            //   39442420             | cmp                 dword ptr [esp + 0x20], eax
            //   7515                 | jne                 0x17
            //   57                   | push                edi
            //   55                   | push                ebp
            //   53                   | push                ebx

        $sequence_8 = { 7508 ff4e04 394604 7fef 5b 5f 5d }
            // n = 7, score = 100
            //   7508                 | jne                 0xa
            //   ff4e04               | dec                 dword ptr [esi + 4]
            //   394604               | cmp                 dword ptr [esi + 4], eax
            //   7fef                 | jg                  0xfffffff1
            //   5b                   | pop                 ebx
            //   5f                   | pop                 edi
            //   5d                   | pop                 ebp

        $sequence_9 = { e8???????? 83c404 53 e8???????? 8b442424 83c404 5f }
            // n = 7, score = 100
            //   e8????????           |                     
            //   83c404               | add                 esp, 4
            //   53                   | push                ebx
            //   e8????????           |                     
            //   8b442424             | mov                 eax, dword ptr [esp + 0x24]
            //   83c404               | add                 esp, 4
            //   5f                   | pop                 edi

    condition:
        7 of them and filesize < 1024000
}