rule win_ramnit_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.ramnit."
        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.ramnit"
        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 = { 8b4508 3b450c 7603 8b450c c9 c20800 55 }
            // n = 7, score = 4000
            //   8b4508               | mov                 eax, dword ptr [ebp + 8]
            //   3b450c               | cmp                 eax, dword ptr [ebp + 0xc]
            //   7603                 | jbe                 5
            //   8b450c               | mov                 eax, dword ptr [ebp + 0xc]
            //   c9                   | leave               
            //   c20800               | ret                 8
            //   55                   | push                ebp

        $sequence_1 = { c20c00 b800000000 59 5f 5e 5a 5b }
            // n = 7, score = 4000
            //   c20c00               | ret                 0xc
            //   b800000000           | mov                 eax, 0
            //   59                   | pop                 ecx
            //   5f                   | pop                 edi
            //   5e                   | pop                 esi
            //   5a                   | pop                 edx
            //   5b                   | pop                 ebx

        $sequence_2 = { 8b7d08 b000 f2ae 8bc1 f7d0 48 }
            // n = 6, score = 4000
            //   8b7d08               | mov                 edi, dword ptr [ebp + 8]
            //   b000                 | mov                 al, 0
            //   f2ae                 | repne scasb         al, byte ptr es:[edi]
            //   8bc1                 | mov                 eax, ecx
            //   f7d0                 | not                 eax
            //   48                   | dec                 eax

        $sequence_3 = { 50 e8???????? 38d8 751a 47 46 49 }
            // n = 7, score = 4000
            //   50                   | push                eax
            //   e8????????           |                     
            //   38d8                 | cmp                 al, bl
            //   751a                 | jne                 0x1c
            //   47                   | inc                 edi
            //   46                   | inc                 esi
            //   49                   | dec                 ecx

        $sequence_4 = { f7d0 48 59 5f }
            // n = 4, score = 4000
            //   f7d0                 | not                 eax
            //   48                   | dec                 eax
            //   59                   | pop                 ecx
            //   5f                   | pop                 edi

        $sequence_5 = { 55 8bec 56 57 51 53 52 }
            // n = 7, score = 4000
            //   55                   | push                ebp
            //   8bec                 | mov                 ebp, esp
            //   56                   | push                esi
            //   57                   | push                edi
            //   51                   | push                ecx
            //   53                   | push                ebx
            //   52                   | push                edx

        $sequence_6 = { 8bec 83c4f8 56 57 51 53 52 }
            // n = 7, score = 4000
            //   8bec                 | mov                 ebp, esp
            //   83c4f8               | add                 esp, -8
            //   56                   | push                esi
            //   57                   | push                edi
            //   51                   | push                ecx
            //   53                   | push                ebx
            //   52                   | push                edx

        $sequence_7 = { 55 8bec 53 52 51 }
            // n = 5, score = 4000
            //   55                   | push                ebp
            //   8bec                 | mov                 ebp, esp
            //   53                   | push                ebx
            //   52                   | push                edx
            //   51                   | push                ecx

        $sequence_8 = { 3a06 7512 47 46 e2f6 b801000000 59 }
            // n = 7, score = 4000
            //   3a06                 | cmp                 al, byte ptr [esi]
            //   7512                 | jne                 0x14
            //   47                   | inc                 edi
            //   46                   | inc                 esi
            //   e2f6                 | loop                0xfffffff8
            //   b801000000           | mov                 eax, 1
            //   59                   | pop                 ecx

        $sequence_9 = { 668918 8b45fc 5e 5f 59 }
            // n = 5, score = 4000
            //   668918               | mov                 word ptr [eax], bx
            //   8b45fc               | mov                 eax, dword ptr [ebp - 4]
            //   5e                   | pop                 esi
            //   5f                   | pop                 edi
            //   59                   | pop                 ecx

    condition:
        7 of them and filesize < 470016
}