def rule(event):
    if any(
        [
            all(
                [
                    event.deep_get("sc-status", default="") == 401,
                    "/autodiscover.json" in event.deep_get("cs-uri-query", default=""),
                    any(
                        [
                            "/powershell" in event.deep_get("cs-uri-query", default=""),
                            "/mapi/nspi" in event.deep_get("cs-uri-query", default=""),
                            "/EWS" in event.deep_get("cs-uri-query", default=""),
                            "X-Rps-CAT" in event.deep_get("cs-uri-query", default=""),
                        ]
                    ),
                ]
            ),
            all(
                [
                    event.deep_get("sc-status", default="") == 401,
                    any(
                        [
                            "autodiscover.json?@" in event.deep_get("cs-uri-query", default=""),
                            "autodiscover.json%3f@" in event.deep_get("cs-uri-query", default=""),
                            "%3f@foo.com" in event.deep_get("cs-uri-query", default=""),
                            "Email=autodiscover/autodiscover.json"
                            in event.deep_get("cs-uri-query", default=""),
                            "json?@foo.com" in event.deep_get("cs-uri-query", default=""),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
