import re


def rule(event):
    if all(
        [
            any(
                [
                    event.deep_get("Image", default="").endswith("\\csc.exe"),
                    event.deep_get("OriginalFileName", default="") == "csc.exe",
                ]
            ),
            any(
                [
                    any(
                        [
                            event.deep_get("ParentImage", default="").endswith("\\cscript.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\excel.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\mshta.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\onenote.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\outlook.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\powerpnt.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\winword.exe"),
                            event.deep_get("ParentImage", default="").endswith("\\wscript.exe"),
                        ]
                    ),
                    all(
                        [
                            any(
                                [
                                    event.deep_get("ParentImage", default="").endswith(
                                        "\\powershell.exe"
                                    ),
                                    event.deep_get("ParentImage", default="").endswith(
                                        "\\pwsh.exe"
                                    ),
                                ]
                            ),
                            any(
                                [
                                    "-Encoded " in event.deep_get("ParentCommandLine", default=""),
                                    "FromBase64String"
                                    in event.deep_get("ParentCommandLine", default=""),
                                ]
                            ),
                        ]
                    ),
                    any(
                        [
                            re.match(
                                r"(?:[Pp]rogram[Dd]ata|%(?:[Ll]ocal)?[Aa]pp[Dd]ata%|\\\\[Aa]pp[Dd]ata\\\\(?:[Ll]ocal(?:[Ll]ow)?|[Rr]oaming))\\\\[^\\\\]{1,256}$",
                                event.deep_get("ParentCommandLine", default=""),
                            ),
                            any(
                                [
                                    ":\\PerfLogs\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                    ":\\Users\\Public\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                    ":\\Windows\\Temp\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                    "\\Temporary Internet"
                                    in event.deep_get("ParentCommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("ParentCommandLine", default=""),
                                    "\\Favorites\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("ParentCommandLine", default=""),
                                    "\\Favourites\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("ParentCommandLine", default=""),
                                    "\\Contacts\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                ]
                            ),
                            all(
                                [
                                    ":\\Users\\" in event.deep_get("ParentCommandLine", default=""),
                                    "\\Pictures\\"
                                    in event.deep_get("ParentCommandLine", default=""),
                                ]
                            ),
                        ]
                    ),
                ]
            ),
            not any(
                [
                    any(
                        [
                            event.deep_get("ParentImage", default="").startswith(
                                "C:\\Program Files (x86)\\"
                            ),
                            event.deep_get("ParentImage", default="").startswith(
                                "C:\\Program Files\\"
                            ),
                        ]
                    ),
                    event.deep_get("ParentImage", default="")
                    == "C:\\Windows\\System32\\sdiagnhost.exe",
                    event.deep_get("ParentImage", default="")
                    == "C:\\Windows\\System32\\inetsrv\\w3wp.exe",
                ]
            ),
            not any(
                [
                    event.deep_get("ParentImage", default="")
                    == "C:\\ProgramData\\chocolatey\\choco.exe",
                    "\\ProgramData\\Microsoft\\Windows Defender Advanced Threat Protection"
                    in event.deep_get("ParentCommandLine", default=""),
                    any(
                        [
                            "JwB7ACIAZgBhAGkAbABlAGQAIgA6AHQAcgB1AGUALAAiAG0AcwBnACIAOgAiAEEAbgBzAGkAYgBsAGUAIAByAGUAcQB1AGkAcgBlAHMAIABQAG8AdwBlAHIAUwBoAGUAbABsACAAdgAzAC4AMAAgAG8AcgAgAG4AZQB3AGUAcgAiAH0AJw"
                            in event.deep_get("ParentCommandLine", default=""),
                            "cAewAiAGYAYQBpAGwAZQBkACIAOgB0AHIAdQBlACwAIgBtAHMAZwAiADoAIgBBAG4AcwBpAGIAbABlACAAcgBlAHEAdQBpAHIAZQBzACAAUABvAHcAZQByAFMAaABlAGwAbAAgAHYAMwAuADAAIABvAHIAIABuAGUAdwBlAHIAIgB9ACcA"
                            in event.deep_get("ParentCommandLine", default=""),
                            "nAHsAIgBmAGEAaQBsAGUAZAAiADoAdAByAHUAZQAsACIAbQBzAGcAIgA6ACIAQQBuAHMAaQBiAGwAZQAgAHIAZQBxAHUAaQByAGUAcwAgAFAAbwB3AGUAcgBTAGgAZQBsAGwAIAB2ADMALgAwACAAbwByACAAbgBlAHcAZQByACIAfQAnA"
                            in event.deep_get("ParentCommandLine", default=""),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
