This article shows how to leverage the Lumu Defender API and Sophos UTM SG API to mitigate security risks.
To run the integration, you need an API key linked to a particular Firewall user. We strongly recommend setting up a restricted user to link it to the API key generated in the next step.
Create a new user for the integration using the Sophos Web Console. Go to the Users & Groups menu under the Definitions & Users section. Fill in the required data and save the user.
To set up an access role for the user to be linked with the API key, go to the WebAdmin Settings menu under the Management section. Select the Access Control tab and click on the New Role button. Fill in the requested data, and associate the user created in the step above. In the Rights section enable only the following:
Save the new role.
Using the Sophos UTM SG Web Console, go to the WebAdmin Settings under the Management section. In the WebAdmin Settings window, go to the RESTful API tab. Click in the New API Token button to create the token and attach the user created before.
There are 2 environment options to deploy the script, select the one that fits better in your current infrastructure. Whatever alternative you select, you need to unpack first the integration package shared by our Support team. Unpack the deployment package provided by Lumu in your preferred path/folder. Keep in mind this location, as it will be required for further configurations. From now on, we will refer to this folder as <sophos_lumu_root>.
In the package, you will find the script required to run the integration. To use the script, you must locate yourself on the path selected for deployment (<sophos_lumu_root>). Specific steps are included in the next sections.
If you are running different Python scripts in the selected host, it’s recommended to create a virtual environment to preserve the integrity of other tools. To do so, follow these steps:
1. Using a command line tool, locate yourself in the <sophos_lumu_root> folder
2. Run the following command to create the virtual environment
python3 -m venv <venv_folder>3. Activate the virtual environment running the following
source <venv_folder>/bin/activate
The file requirements.txt contains the list of requirements for this integration. After deploying the package locally, run the following command from the deployment folder:
To use the script, you must locate yourself on the path selected for deployment (<sophos_lumu_root>). Use the following command to show all options available for the package:
usage: sophos_lumu.py [options]
Options | Description |
---|---|
-h, --help | show this help message and exit |
--config CONFIG | Load options from config file |
--proxy-host PROXY_HOST--proxy_host PROXY_HOST | Proxy host (if required) |
--proxy-port PROXY_PORT--proxy_port PROXY_PORT | Proxy port (if required) |
--proxy-user PROXY_USER--proxy_user PROXY_USER | Proxy user (if required) |
--proxy-password PROXY_PASSWORD--proxy_password PROXY_PASSWORD | Proxy password (if required) |
--company-key COMPANY_KEY--company_key COMPANY_KEY | Lumu Company Key (Defender API). |
--logging {screen,file} | Logging option (default screen). |
--verbose, -v | Verbosity level. |
--adversary-types {C2C,Malware,Mining,Spam,Phishing--adversary_types {C2C,Malware,Mining,Spam,Phishing} | Lumu adversary types to be filtered. |
--days DAYS | The number of days backward from now to query Lumu incidents (default 30). |
--test, -t | Runs a test with one incident only. |
--clean | Cleans all rules and objects created by the Lumu integration. |
--sophos_hostname SOPHOS_HOSTNAME | Sophos SG UTM Name |
--sophos_api_token SOPHOS_API_TOKEN | Sophos SG UTM API Token |
--ioc_types {ip,url,host}--ioc-types {ip,url,host} | IOC types to be collected and processed by the integration |
To query all IPs, domains, URLs related to Lumu incidents triggered in the last 30 days, run the following command.
By default, the integration script will query incidents for the last 30 days. If you need to change this value, you can use the --days flag as follows.
In this example, the integration will query and push to the Sophos Firewall IPs, URLs, and domains related to incidents in the last 5 days
By default, the integration script will query incidents related to all adversary types. If you need to filter the query to specific adversary types, you can use the --adversary-types flag as follows
In this example, the integration will query and push to the Sophos Firewall IPs, URLs, and domainsfrom incidents related to adversaries classified as C&C and Malware.
You can run the integration using a configuration file where you can save the required arguments in the form of <argument_name>=<value>, one argument per line. In the <sophos-lumu> path, save a file named .config with your configuration. Following, you have a sample of the format of the file.
# Configuration file example company_key=abcd sophos_api_token=xyz sophos_hostname=a.b.c.d:1234 ioc-types=ip ioc-types=url ioc-types=host adversary-types=C2C adversary-types=Malware adversary-types=Mining adversary-types=Spam adversary-types=Phishing days=15
When the script is run with the –clean flag, it will erase all Lumu records created. Using this flag, you will return the sophos lists to their original state.
According to your needs, you can combine the examples shown.
To run the script on a timely basis, consider implementing a Scheduled task in Windows or a Cron task in Unix-based systems. We recommend that the scheduled job runs every 30 minutes.
Following, you have an example of how this Cron job should look using the recommended time.
It’s recommended to add the --logging file argument to any scheduled task. It will record all the output in the log file for further reference. If you have created a configuration file, your crontab entry doesn’t need arguments. It should look as follows:
If you need to work with another scheduling time, you can use the [crontab guru](https://crontab.guru) service.
To avoid race conditions, you can run only one instance. If you have one running, the second one will be canceled immediately.
If you have a Docker environment, you can select this option to run the integration as a Docker process. To deploy and run your integration as a docker container, locate yourself at the <sophos_lumu_root> folder, and follow these instructions:
1. To build the container, run the following command. Change all the flags based on the reference given in the script section above.
docker build --build-arg company_key='xxx' --build-arg sophos_api_token='xxx' --build-arg sophos_hostname='xx-xx-xx-xx-xx' --tag python-lumu-sophos .Do not forget the dot "." at the end of the line2. To run the container, run the following command:
docker run -d --name lumu-sophos python-lumu-sophos
With this mode, your integration will run every 30 minutes.
For troubleshooting purposes, you can run the following commands:
To log in to your container using an interactive shell:
To collect integration logs:
After running the integration, you will see changes in your Firewall configuration. Check the following sections to learn more about them.
All the IPs and domains related to Lumu can be found in this list. This item can be found in the Network Definitions menu under the Definitions & Users section in the Sophos Web Console.
Finally, the integration creates a new Firewall rule above all existing rules. This rule can be found in the Firewall menu under the Network Protection section in the Sophos Web Console.
The URLs related to Lumu incidents can be checked in the Websites tab. You can find it in the Filtering Options menu under the Web Protection section. All the URLs created by the integration will be associated with the Lumu tag.
Use the Lumu tag to finish your configuration. You need to associate this tag to a Filter Action, then the Filter Action to a Filter Policy. Finally, associate the Filter policy to a Filter Profile.
When creating the Filter Policy, select the Operation mode that best fits your environment. Check the Sophos SG official documentation for further reference.
To identify failures in the script execution, use the -v flag. The script execution log will show more detailed information.
If you receive the following error.
There could be another instance running. To check this, open the pid.pid file in the integration folder. This file stores the process id if it’s running. Search for this process in your system. The following pictures show the process in Windows and Linux.
If the previous validation indicates that another instance is running, please, check its progress using the integration’s log lumu.log.