Malware Intelligence
Introduction¶
The malware_intel module allows you to interact with the Recorded Future Malware Intelligence. It includes:
- Querying for known hashes
- Auto YARA rule generation based on hashes
- Auto Sigma rule generation based on hashes
- Saving generated rules to disk
See the API Reference for internal details of the module.
Notes¶
- The
reportsmethod returns at most 10 reports, with the highest sandbox score. - Use the
save_rulehelper function to write generated Auto YARA and Auto Sigma rules to disk. Auto YARA results are saved as a.yarfile named after the job, while Auto Sigma results are saved as multiple.ymlfiles named<job_name> - Rule N.yml. See the Helpers API for details.
Examples¶
Warning
The following examples demonstrate how to use this module. Be sure to add appropriate error handling as needed; all possible errors for each method or function are listed in the API Reference page.
Additionally, you must configure the RF_TOKEN environment variable before getting started. For instructions, see Learn.
1: Search for reports for a specific SHA256 hash¶
In this example you search for a query that is matching all the reports having a sha256 as defined in the sha256 argument.
The start and end date are relative to the day in which you run the example.
The output of the example is:
2: Generate a YARA rule based on hashes¶
In this example you are creating a YARA rule based on 3 known hashes of WannaCry that has been identified via the query 'sample.tags == "family:wannacry"'. Adding a query is not mandatory but useful for future reference.
By default, fetching a newly created job may return a non-terminal status such as CREATED or RUNNING, and yara_rule_str can still be None.
To simplify this flow, fetch_rule_job_result supports an optional wait_until_finished=True argument. When enabled, the client polls the job until it reaches FINISHED (or raises if the job fails or times out), so you do not need to write your own wait loop.
Once the job is created, all jobs can be printed using fetch_rule_jobs.
3: Delete the generated YARA rules¶
In this example you are going to delete all the rules generated by the token configured. This example is used to demonstrate that fetch_rule_jobs can be used to access the job ID via the job_id field, and pass it as argument of delete_rule_job.
4: Generate Sigma rules from malware query results¶
In this example you create an Auto Sigma job from a malware query and a time range, then fetch the result.
As with Auto YARA, fetch_rule_job_result supports wait_until_finished=True so the client polls until the job reaches FINISHED.
5: Delete generated Auto Sigma jobs¶
In this example you fetch all Auto Sigma jobs for the configured token and delete them one by one using delete_rule_job.