import re


def rule(event):
    if all(
        [
            "\\GoAnywhere\\tomcat\\" in event.deep_get("ParentImage", default=""),
            any(
                [
                    all(
                        [
                            any(
                                [
                                    event.deep_get("Image", default="").endswith(
                                        "\\powershell.exe"
                                    ),
                                    event.deep_get("Image", default="").endswith(
                                        "\\powershell_ise.exe"
                                    ),
                                    event.deep_get("Image", default="").endswith("\\pwsh.exe"),
                                ]
                            ),
                            any(
                                [
                                    all(
                                        [
                                            "IEX" in event.deep_get("CommandLine", default=""),
                                            "enc" in event.deep_get("CommandLine", default=""),
                                            "Hidden" in event.deep_get("CommandLine", default=""),
                                            "bypass" in event.deep_get("CommandLine", default=""),
                                        ]
                                    ),
                                    any(
                                        [
                                            re.match(
                                                r"net\\s+user",
                                                event.deep_get("CommandLine", default=""),
                                            ),
                                            re.match(
                                                r"net\\s+group",
                                                event.deep_get("CommandLine", default=""),
                                            ),
                                            re.match(
                                                r"query\\s+session",
                                                event.deep_get("CommandLine", default=""),
                                            ),
                                        ]
                                    ),
                                    any(
                                        [
                                            "whoami" in event.deep_get("CommandLine", default=""),
                                            "systeminfo"
                                            in event.deep_get("CommandLine", default=""),
                                            "dsquery" in event.deep_get("CommandLine", default=""),
                                            "localgroup administrators"
                                            in event.deep_get("CommandLine", default=""),
                                            "nltest" in event.deep_get("CommandLine", default=""),
                                            "samaccountname="
                                            in event.deep_get("CommandLine", default=""),
                                            "adscredentials"
                                            in event.deep_get("CommandLine", default=""),
                                            "o365accountconfiguration"
                                            in event.deep_get("CommandLine", default=""),
                                            ".DownloadString("
                                            in event.deep_get("CommandLine", default=""),
                                            ".DownloadFile("
                                            in event.deep_get("CommandLine", default=""),
                                            "FromBase64String("
                                            in event.deep_get("CommandLine", default=""),
                                            "System.IO.Compression"
                                            in event.deep_get("CommandLine", default=""),
                                            "System.IO.MemoryStream"
                                            in event.deep_get("CommandLine", default=""),
                                            "curl" in event.deep_get("CommandLine", default=""),
                                        ]
                                    ),
                                ]
                            ),
                        ]
                    ),
                    any(
                        [
                            all(
                                [
                                    event.deep_get("Image", default="").endswith("\\cmd.exe"),
                                    any(
                                        [
                                            "powershell"
                                            in event.deep_get("CommandLine", default=""),
                                            "whoami" in event.deep_get("CommandLine", default=""),
                                            "net.exe" in event.deep_get("CommandLine", default=""),
                                            "net1.exe" in event.deep_get("CommandLine", default=""),
                                            "rundll32" in event.deep_get("CommandLine", default=""),
                                            "quser" in event.deep_get("CommandLine", default=""),
                                            "nltest" in event.deep_get("CommandLine", default=""),
                                            "curl" in event.deep_get("CommandLine", default=""),
                                        ]
                                    ),
                                ]
                            ),
                            any(
                                [
                                    "bitsadmin" in event.deep_get("CommandLine", default=""),
                                    "certutil" in event.deep_get("CommandLine", default=""),
                                    "mshta" in event.deep_get("CommandLine", default=""),
                                    "cscript" in event.deep_get("CommandLine", default=""),
                                    "wscript" in event.deep_get("CommandLine", default=""),
                                ]
                            ),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
