rule win_koiloader_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-05-04"
        version = "1"
        description = "Detects win.koiloader."
        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.koiloader"
        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 = { 0f1f00 8a840dc0f5ffff 88440db0 41 }
            // n = 4, score = 600
            //   0f1f00               | nop                 dword ptr [eax]
            //   8a840dc0f5ffff       | mov                 al, byte ptr [ebp + ecx - 0xa40]
            //   88440db0             | mov                 byte ptr [ebp + ecx - 0x50], al
            //   41                   | inc                 ecx

        $sequence_1 = { 7421 8d343f 33c9 85f6 7412 0f1f8000000000 }
            // n = 6, score = 600
            //   7421                 | je                  0x23
            //   8d343f               | lea                 esi, [edi + edi]
            //   33c9                 | xor                 ecx, ecx
            //   85f6                 | test                esi, esi
            //   7412                 | je                  0x14
            //   0f1f8000000000       | nop                 dword ptr [eax]

        $sequence_2 = { 0fb74710 50 ff15???????? 6a06 668945ea b802000000 6a01 }
            // n = 7, score = 600
            //   0fb74710             | movzx               eax, word ptr [edi + 0x10]
            //   50                   | push                eax
            //   ff15????????         |                     
            //   6a06                 | push                6
            //   668945ea             | mov                 word ptr [ebp - 0x16], ax
            //   b802000000           | mov                 eax, 2
            //   6a01                 | push                1

        $sequence_3 = { 752d 85d2 7410 52 6a00 ff15???????? 50 }
            // n = 7, score = 600
            //   752d                 | jne                 0x2f
            //   85d2                 | test                edx, edx
            //   7410                 | je                  0x12
            //   52                   | push                edx
            //   6a00                 | push                0
            //   ff15????????         |                     
            //   50                   | push                eax

        $sequence_4 = { 6666660f1f840000000000 8b8c15acfcffff 2b8c1574feffff 8b8415b0fcffff 1b841578feffff 898c1574feffff 89841578feffff }
            // n = 7, score = 600
            //   6666660f1f840000000000     | nop    word ptr [eax + eax]
            //   8b8c15acfcffff       | mov                 ecx, dword ptr [ebp + edx - 0x354]
            //   2b8c1574feffff       | sub                 ecx, dword ptr [ebp + edx - 0x18c]
            //   8b8415b0fcffff       | mov                 eax, dword ptr [ebp + edx - 0x350]
            //   1b841578feffff       | sbb                 eax, dword ptr [ebp + edx - 0x188]
            //   898c1574feffff       | mov                 dword ptr [ebp + edx - 0x18c], ecx
            //   89841578feffff       | mov                 dword ptr [ebp + edx - 0x188], eax

        $sequence_5 = { 0f8404020000 83e801 0f850d020000 394508 0f8404020000 33d2 }
            // n = 6, score = 600
            //   0f8404020000         | je                  0x20a
            //   83e801               | sub                 eax, 1
            //   0f850d020000         | jne                 0x213
            //   394508               | cmp                 dword ptr [ebp + 8], eax
            //   0f8404020000         | je                  0x20a
            //   33d2                 | xor                 edx, edx

        $sequence_6 = { 0fb64c05b0 c1e208 0bd1 89940558ffffff 83c004 }
            // n = 5, score = 600
            //   0fb64c05b0           | movzx               ecx, byte ptr [ebp + eax - 0x50]
            //   c1e208               | shl                 edx, 8
            //   0bd1                 | or                  edx, ecx
            //   89940558ffffff       | mov                 dword ptr [ebp + eax - 0xa8], edx
            //   83c004               | add                 eax, 4

        $sequence_7 = { 8b75e8 c1f91f 23c8 8bc1 c1e01a 2bf0 }
            // n = 6, score = 600
            //   8b75e8               | mov                 esi, dword ptr [ebp - 0x18]
            //   c1f91f               | sar                 ecx, 0x1f
            //   23c8                 | and                 ecx, eax
            //   8bc1                 | mov                 eax, ecx
            //   c1e01a               | shl                 eax, 0x1a
            //   2bf0                 | sub                 esi, eax

        $sequence_8 = { 72ef 8d8520feffff 50 8d55b0 8d8db8f8ffff e8???????? 83c404 }
            // n = 7, score = 600
            //   72ef                 | jb                  0xfffffff1
            //   8d8520feffff         | lea                 eax, [ebp - 0x1e0]
            //   50                   | push                eax
            //   8d55b0               | lea                 edx, [ebp - 0x50]
            //   8d8db8f8ffff         | lea                 ecx, [ebp - 0x748]
            //   e8????????           |                     
            //   83c404               | add                 esp, 4

        $sequence_9 = { 8bd0 e8???????? 8bf0 83c404 85f6 7435 6804010000 }
            // n = 7, score = 600
            //   8bd0                 | mov                 edx, eax
            //   e8????????           |                     
            //   8bf0                 | mov                 esi, eax
            //   83c404               | add                 esp, 4
            //   85f6                 | test                esi, esi
            //   7435                 | je                  0x37
            //   6804010000           | push                0x104

    condition:
        7 of them and filesize < 101376
}