Skip to main content
Solved

Yara to count the no. of any characters repeated in the command line

  • February 22, 2024
  • 2 replies
  • 16 views

Forum|alt.badge.img+1

1. Is there any way in Yara to count the no. of any characters repeated in the command line?

Below is the scenario i am trying to solve

https://redcanary.com/threat-detection-report/techniques/obfuscated-files-information/

 

 

Best answer by AymanC

How about use of re.regex. For example lets say the field that contains the command line is "

target.process.command_line" we will condition it with $process.
 
re.regex($process.
target.process.command_line, /.*%.*%.*%.*%.*%.*/)
 
The above will match 5 or more uses of %, with anything before or after it. With further exclusions that should be applied based on your environment.

2 replies

AymanC
Forum|alt.badge.img+13
  • Bronze 5
  • Answer
  • February 22, 2024

How about use of re.regex. For example lets say the field that contains the command line is "

target.process.command_line" we will condition it with $process.
 
re.regex($process.
target.process.command_line, /.*%.*%.*%.*%.*%.*/)
 
The above will match 5 or more uses of %, with anything before or after it. With further exclusions that should be applied based on your environment.

Forum|alt.badge.img+1
  • Author
  • New Member
  • February 26, 2024

Optimized approach 😁

target.process.command_line = /(.*(\\^|\\$|\\%|\\+).*){5,}/