def rule(event):
    if all(
        [
            event.deep_get("EventID", default="") == 5156,
            any(
                [
                    all(
                        [
                            event.deep_get("SourcePort", default="") == 3389,
                            any(
                                [
                                    event.deep_get("DestAddress", default="").startswith("127."),
                                    event.deep_get("DestAddress", default="") == "::1",
                                ]
                            ),
                        ]
                    ),
                    all(
                        [
                            event.deep_get("DestPort", default="") == 3389,
                            any(
                                [
                                    event.deep_get("SourceAddress", default="").startswith("127."),
                                    event.deep_get("SourceAddress", default="") == "::1",
                                ]
                            ),
                        ]
                    ),
                ]
            ),
            not any(
                [
                    event.deep_get("FilterOrigin", default="") == "AppContainer Loopback",
                    any(
                        [
                            event.deep_get("Application", default="").endswith("\\thor.exe"),
                            event.deep_get("Application", default="").endswith("\\thor64.exe"),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
