rule win_dharma_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.dharma."
        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.dharma"
        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 = { 68???????? e8???????? 83c410 8945e8 8b45e8 50 e8???????? }
            // n = 7, score = 100
            //   68????????           |                     
            //   e8????????           |                     
            //   83c410               | add                 esp, 0x10
            //   8945e8               | mov                 dword ptr [ebp - 0x18], eax
            //   8b45e8               | mov                 eax, dword ptr [ebp - 0x18]
            //   50                   | push                eax
            //   e8????????           |                     

        $sequence_1 = { 880a 8b55f4 83c201 8955f4 837d1000 744a 8b45fc }
            // n = 7, score = 100
            //   880a                 | mov                 byte ptr [edx], cl
            //   8b55f4               | mov                 edx, dword ptr [ebp - 0xc]
            //   83c201               | add                 edx, 1
            //   8955f4               | mov                 dword ptr [ebp - 0xc], edx
            //   837d1000             | cmp                 dword ptr [ebp + 0x10], 0
            //   744a                 | je                  0x4c
            //   8b45fc               | mov                 eax, dword ptr [ebp - 4]

        $sequence_2 = { 6a02 6880000000 68???????? 68???????? e8???????? 83c410 8945dc }
            // n = 7, score = 100
            //   6a02                 | push                2
            //   6880000000           | push                0x80
            //   68????????           |                     
            //   68????????           |                     
            //   e8????????           |                     
            //   83c410               | add                 esp, 0x10
            //   8945dc               | mov                 dword ptr [ebp - 0x24], eax

        $sequence_3 = { 51 e8???????? 85c0 0f8477010000 837de400 }
            // n = 5, score = 100
            //   51                   | push                ecx
            //   e8????????           |                     
            //   85c0                 | test                eax, eax
            //   0f8477010000         | je                  0x17d
            //   837de400             | cmp                 dword ptr [ebp - 0x1c], 0

        $sequence_4 = { c1e002 50 6a00 8b4dec 8b510c 52 e8???????? }
            // n = 7, score = 100
            //   c1e002               | shl                 eax, 2
            //   50                   | push                eax
            //   6a00                 | push                0
            //   8b4dec               | mov                 ecx, dword ptr [ebp - 0x14]
            //   8b510c               | mov                 edx, dword ptr [ecx + 0xc]
            //   52                   | push                edx
            //   e8????????           |                     

        $sequence_5 = { 0fb645f9 8b4de4 8a55ef 881401 0fb645fa }
            // n = 5, score = 100
            //   0fb645f9             | movzx               eax, byte ptr [ebp - 7]
            //   8b4de4               | mov                 ecx, dword ptr [ebp - 0x1c]
            //   8a55ef               | mov                 dl, byte ptr [ebp - 0x11]
            //   881401               | mov                 byte ptr [ecx + eax], dl
            //   0fb645fa             | movzx               eax, byte ptr [ebp - 6]

        $sequence_6 = { e9???????? 8b5508 8a45fd 8802 8b4d08 }
            // n = 5, score = 100
            //   e9????????           |                     
            //   8b5508               | mov                 edx, dword ptr [ebp + 8]
            //   8a45fd               | mov                 al, byte ptr [ebp - 3]
            //   8802                 | mov                 byte ptr [edx], al
            //   8b4d08               | mov                 ecx, dword ptr [ebp + 8]

        $sequence_7 = { 8b4508 8b4dfc 894804 8b5508 8b45f8 8902 8be5 }
            // n = 7, score = 100
            //   8b4508               | mov                 eax, dword ptr [ebp + 8]
            //   8b4dfc               | mov                 ecx, dword ptr [ebp - 4]
            //   894804               | mov                 dword ptr [eax + 4], ecx
            //   8b5508               | mov                 edx, dword ptr [ebp + 8]
            //   8b45f8               | mov                 eax, dword ptr [ebp - 8]
            //   8902                 | mov                 dword ptr [edx], eax
            //   8be5                 | mov                 esp, ebp

        $sequence_8 = { 8b4da8 51 e8???????? 83c40c 8b55a8 52 }
            // n = 6, score = 100
            //   8b4da8               | mov                 ecx, dword ptr [ebp - 0x58]
            //   51                   | push                ecx
            //   e8????????           |                     
            //   83c40c               | add                 esp, 0xc
            //   8b55a8               | mov                 edx, dword ptr [ebp - 0x58]
            //   52                   | push                edx

        $sequence_9 = { 894de0 8b55f0 52 68???????? 8b45f4 50 6a03 }
            // n = 7, score = 100
            //   894de0               | mov                 dword ptr [ebp - 0x20], ecx
            //   8b55f0               | mov                 edx, dword ptr [ebp - 0x10]
            //   52                   | push                edx
            //   68????????           |                     
            //   8b45f4               | mov                 eax, dword ptr [ebp - 0xc]
            //   50                   | push                eax
            //   6a03                 | push                3

    condition:
        7 of them and filesize < 204800
}