AWS Partner Network (APN) Blog
Preventing Malware in Serverless Web Applications with SophosLabs Intelix
By James Wilson, Sr. Product Manager at SophosLabs
By Tom Ellis, Sr. Solutions Architect ISV at AWS
Building web applications in a serverless environment has brought many advantages, including scalability and a focus on maintaining code rather than servers.
As with every big shift, however, there are certain practices such as malware protection that need to be reinvented.
Gone are the days of managing your own servers, being able to install your chosen anti-malware product, and feeling safe in the knowledge that any malicious files will be caught as they are saved to the server.
Customers are building more and more web applications that take uploaded files from application users. In a serverless environment, it’s much harder to use traditional anti-malware products to keep you and your customers safe.
To solve for this, organizations need a solution that is easy to query from web application via API with no infrastructure required. This solution needs to give a clear verdict, telling you whether a file is clean or malicious, and provide additional metadata on the findings.
In this post, we will introduce SophosLabs Intelix, a suite of APIs which provide specific, actionable intelligence about files. Intelix has been built by combining tools and information from SophosLabs and Sophos AI. Sophos is an AWS Security Competency Partner.
We’ll also cover how to use the Intelix APIs for analysis and deploy a solution to scan objects upon upload to Amazon Simple Storage Service (Amazon S3). This uses an S3 event trigger and AWS Lambda function calling to Intelix APIs, and copies valid objects to a second S3 bucket and logs the analysis results into Amazon CloudWatch Logs.
By using Intelix within a Lambda function, you can maintain your serverless infrastructure and protect assets from malicious content.
SophosLabs Intelix is available on AWS Marketplace.
SophosLabs Intelix
SophosLabs is a tier-1 threat research lab with decades of experience analyzing the global threat landscape and staying ahead of emerging threats.
The Sophos AI team, meanwhile, is pushing the boundaries of applying machine learning (ML) and other techniques to cybersecurity.
The combination of these teams’ efforts led to a powerful solution which is provided through easy-to-use APIs. Intelix offers a layered approach to security and allows you to deeply inspect suspicious files, while letting obviously clean files pass through the scanning quickly.
Figure 1 – Intelix solution architecture.
The services that SophosLabs Intelix offers can be split into three layers:
- Cloud lookups
- Static analysis
- Dynamic analysis
As you go down through the layers, the time taken to complete the analysis increases as the depth of the inspection increases. At the first two layers, the response from Intelix can be clean, malicious, or not known.
Dynamic analysis analyzes the behavior of the file within the sandbox. It will always give a clean or malicious response depending on whether or not malicious behavior was observed.
Implementation Plan
The flow chart below shows how to implement Intelix, as we are hunting for the first definitive answer as to whether the file is clean or malicious.
Figure 2 – Intelix services flow chart.
To allow Intelix to easily integrate this your application, we’re going to build a Lambda function that will take a file and tell us whether it’s clean or malicious.
This Lambda function can be deployed as part of your serverless application. An example is provided whereby an S3 event trigger calls Lambda when a new object is uploaded. It then runs through the analysis before moving clean (non-malicious) data to a second bucket and logging the results to Amazon CloudWatch Logs.
The example code is available on GitHub.
Login
Once you have registered to the Intelix service via AWS Marketplace, you are provided with API credentials in the form of a client_id and client_secret. These are required to access the Intelix APIs and must be base64 encoded:
This will return the base64 credentials, which you can export as INTELIX_CREDENTIALS environment variable to run locally, or use in the Lambda environment configuration.
Within the Lambda function, you’ll need to get an authorization token for Intelix to make the request with your credentials. This can be obtained quickly via the login token endpoint:
Cloud Lookups
Cloud lookups provide the ability to query SophosLabs’ database of known clean and malicious files. This is the fastest request to the Intelix API you can make, as this is a synchronous request.
The hash of the file is sent to the cloud lookup API, and this provides a JSON response which includes the reputation score we can use to see if the file is clean, malicious, or not known.
In the following example, the cloud lookup has identified the file as being malicious; the reputation score returned is below 20.
Static Analysis
Static analysis will scan the file with the Sophos Anti-Malware engine and will, for files such as documents and Portable Executable (PE) files that contain active content, use machine learning models to inspect the file features and structure for malicious content.
In this case, the complete file will need to be sent to Intelix for analysis as part of the request:
The response will either be the report, or a job id indicating the analysis is in progress. When the job is in progress, the following JSON is returned:
We can determine which response we are getting based on the status code:
If we have the job id, then we’ll need to poll the service every few seconds to get the report. These can take up to 15 minutes depending on the analysis carried out, but it typically returns with minutes.
To put this together for static analysis, we will send the file for analysis and then get the score from the report provided:
When we get the report, there is a full intelligence report. As shown above, the score under the report object is the important field. In the example below, the score is 50:
Dynamic Analysis
Dynamic analysis detonates the file in the SophosLabs sandbox environment. This is the longest scan and typically takes five minutes.
The sample is detonated in a virtual machine (VM) containing all of Sophos’ detection capabilities, as well as specific tools for monitoring behavior through memory dumps and other techniques.
This provides a detailed report on whether any malicious behavior is exhibited.
Submitting a sample for dynamic analysis is the same as for static analysis (as is collecting the verdict), but uses a different URL for the request, as shown in the code example below:
The response you get from dynamic analysis will have the full intelligence report, containing all of the information observed during detonation of the sample.
As with the static analysis, the score in the report section is the important field. In the example below (which has detail removed for brevity) you can see the score is 100:
By using a Lambda function to access Intelix functionality, you can get a detailed analysis of each file uploaded ensuring it’s not malicious before you use it any further within your web applications and AWS environment.
AWS CDK Deployment Example
An example deployment template using the AWS Cloud Development Toolkit (CDK) has been provided within the GitHub repository. This allows you to easily deploy an Amazon S3 bucket for data uploads, AWS Lambda function for Intelix analysis, and an S3 bucket for clean data.
When the Lambda function runs the analysis, results are published to Amazon CloudWatch Logs and, if clean, the data is copied to a second S3 bucket. This can be deployed using in a few simple steps. For further information please see README.md within the GIT repository:
Summary
With SophosLabs Intelix, you have a robust anti-malware solution that integrates via RESTful API and provides flexibility to integrate the service into your own serverless application.
The example code we shared in this post provides a great starting point to interact with the Intelix API. You could further customize this with a state machine in AWS Step Functions or event triggers with Amazon EventBridge.
If you’re building a web application that accepts files from untrusted sources, try out SophosLabs Intelix to keep your customers and systems free from malware.
Sign up for Intelix on AWS Marketplace, which includes a free tier to help you get started. You can also access the API documentation, and deploy the sample code used in this post on the SophosLabs GitHub repository.
Sophos – AWS Partner Spotlight
Sophos is an AWS Security Competency Partner that designs products to eliminate complexity, from network to endpoint to server security.
Contact Sophos | Partner Overview | AWS Marketplace
*Already worked with Sophos? Rate the Partner
*To review an AWS Partner, you must be a customer that has worked with them directly on a project.