def rule(event):
    if all(
        [
            any(
                [
                    event.deep_get("TargetImage", default="").endswith("\\cmd.exe"),
                    event.deep_get("TargetImage", default="").endswith("\\powershell.exe"),
                    event.deep_get("TargetImage", default="").endswith("\\pwsh.exe"),
                ]
            ),
            not any(
                [
                    event.deep_get("SourceImage", default="").startswith("C:\\Windows\\System32\\"),
                    event.deep_get("SourceImage", default="").startswith("C:\\Windows\\SysWOW64\\"),
                    event.deep_get("SourceImage", default="").startswith(
                        "C:\\Program Files (x86)\\"
                    ),
                    event.deep_get("SourceImage", default="").startswith("C:\\Program Files\\"),
                ]
            ),
            not event.deep_get("SourceImage", default="").endswith("\\MsMpEng.exe"),
        ]
    ):
        return True
    return False
