Example Advanced EPL RulesExample Advanced EPL Rules
Following are the examples of Advanced ESA rules. Each example has multiple ways of implementing the same use-case.
For best practices on writing advanced EPL rules, see ESA Rule Writing Best Practices.
Example #1:Example #1:
Create a user account and delete the same user account in 300s. User information is stored in user_src meta.
EPL #1:EPL #1:
Rule Name | CreateAndDelete Useraccount1 |
Rule Description | Create a user account followed by an action to delete the same user account in 300 seconds. |
Rule Code |
@RSAAlert(oneInSeconds=0) match_recognize (partition by user_src |
Note |
|
EPL #2:EPL #2:
Rule Name | CreateAndDeleteUseraccount2 |
Rule Description | Create a user account followed by an action to delete the same user account in 300 seconds. |
Rule Code |
@RSAAlert(oneInSeconds=0) -> ( Event(ec_subject='User' AND ec_outcome='Success' AND user_dst is NOT NULL AND ec_activity IN ('Create') AND user_src = a.user_src)) )where timer:within(300 Sec) ]; |
Note |
|
Example #2:Example #2:
Detect pattern where user created followed by login by same user and user is deleted in end. In case of windows logs user info is stored in either user_dst or user_src depending on event.
user_src(create) = user_dst(Login) = user_src(Delete)
EPL #3:EPL #3:
Rule Name | CreateUserLoginandDeleteUser |
Rule Description | Detect a pattern where a user creates a User account followed by login by the same user followed by deletion of the User account. |
Rule Code |
@RSAAlert(oneInSeconds=0) |
Note |
|
EPL #4: Using NamedWindows and match recognizeEPL #4: Using NamedWindows and match recognize
Rule Name | CreateUserLoginandDeleteUser |
Rule Description | Detect a pattern where a user creates a User account followed by login by the same user followed by deletion of the User account. |
Rule Code |
@Name('NormalizedWindow') create window FilteredEvents.win:time(300 sec) (user String, ecactivity string, sessionid Long); @Name('UsersrcEvents') Insert into FilteredEvents select user_src as user, ec_activity as ecactivity, sessionid from Event( ec_subject='User' and ec_activity in ('Create','Delete') and ec_theme in ('UserGroup', 'Authentication') and ec_outcome='Success' and user_src is not null ); @Name('UsrdstEvents') Insert into FilteredEvents select user_dst as user, ec_activity as ecactivity, sessionid from Event( ec_subject='User' and ec_activity in (Logon’) and ec_theme in ('UserGroup', 'Authentication') and ec_outcome='Success' and user_dst is not null ); @Name('Pattern') @RSAAlert(oneInSeconds=0, identifiers={"user"}) select * from FilteredEvents |
EPL #5: Using Every @RSAAlert(identifiers={"user_src"})EPL #5: Using Every @RSAAlert(identifiers={"user_src"})
Rule Name | CreateUserLoginandDeleteUser |
Rule Description |
Detect a pattern where a user creates a User account followed by login by the same user followed by deletion of the User account. |
Rule Code |
SELECT a.time as time,a.ip_src as ip_src,a.user_dst as user_dst,a.ip_dst as ip_dst,a.alias_host as alias_host from pattern[every (a=Event (ec_subject='User' and ec_activity='Create' and ec_theme='UserGroup' and ec_outcome='Success') -> (Event(ec_subject='User' and ec_activity='Logon' and ec_theme='Authentication' and user_src=a.user_dst) -> b=Event(ec_subject='User' and ec_activity='Delete' and ec_theme='UserGroup' and user_dst=a.user_dst))) where timer:within(300 sec)]; |
Example #3:Example #3:
Excessive login failures from same sourceIP.
EPL #6: @RSAAlert(identifiers={"ip_src"})EPL #6: @RSAAlert(identifiers={"ip_src"})
Rule Name | ExcessLoginFailure | ||||||||||||||||||||||||||||||||||||||||||||
Rule Description | The same user tried logging in from the same Source IP and faced login failures. | ||||||||||||||||||||||||||||||||||||||||||||
Rule Code |
@RSAAlert(oneInSeconds=0) |
||||||||||||||||||||||||||||||||||||||||||||
Note |
In the below sequence of events at t=301 even though 10 login failures occurred for the same login in the last 300 secs, there will be no alert because the batch of events was dropped at t=300.
|
||||||||||||||||||||||||||||||||||||||||||||
EPL #7: @RSAAlert(identifiers={"ip_src"})EPL #7: @RSAAlert(identifiers={"ip_src"})
Rule Name | ExcessLoginFailure |
Rule Description | The same user tried logging in from the same Source IP and faced login failures. |
Rule Code |
@RSAAlert(oneInSeconds=0) |
Note |
|
Example #4:Example #4:
Multiple failed logins from multiple different users from same source to same destination, a single user from multiple different sources to same destination.
EPL #8: using time_batchEPL #8: using time_batch
Rule Name | MultiplefailedLogins |
Rule Description | There are multiple failed logins for the following cases: - From multiple users from same source to same destination. - Single user from multiple sources to the same destination. |
Rule Code |
@RSAAlert(oneInSeconds=0) ec_activity='Logon' AND ec_outcome='Failure' AND ip_src IS NOT NULL AND ip_dst IS NOT NULL AND user_dst IS NOT NULL ) .win:time_batch(300 seconds) group by ip_src,ip_dst having count(distinct user_dst) >= 5; |
Note |
|
Example #5:Example #5:
No Log traffic from a device in a given timeframe.
EPL #9: using timer:intervalEPL #9: using timer:interval
Rule Name | NoLogTraffic |
Rule Description | There is no log traffic observed from a device in a given time frame. |
Rule Code |
SELECT * FROM pattern [every a = Event(device_ip IN ('10.0.0.0','10.0.0.1') AND medium = 32) -> (timer:interval (3600 seconds) AND NOT Event(device_ip = a.device_ip AND device_type = a.device_type AND medium = 32))]; |
Note |
|
Example #6:Example #6:
Multiple Failed Logins NOT followed by a Lockout event by the same user.
EPL #10: using timer and LockoutEPL #10: using timer and Lockout
Rule Name | FailedloginswoLockout |
Rule Description | There are multiple failed logins that are not followed by Lockout event by the same user. |
Rule Code |
|
Note |
|
Example #7:Example #7:
Custom functions to perform LIKE and REGEX operations for ARRAY elements.
EPL #11: @RSAAlert(oneInSeconds=0)EPL #11: @RSAAlert(oneInSeconds=0)
Rule Name | MatchLikeRegex |
Rule Description | There are custom functions to perform LIKE and REGEX comparisons of array meta keys. |
Rule Code |
|
Note:
1. “.” in meta keys should be replaced with (”_”).
2. All patterns should be time bound.
3. Use appropriate tags in front of statements, for example:
@RSAPersist:
@RSAAlert:
For additional details you can refer to:
- EPL Documentation: http://www.espertech.com/esper/esper-documentation/
- EPL Online Tool: http://esper-epl-tryout.appspot.com/epltryout/mainform.html