rule win_sharpknot_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.sharpknot."
        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.sharpknot"
        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 = { f2ae 8bcb 4f c1e902 f3a5 8b84241c020000 8bcb }
            // n = 7, score = 100
            //   f2ae                 | repne scasb         al, byte ptr es:[edi]
            //   8bcb                 | mov                 ecx, ebx
            //   4f                   | dec                 edi
            //   c1e902               | shr                 ecx, 2
            //   f3a5                 | rep movsd           dword ptr es:[edi], dword ptr [esi]
            //   8b84241c020000       | mov                 eax, dword ptr [esp + 0x21c]
            //   8bcb                 | mov                 ecx, ebx

        $sequence_1 = { 85c0 7423 8bce 8bc6 c1f905 83e01f 8b0c8d40e64400 }
            // n = 7, score = 100
            //   85c0                 | test                eax, eax
            //   7423                 | je                  0x25
            //   8bce                 | mov                 ecx, esi
            //   8bc6                 | mov                 eax, esi
            //   c1f905               | sar                 ecx, 5
            //   83e01f               | and                 eax, 0x1f
            //   8b0c8d40e64400       | mov                 ecx, dword ptr [ecx*4 + 0x44e640]

        $sequence_2 = { 85c0 7405 83c60a ebe8 bb01000000 85db }
            // n = 6, score = 100
            //   85c0                 | test                eax, eax
            //   7405                 | je                  7
            //   83c60a               | add                 esi, 0xa
            //   ebe8                 | jmp                 0xffffffea
            //   bb01000000           | mov                 ebx, 1
            //   85db                 | test                ebx, ebx

        $sequence_3 = { c1fa02 8bca 897c2430 c1e91f 03d1 83fa01 0f83b3000000 }
            // n = 7, score = 100
            //   c1fa02               | sar                 edx, 2
            //   8bca                 | mov                 ecx, edx
            //   897c2430             | mov                 dword ptr [esp + 0x30], edi
            //   c1e91f               | shr                 ecx, 0x1f
            //   03d1                 | add                 edx, ecx
            //   83fa01               | cmp                 edx, 1
            //   0f83b3000000         | jae                 0xb9

        $sequence_4 = { 50 6a00 ff15???????? 8d8c240c010000 }
            // n = 4, score = 100
            //   50                   | push                eax
            //   6a00                 | push                0
            //   ff15????????         |                     
            //   8d8c240c010000       | lea                 ecx, [esp + 0x10c]

        $sequence_5 = { 6a01 56 ff15???????? 68e8030000 ff15???????? }
            // n = 5, score = 100
            //   6a01                 | push                1
            //   56                   | push                esi
            //   ff15????????         |                     
            //   68e8030000           | push                0x3e8
            //   ff15????????         |                     

        $sequence_6 = { 7505 5f 33c0 5b c3 803f00 7505 }
            // n = 7, score = 100
            //   7505                 | jne                 7
            //   5f                   | pop                 edi
            //   33c0                 | xor                 eax, eax
            //   5b                   | pop                 ebx
            //   c3                   | ret                 
            //   803f00               | cmp                 byte ptr [edi], 0
            //   7505                 | jne                 7

        $sequence_7 = { 68???????? ff15???????? 8bf0 85f6 0f84b6000000 8b1d???????? 68???????? }
            // n = 7, score = 100
            //   68????????           |                     
            //   ff15????????         |                     
            //   8bf0                 | mov                 esi, eax
            //   85f6                 | test                esi, esi
            //   0f84b6000000         | je                  0xbc
            //   8b1d????????         |                     
            //   68????????           |                     

        $sequence_8 = { 7cf1 56 8bf1 c1e603 3b9670da4000 }
            // n = 5, score = 100
            //   7cf1                 | jl                  0xfffffff3
            //   56                   | push                esi
            //   8bf1                 | mov                 esi, ecx
            //   c1e603               | shl                 esi, 3
            //   3b9670da4000         | cmp                 edx, dword ptr [esi + 0x40da70]

        $sequence_9 = { 83651003 8bf0 750b c1e602 8b86e8dc4000 eb09 c1e602 }
            // n = 7, score = 100
            //   83651003             | and                 dword ptr [ebp + 0x10], 3
            //   8bf0                 | mov                 esi, eax
            //   750b                 | jne                 0xd
            //   c1e602               | shl                 esi, 2
            //   8b86e8dc4000         | mov                 eax, dword ptr [esi + 0x40dce8]
            //   eb09                 | jmp                 0xb
            //   c1e602               | shl                 esi, 2

    condition:
        7 of them and filesize < 1032192
}