Skip to main content
Question

Rules using the strings.base64_decode and the regex involved.

  • December 19, 2025
  • 2 replies
  • 72 views

mccrilb
Forum|alt.badge.img+12

I spent a good amount of time, well, AI and I spent a good amount of time,  working out a regex that would actually work in our environment. What I ended up with seems to work very well. I wanted to share this, and maybe someone has a better way, or there is some obvious gap that I am not taking account for? 

 

(((($event.metadata.event_type = "PROCESS_LAUNCH"

       

        and $event.target.process.command_line = /.*powershell.*/ nocase

        and $event.target.process.command_line = /(?:^|\s)-(?:encodedcommand|enco(?:ded)?|enc|ec)\b\s*:?\s*(?:"([^"]+)"|'([^']+)'|([A-Za-z0-9+\/=]+))(?:\s|$)/ nocase

        and $encodedPS = re.capture($event.target.process.command_line, `(?i)(?:-encodedcommand|-enco(?:ded)?|-enc|-ec|-en)\s*:?\s*(?:["'])?([A-Za-z0-9+/]+={0,2})(?:["'])?(?:\s|$)`)

   

        and $decoded_value = re.replace(

            strings.base64_decode(

            re.capture(

                        $event.target.process.command_line,

                        `(?i)(?:-encodedcommand|-enco(?:ded)?|-enc|-ec|-en)\s*:?\s*(?:["'])?([A-Za-z0-9+/]+={0,2})(?:["'])?(?:\s|$)`

                        )

                        ),

                        `\x00`, ``   // remove UTF-16LE NUL bytes

            )

 

        )

        )

 

   

        and $event.principal.hostname = $hostname

        and $event.principal.user.userid = $user

        )

   

         and $decoded_value in %yourcommandlist.commands nocase

        )

2 replies

Eoved
Forum|alt.badge.img+8
  • Bronze 2
  • December 25, 2025

Hi, I think that if you can provide some log samples, we can check if there is a better way.
 


mccrilb
Forum|alt.badge.img+12
  • Author
  • Silver 2
  • December 26, 2025

I don’t think that I can share the actual logs that I am seeing. So far I have not found anything outside of legit activity. The rules does look to be working correctly, the only failures that I have had are from multiple layers of encryption.  Which some of our admin tools are doing.