AGENT SKILL

malware-ransomware-decryption

--', b'0‚', # ASN.1 SEQUENCE ] for marker in rsa_markers: offset = data.

License 许可
MIT
最近更新
2026-09-01
Stars
★ 0
Forks
0

01 前言 Front Matter

name
malware-ransomware-decryption
domain
cybersecurity
description
--', b'0‚', # ASN.1 SEQUENCE ] for marker in rsa_markers: offset = data.

02 资源文件 1

03 SKILL.md 正文

--', b'\x30\x82', # ASN.1 SEQUENCE ] for marker in rsa_markers: offset = data.find(marker) if offset != -1: print(f" RSA key marker at offset 0x{offset:x}")

# Common ransomware file extension patterns
import re
ext_pattern = re.compile(rb'\.\w{3,10}(?=\x00)', re.IGNORECASE)
extensions = set()
for match in ext_pattern.finditer(data):
    ext = match.group().decode('ascii', errors='replace').lower()
    target_exts = [
        '.doc', '.docx', '.xls', '.xlsx', '.pdf', '.ppt',
        '.jpg', '.png', '.sql', '.mdb', '.bak', '.zip',
    ]
    if ext in target_exts:
        extensions.add(ext)

if extensions:
    print(f"\n  Target file extensions: {', '.join(sorted(extensions))}")

if name == "main": if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} <ransomware_sample>") sys.exit(1)

analyze_imports(sys.argv[1])
find_crypto_constants(sys.argv[1])

### Step 2: Analyze Encryption Flow

```python
def analyze_encryption_pattern(filepath):
    """Analyze file encryption patterns from ransomware artifacts."""
    import os
    import struct

    with open(filepath, 'rb') as f:
        data = f.read()

    file_size = len(data)
    print(f"\n[+] Encrypted File Analysis: {filepath}")
    print(f"  Size: {file_size:,} bytes")

    # Check for appended key material (common pattern)
    # Many ransomware families append encrypted key at end of file
    tail_sizes = [256, 512, 1024, 2048]  # Common RSA ciphertext sizes
    for size in tail_sizes:
        if file_size > size + 16:
            tail = data[-size:]
            # High entropy suggests encrypted data
            entropy = calculate_entropy(tail)
            if entropy > 7.5:
                print(f"  Possible encrypted key ({size} bytes) "
                      f"at end of file (entropy: {entropy:.2f})")

    # Check for header modifications
    # Many ransomware prepend metadata
    header = data[:64]
    print(f"  First 16 bytes: {header[:16].hex()}")

    # Check if original file header is preserved
    known_headers = {
        b'PK': 'ZIP/Office',
        b'\x89PNG': 'PNG',
        b'\xff\xd8\xff': 'JPEG',
        b'%PDF': 'PDF',
        b'\xd0\xcf\x11\xe0': 'OLE (DOC/XLS)',
    }
    for magic, ftype in known_headers.items():
        if header.startswith(magic):
            print(f"  Original format preserved: {ftype}")
            break
    else:
        print("  Original header destroyed/encrypted")

def calculate_entropy(data):
    """Calculate Shannon entropy of data."""
    from collections import Counter
    import math

    if not data:
        return 0

    freq = Counter(data)
    length = len(data)
    entropy = -sum(
        (count / length) * math.log2(count / length)
        for count in freq.values()
    )
    return entropy

Validation Criteria

  • Cryptographic algorithms identified (AES, RSA, ChaCha20, etc.)
  • Key size and mode of operation determined
  • Key generation method analyzed for potential weaknesses
  • Per-file key encryption scheme documented
  • File targeting patterns and extension list extracted
  • Embedded public keys extracted for infrastructure correlation
  • Potential decryption opportunities assessed

References

04 同仓库更多 Skills