Overview
In this tutorial, you will learn how to write custom SpecterScripts to customize or augment the ones provided out-of-the-box. A SpecterScript is just a PowerShell script that can reference the built-in cmdlets provided by the Specter host environment.
Write a Basic SpecterScript
Let’s say you need a basic command to find all Microsoft Office documents that have been recently edited by users on the system. How do you get that information using SpecterInsight? The best and most repeatable way is to create a SpecterScript.
Draft the Script
The recommended way to create a SpecterScript is to first write and test most of the script in a local development environment like the PowerShell Integrated Scripting Environment (ISE).
If your script needs something from the Specter runtime environment, then the best way to do that is to spin up a Specter and write your script by tasking a Specter through an interactive session.
$files = gci "C:\Users\*" -Include @("*.doc", "*.docx", "*.xls", "*.xlsx","*.ppt", "*.pptx") -Recurse -ErrorAction SilentlyContinue;
$files | Select LastWriteTime,Length,FullName
Create a New SpecterScript
Define the SpecterScript Metadata
Each SpecterScript has several metadata fields that are used for searching and filtering as well as documentation for any other users who might reference these SpecterScript. Here is an overview of the different fields:
- Name: A short name for the script.
- Description: A short and concise description of the script that goes into some detail about what the script does without taking up to much space in the SpecterScript Search Panel later on.
- Labels: A set of labels to aid filtering and searching as well as backend analytics in ELK. At a minimum, you should include labels based on the Mitre ATT&CK matrix. In this case, we’ve added the “discovery” and “file-and-directory-discovery” labels.
- Documentation: The documentation field contains markdown that is rendered when searching for scripts in the SpecterScript Search Panel later on. The following sub-fields are recommended:
- Overview: A detailed description of what the script does and how it does it.
- Dependencies: A list of modules this script depends upon.
- Operating Systems: A list of operating systems this script will work on.
- Example Output: This is probably the most important field as it gives any potential users an idea of what the output from this script will look like.