Courseiva
Security OperationsmediumMultiple ChoiceObjective-mapped

CS0-003 Security Operations Practice Question

An analyst is creating a YARA rule to detect a specific malware family that uses the string 'evil' in its PE file. Which of the following rule structures is correct?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

rule detect_malware { strings: $a = "evil" condition: $a }

The standard YARA rule structure includes rule name, meta section, strings section, and condition section. The condition must reference the string.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • rule detect_malware { strings: $a = "evil" condition: $a }

    Why this is correct

    This is the correct YARA rule syntax. It defines a rule named detect_malware, declares a string identifier $a assigned to the literal byte sequence "evil" inside the strings section, and then uses that identifier as the condition. The condition $a evaluates to true if the string 'evil' is found anywhere in the scanned file. YARA requires a dollar-sign prefix for string identifiers, an equals sign to bind the literal value, and a condition that references the identifier without quotes or further assignment. This rule compiles and will trigger a match when the file contains the specified string.

  • rule detect_malware { strings: "evil" condition: $a }

    Why it's wrong here

    This rule is invalid because in YARA, every string entry in the strings section must be bound to a named identifier that begins with a dollar sign, such as $a. Here, the literal "evil" is written without any identifier, so the parser has no way to associate it with the $a referenced later in the condition. As a result, $a in the condition is an undeclared identifier, causing a compilation error. The correct syntax is $a = "evil" inside the strings section, not a bare literal.

  • rule detect_malware { condition: $a = "evil" }

    Why it's wrong here

    This rule fails because it tries to define a string assignment directly inside the condition block. YARA's condition section accepts only boolean expressions, such as references to string identifiers or logical operators; it does not allow equals-sign assignments of literals. Additionally, there is no strings section at all, so $a is never defined anywhere in the rule. For a valid rule, you must declare $a in a separate strings: section and then simply reference it in the condition, e.g., condition: $a.

  • if "evil" in file then alert

    Why it's wrong here

    This is not proper YARA syntax—it resembles an imperative scripting language like Perl or Python, but YARA is a declarative rule language. A YARA rule does not contain an 'if ... in file then alert' construct; instead, it consists of a rule name, optional metadata, a strings section, and a condition that is a boolean expression. The phrase 'in file' is not a valid YARA operator, and YARA does not include imperative actions like 'then alert'—the rule either matches or does not based solely on the condition. A valid equivalent would be a rule with a condition like $a, not an alert statement.

About these practice questions

One of 236 original CS0-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CS0-004 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CS0-004 exam.