Integrate custom Python code [WIP]
How to create custom tasks using pure Python code without external commands.
The PythonRunner class allows you to create custom Secator tasks using pure Python code, without needing to integrate external command-line tools. This is useful when you want to:
Process data using Python libraries
Implement custom logic that doesn't require external commands
Create lightweight tasks that perform transformations or analysis
Build tasks that interact with APIs or databases
Overview
To create a custom Python task, you need to:
Create a Python file in
~/.secator/templates/(for user tasks) orsecator/tasks/(for development)Inherit from the
PythonRunnerclassDecorate your class with the
@task()decoratorDefine
input_typesandoutput_typesImplement the
yielder()method to yield results
Basic structure
Here's the minimal structure of a Python task:
Important notes:
The class name must match the filename (without
.py)The
@task()decorator is requiredYou must inherit from
PythonRunnerThe
yielder()method is where your task logic goesUse
yieldto return results as output types
Available input types
You can specify which input types your task accepts using input_types. Available input types include:
HOST- Hostnames or domainsURL- URLsIP- IP addressesCIDR_RANGE- CIDR rangesEMAIL- Email addressesPATH- File pathsSTRING- Generic stringsNone- Accept any input type
Example:
Available output types
Your task can yield various output types. Common ones include:
Info- Informational messagesUrl- URLsIp- IP addressesPort- Network portsSubdomain- SubdomainsVulnerability- Security vulnerabilitiesTag- Tags/metadataDomain- DomainsRecord- DNS recordsCertificate- SSL certificatesUserAccount- User accountsWarning- Warning messagesError- Error messages
Example:
Example: Simple URL processor
This example processes URLs and extracts information:
Usage:
Example: Vulnerability scanner
This example demonstrates yielding vulnerabilities:
Example: Task with custom options
You can define custom options that users can pass to your task:
Usage:
Example: Task without inputs
Some tasks don't require inputs. Use default_inputs to make inputs optional:
Usage:
Accessing runner properties
In your yielder() method, you have access to several useful properties:
self.inputs- List of input valuesself.run_opts- Dictionary of run options (including customopts)self.name- Task nameself.config- Task configurationself.context- Runner context
Example:
Advanced: Multiple output types
You can yield different output types based on your logic:
Task discovery
Secator automatically discovers tasks from:
User tasks:
~/.secator/templates/*.pyDevelopment tasks:
secator/tasks/*.py(when developing Secator itself)
The task class name must match the filename (case-sensitive). For example:
File:
~/.secator/templates/mytask.py→ Class:mytaskFile:
secator/tasks/urlparser.py→ Class:urlparser
After creating your task file, Secator will automatically discover it on the next run.
Best practices
Use descriptive class names: Choose names that clearly indicate what the task does
Add docstrings: Document what your task does in the class docstring
Set appropriate tags: Use
tagsto categorize your task for better discoverabilityHandle errors gracefully: Use
WarningorErroroutput types for error conditionsYield progress information: Use
Infomessages to provide feedback during long-running tasksValidate inputs: Check input validity before processing
Use appropriate output types: Choose the most specific output type for your results
Testing your task
You can test your task from the command line:
Or use it programmatically:
Common patterns
Pattern: Processing with external libraries
Pattern: API integration
Pattern: Data transformation
Troubleshooting
Task not discovered
Ensure the filename matches the class name exactly
Check that the file is in
~/.secator/templates/orsecator/tasks/Verify the
@task()decorator is presentMake sure the class inherits from
PythonRunner
Validation errors
If you get "Input is empty" errors, set
default_inputs = ''for tasks that don't need inputsFor tasks that accept multiple inputs, ensure you're running with a worker (multiple inputs aren't supported in non-worker mode)
Import errors
Ensure all required Python packages are installed
Check that imports are correct and available in your environment
Last updated