Skip to content

ShulkwiSEC/bb-huge / skills/curated/amsi-bypass

amsi-bypass

Flagged

Bypass the Windows Antimalware Scan Interface (AMSI) using memory patching, reflection, and obfuscation techniques. Execute undetected PowerShell, VBScript, JScript, and .NET assemblies in-memory without triggering Microsoft Defender or third-party AV/EDR solutions. Use this skill during Red Team engagements when loading offensive tools (Mimikatz, Rubeus, SharpHound) in memory on defended Windows endpoints.

FileKindSize
SKILL.mdskill md14.3 KB
evals/evals.jsonconfig508 B
scripts/process.pyscript6.2 KB

scripts/process.py

View on GitHub
#!/usr/bin/env python3
"""
CI/CD Execution Harness for amsi-bypass
Validates AMSI bypass technique knowledge and detection capabilities.
"""
import sys
import json
import base64
import struct
from pathlib import Path
from datetime import datetime, timezone

SKILL_NAME = "amsi-bypass"
SKILL_CATEGORY = "red-teaming/evasion"

# Known AMSI bypass patch bytes: mov eax, 0x80070057; ret
AMSI_PATCH_BYTES = bytes([0xB8, 0x57, 0x00, 0x07, 0x80, 0xC3])
# E_INVALIDARG return value
E_INVALIDARG = 0x80070057


def validate_patch_bytes() -> dict:
    """Validate that the AMSI patch bytes produce correct x86 instructions."""
    result = {"test": "patch_bytes_validation", "passed": False, "details": ""}
    
    # B8 57 00 07 80 = mov eax, 0x80070057
    # C3 = ret
    expected_eax_value = struct.unpack("<I", AMSI_PATCH_BYTES[1:5])[0]
    
    if expected_eax_value == E_INVALIDARG:
        result["passed"] = True
        result["details"] = f"Patch sets EAX to 0x{expected_eax_value:08X} (E_INVALIDARG) then returns"
    else:
        result["details"] = f"Unexpected EAX value: 0x{expected_eax_value:08X}"
    
    return result


def validate_obfuscation_strings() -> dict:
    """Test that obfuscation techniques reconstruct the correct target strings."""
    result = {"test": "obfuscation_reconstruction", "passed": False, "details": ""}
    
    # Test 1: String concatenation
    target_type = 'Sys' + 'tem.Man' + 'agement.Au' + 'tomation.Am' + 'siUt' + 'ils'
    expected_type = "System.Management.Automation.AmsiUtils"
    
    if target_type != expected_type:
        result["details"] = f"Concatenation failed: got '{target_type}'"
        return result
    
    # Test 2: Base64 encoding
    encoded = "U3lzdGVtLk1hbmFnZW1lbnQuQXV0b21hdGlvbi5BbXNpVXRpbHM="
    decoded = base64.b64decode(encoded).decode('utf-8')
    
    if decoded != expected_type:
        result["details"] = f"Base64 decode failed: got '{decoded}'"
        return result
    
    # Test 3: Field name reconstruction
    field_name = 'am' + 'siIn' + 'itFa' + 'iled'
    expected_field = "amsiInitFailed"
    
    if field_name != expected_field:
        result["details"] = f"Field concatenation failed: got '{field_name}'"
        return result
    
    result["passed"] = True
    result["details"] = "All obfuscation strings reconstruct correctly"
    return result


def validate_detection_artifacts() -> dict:
    """Validate that we document the correct detection Event IDs and sources."""
    result = {"test": "detection_coverage", "passed": False, "details": ""}
    
    required_detections = {
        "ETW_PowerShell": "Microsoft-Windows-PowerShell/Operational",
        "ETW_AMSI": "Microsoft-Antimalware-Scan-Interface",
        "Sysmon_ImageLoad": "Event ID 7",
        "Sysmon_ProcessAccess": "Event ID 10",
        "ScriptBlockLogging": "Event ID 4104",
    }
    
    mitre_technique = "T1562.001"  # Impair Defenses: Disable or Modify Tools
    mitre_tactic = "TA0005"  # Defense Evasion
    
    skill_md = Path(__file__).parent.parent / "SKILL.md"
    if not skill_md.exists():
        result["details"] = "SKILL.md not found"
        return result
    
    content = skill_md.read_text(encoding="utf-8")
    
    missing = []
    for detection_name, indicator in required_detections.items():
        if indicator not in content:
            missing.append(f"{detection_name} ({indicator})")
    
    if mitre_technique not in content:
        missing.append(f"MITRE technique {mitre_technique}")
    
    if missing:
        result["details"] = f"Missing detection coverage: {', '.join(missing)}"
        return result
    
    result["passed"] = True
    result["details"] = f"All {len(required_detections)} detection sources documented, MITRE mapping verified"
    return result


def validate_skill_structure() -> dict:
    """Validate SKILL.md has all required sections."""
    result = {"test": "skill_structure", "passed": False, "details": ""}
    
    skill_md = Path(__file__).parent.parent / "SKILL.md"
    if not skill_md.exists():
        result["details"] = "SKILL.md not found"
        return result
    
    content = skill_md.read_text(encoding="utf-8")
    
    required_sections = [
        "## When to Use",
        "## Prerequisites",
        "## Workflow",
        "### Phase 1:",
        "## 🔵 Blue Team",
        "## Key Concepts",
        "## References",
        "Decision Point",
    ]
    
    missing = [section for section in required_sections if section not in content]
    
    if missing:
        result["details"] = f"Missing sections: {', '.join(missing)}"
        return result
    
    # Check for empty/placeholder content
    if "# Placeholder" in content or "TODO" in content:
        result["details"] = "Contains placeholder/TODO content"
        return result
    
    result["passed"] = True
    result["details"] = f"All {len(required_sections)} required sections present"
    return result


def main() -> None:
    print(f"[*] Running validation harness for: {SKILL_NAME}")
    print(f"[*] Category: {SKILL_CATEGORY}")
    print(f"[*] Timestamp: {datetime.now(timezone.utc).isoformat()}")
    print("=" * 60)
    
    tests = [
        validate_patch_bytes,
        validate_obfuscation_strings,
        validate_detection_artifacts,
        validate_skill_structure,
    ]
    
    results = []
    for test_fn in tests:
        test_result = test_fn()
        results.append(test_result)
        status = "✅ PASS" if test_result["passed"] else "❌ FAIL"
        print(f"  {status} | {test_result['test']}: {test_result['details']}")
    
    print("=" * 60)
    passed = sum(1 for r in results if r["passed"])
    total = len(results)
    print(f"[{'+'if passed == total else '!'}] Results: {passed}/{total} tests passed")
    
    # Write results JSON
    output_path = Path(__file__).parent / "validation_results.json"
    with open(output_path, "w", encoding="utf-8") as output_file:
        json.dump({
            "skill": SKILL_NAME,
            "category": SKILL_CATEGORY,
            "timestamp": datetime.now(timezone.utc).isoformat(),
            "passed": passed,
            "total": total,
            "results": results,
        }, output_file, indent=2)
    
    sys.exit(0 if passed == total else 1)


if __name__ == "__main__":
    main()
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall