[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M758DDC6ACNRR8D0X337RTD3":3,"skill-same:01M758DDC6ACNRR8D0X337RTD3":91},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":37,"commitSha":38,"skillDirectory":5,"forksCount":14,"repositoryHtmlUrl":39,"repositoryHomepageUrl":6,"ownerHtmlUrl":40,"ownerBlogUrl":41,"ownerDescription":6,"updatedAt":42,"install":43,"resources":56},"01M758DDC6ACNRR8D0X337RTD3","reverse-engineering-ransomware-encryption-routine",null,"Reverse engineer ransomware encryption routines to identify cryptographic algorithms, key generation flaws, and potential decryption opportunities using static and dynamic analysis.","SamuelChien\u002Fmega-skills-collection","SamuelChien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F4652114?v=4","01M74KK34WVHA0P5ZYSJRDDFMG","Samuel Chien","01M74KK35FQN1N9VZ9EPTH3P2S",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: reverse-engineering-ransomware-encryption-routine\ndescription: Reverse engineer ransomware encryption routines to identify cryptographic algorithms, key generation flaws, and potential decryption opportunities using static and dynamic analysis.\ndomain: cybersecurity\nsubdomain: malware-analysis\ntags: [ransomware, encryption, reverse-engineering, cryptanalysis, aes, rsa, decryption, malware-analysis]\nversion: \"1.0\"\nauthor: mahipal\nlicense: Apache-2.0\n---\n# Reverse Engineering Ransomware Encryption Routine\n\n## Overview\n\nModern ransomware uses hybrid encryption combining symmetric algorithms (AES-256-CBC\u002FCTR, ChaCha20, Salsa20) for file encryption with asymmetric algorithms (RSA-2048\u002F4096, Curve25519) for key protection. The encryption routine typically generates a random symmetric key per file, encrypts file contents, then encrypts the symmetric key with the attacker's embedded public key. Reverse engineering these routines identifies the specific algorithms, key derivation methods, initialization vectors, file targeting patterns, and potential implementation flaws that could enable decryption without paying the ransom. Notable examples include Rhysida (AES-256-CTR + RSA-4096), Qilin.B (AES-256-CTR with AES-NI or ChaCha20 fallback), and Medusa (AES-256 + RSA).\n\n\n## When to Use\n\n- When performing authorized security testing that involves reverse engineering ransomware encryption routine\n- When analyzing malware samples or attack artifacts in a controlled environment\n- When conducting red team exercises or penetration testing engagements\n- When building detection capabilities based on offensive technique understanding\n\n## Prerequisites\n\n- IDA Pro or Ghidra for static disassembly\n- x64dbg\u002FWinDbg for dynamic debugging\n- Python 3.9+ with `pycryptodome`, `pefile`\n- Understanding of AES, RSA, ChaCha20, Curve25519 algorithms\n- Knowledge of Windows CryptoAPI and CNG (BCrypt) functions\n- Sandbox environment for safe execution\n\n## Key Concepts\n\n### Hybrid Encryption Model\n\nRansomware generates a unique AES key and IV for each file. The file content is encrypted with this symmetric key. The symmetric key is then encrypted with the attacker's RSA public key (embedded in the binary or fetched from C2). The encrypted key is appended or prepended to the encrypted file. Only the attacker holding the RSA private key can decrypt the per-file symmetric keys.\n\n### Cryptographic API Identification\n\nWindows ransomware typically uses CryptoAPI (`CryptAcquireContext`, `CryptGenKey`, `CryptEncrypt`) or CNG (`BCryptGenerateSymmetricKey`, `BCryptEncrypt`). Some use OpenSSL or custom implementations. Identifying these API calls provides immediate insight into the algorithm, key size, and mode of operation.\n\n### Implementation Flaws\n\nDecryption opportunities arise from: hardcoded encryption keys, weak PRNG for key generation (using `GetTickCount` or `time()` as seed), reuse of IVs across files, ECB mode usage, keys remaining in memory post-encryption, and race conditions where keys can be captured during encryption.\n\n## Workflow\n\n### Step 1: Identify Cryptographic Functions\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Identify cryptographic functions in ransomware PE files.\"\"\"\nimport pefile\nimport sys\n\nCRYPTO_APIS = {\n    # Windows CryptoAPI\n    \"CryptAcquireContextA\": \"CryptoAPI context acquisition\",\n    \"CryptAcquireContextW\": \"CryptoAPI context acquisition\",\n    \"CryptGenKey\": \"Key generation\",\n    \"CryptDeriveKey\": \"Key derivation\",\n    \"CryptEncrypt\": \"Encryption operation\",\n    \"CryptDecrypt\": \"Decryption operation\",\n    \"CryptImportKey\": \"Key import (public key?)\",\n    \"CryptExportKey\": \"Key export\",\n    \"CryptGenRandom\": \"Random number generation\",\n    \"CryptCreateHash\": \"Hash creation\",\n    \"CryptHashData\": \"Hashing operation\",\n    # Windows CNG (BCrypt)\n    \"BCryptOpenAlgorithmProvider\": \"CNG algorithm initialization\",\n    \"BCryptGenerateSymmetricKey\": \"CNG symmetric key generation\",\n    \"BCryptEncrypt\": \"CNG encryption\",\n    \"BCryptDecrypt\": \"CNG decryption\",\n    \"BCryptGenerateKeyPair\": \"CNG key pair generation\",\n    \"BCryptImportKeyPair\": \"CNG key import\",\n    # OpenSSL\n    \"EVP_EncryptInit_ex\": \"OpenSSL encrypt init\",\n    \"EVP_EncryptUpdate\": \"OpenSSL encrypt update\",\n    \"EVP_EncryptFinal_ex\": \"OpenSSL encrypt final\",\n    \"RSA_public_encrypt\": \"OpenSSL RSA encryption\",\n    \"AES_set_encrypt_key\": \"OpenSSL AES key setup\",\n    # File operations\n    \"CreateFileW\": \"File open (target files)\",\n    \"ReadFile\": \"File read (before encryption)\",\n    \"WriteFile\": \"File write (after encryption)\",\n    \"FindFirstFileW\": \"File enumeration (targeting)\",\n    \"FindNextFileW\": \"File enumeration\",\n    \"MoveFileW\": \"File rename (extension change)\",\n    \"DeleteFileW\": \"File deletion (originals)\",\n}\n\nAES_SBOX = bytes([\n    0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,\n    0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,\n])\n\nCHACHA20_CONSTANT = b\"expand 32-byte k\"\n\n\ndef analyze_imports(filepath):\n    \"\"\"Analyze PE imports for cryptographic APIs.\"\"\"\n    try:\n        pe = pefile.PE(filepath)\n    except pefile.PEFormatError:\n        print(\"[-] Not a valid PE file\")\n        return\n\n    print(\"[+] Cryptographic API Analysis\")\n    print(\"=\" * 60)\n\n    crypto_imports = []\n    if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):\n        for entry in pe.DIRECTORY_ENTRY_IMPORT:\n            dll = entry.dll.decode('utf-8', errors='replace')\n            for imp in entry.imports:\n                if imp.name:\n                    name = imp.name.decode('utf-8', errors='replace')\n                    if name in CRYPTO_APIS:\n                        desc = CRYPTO_APIS[name]\n                        crypto_imports.append((dll, name, desc))\n                        print(f\"  [{dll}] {name}: {desc}\")\n\n    if not crypto_imports:\n        print(\"  No known crypto APIs found in imports\")\n        print(\"  Malware may use custom implementation or dynamic loading\")\n\n    return crypto_imports\n\n\ndef find_crypto_constants(filepath):\n    \"\"\"Search for embedded cryptographic constants.\"\"\"\n    with open(filepath, 'rb') as f:\n        data = f.read()\n\n    print(\"\\n[+] Cryptographic Constants Search\")\n    print(\"=\" * 60)\n\n    # AES S-Box\n    offset = data.find(AES_SBOX)\n    if offset != -1:\n        print(f\"  AES S-Box found at offset 0x{offset:x}\")\n\n    # ChaCha20\u002FSalsa20 constant\n    offset = data.find(CHACHA20_CONSTANT)\n    if offset != -1:\n        print(f\"  ChaCha20 constant at offset 0x{offset:x}\")\n\n    # RSA public key markers\n    rsa_markers = [\n        b'-----BEGIN PUBLIC KEY-----',\n        b'-----BEGIN RSA PUBLIC KEY-----',\n        b'\\x30\\x82',  # ASN.1 SEQUENCE\n    ]\n    for marker in rsa_markers:\n        offset = data.find(marker)\n        if offset != -1:\n            print(f\"  RSA key marker at offset 0x{offset:x}\")\n\n    # Common ransomware file extension patterns\n    import re\n    ext_pattern = re.compile(rb'\\.\\w{3,10}(?=\\x00)', re.IGNORECASE)\n    extensions = set()\n    for match in ext_pattern.finditer(data):\n        ext = match.group().decode('ascii', errors='replace').lower()\n        target_exts = [\n            '.doc', '.docx', '.xls', '.xlsx', '.pdf', '.ppt',\n            '.jpg', '.png', '.sql', '.mdb', '.bak', '.zip',\n        ]\n        if ext in target_exts:\n            extensions.add(ext)\n\n    if extensions:\n        print(f\"\\n  Target file extensions: {', '.join(sorted(extensions))}\")\n\n\nif __name__ == \"__main__\":\n    if len(sys.argv) \u003C 2:\n        print(f\"Usage: {sys.argv[0]} \u003Cransomware_sample>\")\n        sys.exit(1)\n\n    analyze_imports(sys.argv[1])\n    find_crypto_constants(sys.argv[1])\n```\n\n### Step 2: Analyze Encryption Flow\n\n```python\ndef analyze_encryption_pattern(filepath):\n    \"\"\"Analyze file encryption patterns from ransomware artifacts.\"\"\"\n    import os\n    import struct\n\n    with open(filepath, 'rb') as f:\n        data = f.read()\n\n    file_size = len(data)\n    print(f\"\\n[+] Encrypted File Analysis: {filepath}\")\n    print(f\"  Size: {file_size:,} bytes\")\n\n    # Check for appended key material (common pattern)\n    # Many ransomware families append encrypted key at end of file\n    tail_sizes = [256, 512, 1024, 2048]  # Common RSA ciphertext sizes\n    for size in tail_sizes:\n        if file_size > size + 16:\n            tail = data[-size:]\n            # High entropy suggests encrypted data\n            entropy = calculate_entropy(tail)\n            if entropy > 7.5:\n                print(f\"  Possible encrypted key ({size} bytes) \"\n                      f\"at end of file (entropy: {entropy:.2f})\")\n\n    # Check for header modifications\n    # Many ransomware prepend metadata\n    header = data[:64]\n    print(f\"  First 16 bytes: {header[:16].hex()}\")\n\n    # Check if original file header is preserved\n    known_headers = {\n        b'PK': 'ZIP\u002FOffice',\n        b'\\x89PNG': 'PNG',\n        b'\\xff\\xd8\\xff': 'JPEG',\n        b'%PDF': 'PDF',\n        b'\\xd0\\xcf\\x11\\xe0': 'OLE (DOC\u002FXLS)',\n    }\n    for magic, ftype in known_headers.items():\n        if header.startswith(magic):\n            print(f\"  Original format preserved: {ftype}\")\n            break\n    else:\n        print(\"  Original header destroyed\u002Fencrypted\")\n\n\ndef calculate_entropy(data):\n    \"\"\"Calculate Shannon entropy of data.\"\"\"\n    from collections import Counter\n    import math\n\n    if not data:\n        return 0\n\n    freq = Counter(data)\n    length = len(data)\n    entropy = -sum(\n        (count \u002F length) * math.log2(count \u002F length)\n        for count in freq.values()\n    )\n    return entropy\n```\n\n## Validation Criteria\n\n- Cryptographic algorithms identified (AES, RSA, ChaCha20, etc.)\n- Key size and mode of operation determined\n- Key generation method analyzed for potential weaknesses\n- Per-file key encryption scheme documented\n- File targeting patterns and extension list extracted\n- Embedded public keys extracted for infrastructure correlation\n- Potential decryption opportunities assessed\n\n## References\n\n- [Morphisec - Breaking Down Ransomware Encryption](https:\u002F\u002Fwww.morphisec.com\u002Fblog\u002Fbreaking-down-ransomware-encryption-key-strategies-algorithms-and-implementation-trends\u002F)\n- [Emsisoft - Ransomware Encryption Methods](https:\u002F\u002Fwww.emsisoft.com\u002Fen\u002Fblog\u002F27649\u002Fransomware-encryption-methods\u002F)\n- [Halcyon Ransomware Power Rankings Q4-2024](https:\u002F\u002Fwww.halcyon.ai\u002Fraas-mq\u002Fpower-rankings-ransomware-malicious-quartile-q4-2024)\n- [No More Ransom Project](https:\u002F\u002Fwww.nomoreransom.org\u002F)\n- [MITRE ATT&CK T1486 - Data Encrypted for Impact](https:\u002F\u002Fattack.mitre.org\u002Ftechniques\u002FT1486\u002F)\n","# Reverse Engineering Ransomware Encryption Routine\n\n## Overview\n\nModern ransomware uses hybrid encryption combining symmetric algorithms (AES-256-CBC\u002FCTR, ChaCha20, Salsa20) for file encryption with asymmetric algorithms (RSA-2048\u002F4096, Curve25519) for key protection. The encryption routine typically generates a random symmetric key per file, encrypts file contents, then encrypts the symmetric key with the attacker's embedded public key. Reverse engineering these routines identifies the specific algorithms, key derivation methods, initialization vectors, file targeting patterns, and potential implementation flaws that could enable decryption without paying the ransom. Notable examples include Rhysida (AES-256-CTR + RSA-4096), Qilin.B (AES-256-CTR with AES-NI or ChaCha20 fallback), and Medusa (AES-256 + RSA).\n\n\n## When to Use\n\n- When performing authorized security testing that involves reverse engineering ransomware encryption routine\n- When analyzing malware samples or attack artifacts in a controlled environment\n- When conducting red team exercises or penetration testing engagements\n- When building detection capabilities based on offensive technique understanding\n\n## Prerequisites\n\n- IDA Pro or Ghidra for static disassembly\n- x64dbg\u002FWinDbg for dynamic debugging\n- Python 3.9+ with `pycryptodome`, `pefile`\n- Understanding of AES, RSA, ChaCha20, Curve25519 algorithms\n- Knowledge of Windows CryptoAPI and CNG (BCrypt) functions\n- Sandbox environment for safe execution\n\n## Key Concepts\n\n### Hybrid Encryption Model\n\nRansomware generates a unique AES key and IV for each file. The file content is encrypted with this symmetric key. The symmetric key is then encrypted with the attacker's RSA public key (embedded in the binary or fetched from C2). The encrypted key is appended or prepended to the encrypted file. Only the attacker holding the RSA private key can decrypt the per-file symmetric keys.\n\n### Cryptographic API Identification\n\nWindows ransomware typically uses CryptoAPI (`CryptAcquireContext`, `CryptGenKey`, `CryptEncrypt`) or CNG (`BCryptGenerateSymmetricKey`, `BCryptEncrypt`). Some use OpenSSL or custom implementations. Identifying these API calls provides immediate insight into the algorithm, key size, and mode of operation.\n\n### Implementation Flaws\n\nDecryption opportunities arise from: hardcoded encryption keys, weak PRNG for key generation (using `GetTickCount` or `time()` as seed), reuse of IVs across files, ECB mode usage, keys remaining in memory post-encryption, and race conditions where keys can be captured during encryption.\n\n## Workflow\n\n### Step 1: Identify Cryptographic Functions\n\n```python\n#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Identify cryptographic functions in ransomware PE files.\"\"\"\nimport pefile\nimport sys\n\nCRYPTO_APIS = {\n    # Windows CryptoAPI\n    \"CryptAcquireContextA\": \"CryptoAPI context acquisition\",\n    \"CryptAcquireContextW\": \"CryptoAPI context acquisition\",\n    \"CryptGenKey\": \"Key generation\",\n    \"CryptDeriveKey\": \"Key derivation\",\n    \"CryptEncrypt\": \"Encryption operation\",\n    \"CryptDecrypt\": \"Decryption operation\",\n    \"CryptImportKey\": \"Key import (public key?)\",\n    \"CryptExportKey\": \"Key export\",\n    \"CryptGenRandom\": \"Random number generation\",\n    \"CryptCreateHash\": \"Hash creation\",\n    \"CryptHashData\": \"Hashing operation\",\n    # Windows CNG (BCrypt)\n    \"BCryptOpenAlgorithmProvider\": \"CNG algorithm initialization\",\n    \"BCryptGenerateSymmetricKey\": \"CNG symmetric key generation\",\n    \"BCryptEncrypt\": \"CNG encryption\",\n    \"BCryptDecrypt\": \"CNG decryption\",\n    \"BCryptGenerateKeyPair\": \"CNG key pair generation\",\n    \"BCryptImportKeyPair\": \"CNG key import\",\n    # OpenSSL\n    \"EVP_EncryptInit_ex\": \"OpenSSL encrypt init\",\n    \"EVP_EncryptUpdate\": \"OpenSSL encrypt update\",\n    \"EVP_EncryptFinal_ex\": \"OpenSSL encrypt final\",\n    \"RSA_public_encrypt\": \"OpenSSL RSA encryption\",\n    \"AES_set_encrypt_key\": \"OpenSSL AES key setup\",\n    # File operations\n    \"CreateFileW\": \"File open (target files)\",\n    \"ReadFile\": \"File read (before encryption)\",\n    \"WriteFile\": \"File write (after encryption)\",\n    \"FindFirstFileW\": \"File enumeration (targeting)\",\n    \"FindNextFileW\": \"File enumeration\",\n    \"MoveFileW\": \"File rename (extension change)\",\n    \"DeleteFileW\": \"File deletion (originals)\",\n}\n\nAES_SBOX = bytes([\n    0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,\n    0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,\n])\n\nCHACHA20_CONSTANT = b\"expand 32-byte k\"\n\n\ndef analyze_imports(filepath):\n    \"\"\"Analyze PE imports for cryptographic APIs.\"\"\"\n    try:\n        pe = pefile.PE(filepath)\n    except pefile.PEFormatError:\n        print(\"[-] Not a valid PE file\")\n        return\n\n    print(\"[+] Cryptographic API Analysis\")\n    print(\"=\" * 60)\n\n    crypto_imports = []\n    if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):\n        for entry in pe.DIRECTORY_ENTRY_IMPORT:\n            dll = entry.dll.decode('utf-8', errors='replace')\n            for imp in entry.imports:\n                if imp.name:\n                    name = imp.name.decode('utf-8', errors='replace')\n                    if name in CRYPTO_APIS:\n                        desc = CRYPTO_APIS[name]\n                        crypto_imports.append((dll, name, desc))\n                        print(f\"  [{dll}] {name}: {desc}\")\n\n    if not crypto_imports:\n        print(\"  No known crypto APIs found in imports\")\n        print(\"  Malware may use custom implementation or dynamic loading\")\n\n    return crypto_imports\n\n\ndef find_crypto_constants(filepath):\n    \"\"\"Search for embedded cryptographic constants.\"\"\"\n    with open(filepath, 'rb') as f:\n        data = f.read()\n\n    print(\"\\n[+] Cryptographic Constants Search\")\n    print(\"=\" * 60)\n\n    # AES S-Box\n    offset = data.find(AES_SBOX)\n    if offset != -1:\n        print(f\"  AES S-Box found at offset 0x{offset:x}\")\n\n    # ChaCha20\u002FSalsa20 constant\n    offset = data.find(CHACHA20_CONSTANT)\n    if offset != -1:\n        print(f\"  ChaCha20 constant at offset 0x{offset:x}\")\n\n    # RSA public key markers\n    rsa_markers = [\n        b'-----BEGIN PUBLIC KEY-----',\n        b'-----BEGIN RSA PUBLIC KEY-----',\n        b'\\x30\\x82',  # ASN.1 SEQUENCE\n    ]\n    for marker in rsa_markers:\n        offset = data.find(marker)\n        if offset != -1:\n            print(f\"  RSA key marker at offset 0x{offset:x}\")\n\n    # Common ransomware file extension patterns\n    import re\n    ext_pattern = re.compile(rb'\\.\\w{3,10}(?=\\x00)', re.IGNORECASE)\n    extensions = set()\n    for match in ext_pattern.finditer(data):\n        ext = match.group().decode('ascii', errors='replace').lower()\n        target_exts = [\n            '.doc', '.docx', '.xls', '.xlsx', '.pdf', '.ppt',\n            '.jpg', '.png', '.sql', '.mdb', '.bak', '.zip',\n        ]\n        if ext in target_exts:\n            extensions.add(ext)\n\n    if extensions:\n        print(f\"\\n  Target file extensions: {', '.join(sorted(extensions))}\")\n\n\nif __name__ == \"__main__\":\n    if len(sys.argv) \u003C 2:\n        print(f\"Usage: {sys.argv[0]} \u003Cransomware_sample>\")\n        sys.exit(1)\n\n    analyze_imports(sys.argv[1])\n    find_crypto_constants(sys.argv[1])\n```\n\n### Step 2: Analyze Encryption Flow\n\n```python\ndef analyze_encryption_pattern(filepath):\n    \"\"\"Analyze file encryption patterns from ransomware artifacts.\"\"\"\n    import os\n    import struct\n\n    with open(filepath, 'rb') as f:\n        data = f.read()\n\n    file_size = len(data)\n    print(f\"\\n[+] Encrypted File Analysis: {filepath}\")\n    print(f\"  Size: {file_size:,} bytes\")\n\n    # Check for appended key material (common pattern)\n    # Many ransomware families append encrypted key at end of file\n    tail_sizes = [256, 512, 1024, 2048]  # Common RSA ciphertext sizes\n    for size in tail_sizes:\n        if file_size > size + 16:\n            tail = data[-size:]\n            # High entropy suggests encrypted data\n            entropy = calculate_entropy(tail)\n            if entropy > 7.5:\n                print(f\"  Possible encrypted key ({size} bytes) \"\n                      f\"at end of file (entropy: {entropy:.2f})\")\n\n    # Check for header modifications\n    # Many ransomware prepend metadata\n    header = data[:64]\n    print(f\"  First 16 bytes: {header[:16].hex()}\")\n\n    # Check if original file header is preserved\n    known_headers = {\n        b'PK': 'ZIP\u002FOffice',\n        b'\\x89PNG': 'PNG',\n        b'\\xff\\xd8\\xff': 'JPEG',\n        b'%PDF': 'PDF',\n        b'\\xd0\\xcf\\x11\\xe0': 'OLE (DOC\u002FXLS)',\n    }\n    for magic, ftype in known_headers.items():\n        if header.startswith(magic):\n            print(f\"  Original format preserved: {ftype}\")\n            break\n    else:\n        print(\"  Original header destroyed\u002Fencrypted\")\n\n\ndef calculate_entropy(data):\n    \"\"\"Calculate Shannon entropy of data.\"\"\"\n    from collections import Counter\n    import math\n\n    if not data:\n        return 0\n\n    freq = Counter(data)\n    length = len(data)\n    entropy = -sum(\n        (count \u002F length) * math.log2(count \u002F length)\n        for count in freq.values()\n    )\n    return entropy\n```\n\n## Validation Criteria\n\n- Cryptographic algorithms identified (AES, RSA, ChaCha20, etc.)\n- Key size and mode of operation determined\n- Key generation method analyzed for potential weaknesses\n- Per-file key encryption scheme documented\n- File targeting patterns and extension list extracted\n- Embedded public keys extracted for infrastructure correlation\n- Potential decryption opportunities assessed\n\n## References\n\n- [Morphisec - Breaking Down Ransomware Encryption](https:\u002F\u002Fwww.morphisec.com\u002Fblog\u002Fbreaking-down-ransomware-encryption-key-strategies-algorithms-and-implementation-trends\u002F)\n- [Emsisoft - Ransomware Encryption Methods](https:\u002F\u002Fwww.emsisoft.com\u002Fen\u002Fblog\u002F27649\u002Fransomware-encryption-methods\u002F)\n- [Halcyon Ransomware Power Rankings Q4-2024](https:\u002F\u002Fwww.halcyon.ai\u002Fraas-mq\u002Fpower-rankings-ransomware-malicious-quartile-q4-2024)\n- [No More Ransom Project](https:\u002F\u002Fwww.nomoreransom.org\u002F)\n- [MITRE ATT&CK T1486 - Data Encrypted for Impact](https:\u002F\u002Fattack.mitre.org\u002Ftechniques\u002FT1486\u002F)\n",{"name":5,"tags":25,"author":34,"domain":35,"license":15,"version":36,"subdomain":33,"description":7},[26,27,28,29,30,31,32,33],"ransomware","encryption","reverse-engineering","cryptanalysis","aes","rsa","decryption","malware-analysis","mahipal","cybersecurity","1.0","main","c2b1fdccc779e99ac814e55fb69ca8d71215dd0f","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection","https:\u002F\u002Fgithub.com\u002FSamuelChien","http:\u002F\u002Fsamuelchien.com\u002F","2026-05-26 08:27:14",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add SamuelChien\u002Fmega-skills-collection --skill reverse-engineering-ransomware-encryption-routine",{"tool":49,"command":50},"bunx","bunx skills add SamuelChien\u002Fmega-skills-collection --skill reverse-engineering-ransomware-encryption-routine",{"tool":52,"command":53},"pnpm","pnpm dlx skills add SamuelChien\u002Fmega-skills-collection --skill reverse-engineering-ransomware-encryption-routine","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002FSKILL.md",true,[57,63,67,73,77,81,87],{"path":58,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":61,"sourceHtmlUrl":62},"assets\u002Ftemplate.md","ASSET","资产文件",849,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002Fassets\u002Ftemplate.md",{"path":64,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":66,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":68,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":71,"sourceHtmlUrl":72},"references\u002Fapi-reference.md","REFERENCE","参考文档",1902,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002Freferences\u002Fapi-reference.md",{"path":74,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fstandards.md",1168,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002Freferences\u002Fstandards.md",{"path":78,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fworkflows.md",1698,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002Freferences\u002Fworkflows.md",{"path":82,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":85,"sourceHtmlUrl":86},"scripts\u002Fagent.py","SCRIPT","脚本",6767,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002Fscripts\u002Fagent.py",{"path":88,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":89,"sourceHtmlUrl":90},"scripts\u002Fprocess.py",5561,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Freverse-engineering-ransomware-encryption-routine\u002Fscripts\u002Fprocess.py",[92,100,107,114,121,128],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":96,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":20},"01M76R4WZQZAXGGXMQCA0FZ716","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.","MIT","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":96,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":20},"01M76R4T9KENDH7FENGZQHBW4G","zustand-store-creator","Zustand Store Creator - Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":96,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":20},"01M76R3YWN84B7SANJ52X799ZE","zero-trust-config-helper","Zero Trust Config Helper - Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":96,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":20},"01M76R3HNSV2AEYSKHM915GJ58","zapier-integration-helper","Zapier Integration Helper - Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":127,"publishedAt":20},"01M76R3DJSKAT4FA7DV4BF3GCE","zai-cli","Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP.\nUse when user needs image\u002Fvideo analysis, OCR, UI-to-code conversion, error diagnosis,\nreal-time web search, web page to markdown extraction, or GitHub code exploration.\nTrigger with phrases like \"analyze this image\", \"search the web for\", \"read this page\",\n\"explore this repo\", or \"use zai\". Requires Z_AI_API_KEY.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzai-cli\u002FSKILL.md",[],[],{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":96,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":20},"01M76R2KAM699XE9AJVAWE4H2E","yt-research","Research competitor YouTube channels, niches, and trending topics for your content strategy.\nUse this skill whenever the user says \"research channels\", \"analyze competitors\", \"find trending topics\",\n\"niche analysis\", \"competitive research\", \"what are other creators doing\", \"scrape YouTube channels\",\nor wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fyt-research\u002FSKILL.md",[],[]]