def rule(event):
    if all(
        [
            any(
                [
                    event.deep_get("Image", default="").endswith("\\reg.exe"),
                    event.deep_get("OriginalFileName", default="") == "reg.exe",
                ]
            ),
            " add " in event.deep_get("CommandLine", default=""),
            "\\CurrentControlSet\\Control\\Terminal Server"
            in event.deep_get("CommandLine", default=""),
            "REG_DWORD" in event.deep_get("CommandLine", default=""),
            " /f" in event.deep_get("CommandLine", default=""),
            any(
                [
                    all(
                        [
                            "Licensing Core" in event.deep_get("CommandLine", default=""),
                            "EnableConcurrentSessions" in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                    any(
                        [
                            "AllowTSConnections" in event.deep_get("CommandLine", default=""),
                            "fDenyTSConnections" in event.deep_get("CommandLine", default=""),
                            "fEnableWinStation" in event.deep_get("CommandLine", default=""),
                            "fSingleSessionPerUser" in event.deep_get("CommandLine", default=""),
                            "IdleWinStationPoolCount" in event.deep_get("CommandLine", default=""),
                            "MaxInstanceCount" in event.deep_get("CommandLine", default=""),
                            "SecurityLayer" in event.deep_get("CommandLine", default=""),
                            "TSAdvertise" in event.deep_get("CommandLine", default=""),
                            "TSAppCompat" in event.deep_get("CommandLine", default=""),
                            "TSEnabled" in event.deep_get("CommandLine", default=""),
                            "TSUserEnabled" in event.deep_get("CommandLine", default=""),
                            "WinStations\\RDP-Tcp" in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                ]
            ),
            not all(
                [
                    "SecurityLayer" in event.deep_get("CommandLine", default=""),
                    "02" in event.deep_get("CommandLine", default=""),
                ]
            ),
        ]
    ):
        return True
    return False
