Skip to main content

"New to Google SecOps" is a deep-dive series by Google Cloud Principal Security Strategist John Stoner which provides practical guidance for security teams that are either new to SIEM or replacing their SIEM with Google SecOps.

Previously, I introduced contextual awareness and demonstrated how entity data is automatically enriched into events for analysts to use when searching–provided you are loading this data into Google SecOps.

Today, let’s move forward and show how to apply this capability to our YARA-L rules. To ensure everyone is on the same page, we will start with the search we used at the end of the contextual awareness post. We are looking for process command lines that execute the net use command that then attempt to map to C$, ADMIN$ or IPC$.

metadata.event_type = "PROCESS_LAUNCH" AND target.process.command_line = /net.*use.*(c|admin|ipc)\\$/ nocase

We can easily convert this search to a YARA-L rule. Here is what that search looks like converted to a rule.

rule mitre_attack_T1021_002_windows_admin_share { meta: author = "Google Cloud Security" description = "Net use commands for SMB/Windows admin shares" reference = "https://attack.mitre.org/techniques/T1021/002/" events: $process.target.process.command_line = /net.*use.*(C|ADMIN|IPC)\\$/ nocase $process.principal.user.userid = $userid match: $userid over 5m condition: $process }
 

The Detections screen indicates this rule is detecting the activity for both Sysmon and Windows event data. So far, so good.

Creating a Rule Based on Contextual Enrichment

The detection results indicate that there are Information Technology (IT) users accessing these administrative shares. For this example, this access is part of an IT user's normal workflow and alerting on every event may not be ideal. We can refine our rule to eliminate the members of the IT department.

To do so, we can refer back to our blog on single event rules, where we mentioned that the events section of YARA-L is where our criteria resides. Because we are associating an event with an entity, you might be thinking we need to apply the concepts of a multi-event rule to join the event data to the entity. Depending on the fields we are looking to leverage in our rules, we may not need to.

So, you are saying the answer is that it depends…

Yes, it does depend. If you recall, Google SecOps automatically enriches UDM events with entity values for users and assets. Fields that contain entity information like department, company, title, and address are automatically enriched in UDM if you are ingesting contextual data like Workspace, Active Directory and the like. Therefore, we don’t need to join the events and entities together to update our rule to filter out the IT department; we can use the fields that exist in the UDM events. Below, we’ve added criteria (line 11) that uses enriched entity data in the event to refine the rule. Nothing else changes in the match or condition sections of the rule.

rule mitre_attack_T1021_002_windows_admin_share_with_entity { meta: author = "Google Cloud Security" description = "Net use commands for SMB/Windows admin shares" reference = "https://attack.mitre.org/techniques/T1021/002/" events: $process.target.process.command_line = /net.*use.*(C|ADMIN|IPC)\\$/ nocase $process.principal.user.userid = $userid $process.principal.user.department != "Information Technology" match: $userid over 5m condition: $process }

In the results, the principal.user.department column is added, and we can see that a user from the Marketing department has been detected using the net.exe command to create the admin shares. 

Pro tip: checking out the columns available in the Detections screen or in the UDM search will help identify different enriched content you can use to refine your rules!

Creating a Rule with User Context from the Entity Graph

Alright, we demonstrated how entity data that has been enriched into UDM can be used for rules. But what if we wanted to bound our rule based on contextual data that is not enriched into the UDM event? Group membership of an asset or user is not enriched into the UDM event, but we can still write our rule to focus on a group.

Let’s use the same rule we have been working with, but this time, let’s focus on alerting when an admin share is being used by someone who is a member of the domain administrator (Domain Admins) group. Admittedly this may not be the best rule to focus on our domain admins, but the concept is very important because of the power a domain admin account has. So, if we can trigger this rule based on the user’s group, we can apply the same concept to any rule.

In this example, lines 11-13 are the criteria that make up the entity portion of the rule. Line 11 joins the event and the entity graph, where all of our entities and context is stored, with a common value using a placeholder variable. Line 12 describes the entity as being a user. The addition of this criteria is considered a best practice to focus the rule on just user entities. Finally, line 13 focuses our rule on the group that this rule applies to. The any in front of $user.graph.relations.entity.group.group_display_name is used with repeated fields, a field that can have a list of values in it. Prepending any to this line will allow the rules engine to evaluate each group name individually and will meet our criteria even if only a single match occurs.

Last but not least, because this rule is referencing both event variables, $process and $user, we need to ensure they are both found in the condition section of the rule. I used this naming convention to clearly define the event and the entity in my detection. Creative, I know, but descriptive.

rule mitre_attack_T1021_002_windows_admin_share_with_entity { meta: author = "Google Cloud Security" description = "Net use commands for SMB/Windows admin shares" reference = "https://attack.mitre.org/techniques/T1021/002/" events: $process.target.process.command_line = /net.*use.*(C|ADMIN|IPC)\\$/ nocase $process.principal.user.userid = $userid $user.graph.entity.user.userid = $userid $user.graph.metadata.entity_type = "USER" any $user.graph.relations.entity.group.group_display_name = "Domain Admins" match: $userid over 5m condition: $process and $user }
 

We can see that the detection contains both an entity (user) record and the associated events. If we clicked on the row under Entities, we would see the entity metadata associated with this user to the right. We would find numerous fields that describe our user entity, including the enriched values like department that we used earlier, as well as the relations.entity.group.group_display_name field we used in this example, which we’ve added to the detection view.

Today, we demonstrated two different ways to use contextual awareness that apply greater focus to our rules. These concepts apply to both asset and user entity data. As I mentioned at the start of this blog, to take advantage of this capability, we need to load entity data to Google SecOps, so if you haven’t yet, you really should!

In subsequent blogs, we will be going further into all sorts of cool stuff that can be accessed with the entity graph, so think of this as our first step, but an important one at that.

hi jstone

could you please help creating the following

1Suspicious Powershell Process Executing Encoded Command

2Suspicious PowerShell Cmdlets : Detect suspicious cmdlets used after the execution of powershell.exe: 

3) outbound Activity to C&C IP Addresses  : Alert flags potentially compromised devices within your network that are attempting to communicate with known C2 servers operated by cybercriminals. C2 servers are used by malware and threat actors to control infected systems, steal data, and execute malicious commands.

4Traffic Activity from Tor :

5SQL Injection Attempt:

6Potential Cobalt Strike Activity:

7Scheduled Cron Task:

8Processlauch Launch VT Enrichment

9Suspicious Process Injection: Detects common supicious process injections


hi jstone

could you please have a pass on the above

 


I'd suggest taking a look at the github repo of rules with a particular focus on the community section. I'd also point you to the community blogs and secops best practices on this website for blogs and videos on how to build rules that contain examples. Some of the things on the list are available there and while others might not be, these resources will provide a foundation for you to build your own rule there.

I will also mention that there are a number of curated detections built into Google SecOps that can also be enabled that may assist with some of your use cases.


hello Jstone 

while writing the rule for suspicious cmdlets i am getting thousands of detection . could you help me finetune this

 

 


i am gettting around 50k plus result per day even after adding

$powershell.target.security_result.threat_verdict != "undetected" nocase

i am not able to identify the legitimate process

 

 

 

 


I don't have a great answer for you on this. Much of this fine-tuning is going to come down to the threat posture and risk tolerance of the organization and what they want to be detecting. For instance the mppreference commandlets are tied to Microsoft Defender. Is that something you want to be alerted to everytime someone issues a command for it? 

Similar with start-process, download or iex. If these things are allowed within an organization, I suspect there will be large amounts of them and just the presence of them doesn't make them suspicious, but perhaps who is issuing them and from there as well as the switches being used.

To wrangle something like PowerShell cmdlets, it might be good to understand what the policy of the organization is around these things and use that as a starting point and perhaps use a search first to identify the total pool of these cmdlets floating around and being used and by whom and then having a conversation with leadership to understand what needs to be alerted on and what can be considered benign and then evolving the rule to take into account those guidelines. For instance, maybe the IT staff can be using many of these cmdlets but only from certain IP ranges. 


hey jstone

greetings..!!

while working on interactive login attempts from service account

the ad i am working doesn't follow any naming convention for service account

so is there anyway i can identify service account from user login attempts 

i was think about using sid , like sid s-1-5-80 or s-1-5-18 to 21

is there any other way to identify all service account ?

thanks in advance

naseef